Skip to main content

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

explorer() completion!

 I worked hard this week to get the job done. So here it is, the newly completed explorer() function!

def explorer():
global x
global y
global z
global chapter
global region
global regionDisplay
global Lori
global Lauren
global Julius
global Marcus
global locations
global local
global gold
menu = GameMenu()
characters = [Lori, Lauren, Julius, Marcus]
menu.update(characters)
print("x: " + str(x) + " y: " + str(y) + " z: "+ str(z))
if not local:
selections = [4, 5, 6]
print(regionDisplay + ":")
print(regionDiscribe(region))
for pair in AOEScanner(x,y,z,locations, region):
print("You can see " + pair[0] + " in the " + pair[1])
if local:
selections = [4, 5, 6, 7]
print(regionDisplay + ":")
print(locationCheck(x, y, z, locations, region)[2])
if regionCheck(x+1,y,z) >= 0 and \
(fetchRegionZ(regionCheck(x+1,y,z))-fetchRegionZ(region) <= 5 and
fetchRegionZ(region)-fetchRegionZ(regionCheck(x+1,y,z)) <= 5):
selections.append(1)
if regionCheck(x,y+1,z) >= 0 and \
(fetchRegionZ(regionCheck(x,y+1,z))-fetchRegionZ(region) <= 5 and
fetchRegionZ(region)-fetchRegionZ(regionCheck(x,y+1,z)) <= 5):
selections.append(0)
if regionCheck(x-1,y,z) >= 0 and \
(fetchRegionZ(regionCheck(x-1,y,z))-fetchRegionZ(region) <= 5 and
fetchRegionZ(region)-fetchRegionZ(regionCheck(x-1,y,z)) <= 5):
selections.append(3)
if regionCheck(x,y-1,z) >= 0 and \
(fetchRegionZ(regionCheck(x,y-1,z))-fetchRegionZ(region) <= 5 and
fetchRegionZ(region)-fetchRegionZ(regionCheck(x,y-1,z)) <= 5):
selections.append(2)
if 0 in selections:
print("0: March north")
if 1 in selections:
print("1: March east")
if 2 in selections:
print("2: March south")
if 3 in selections:
print("3: March west")
print("4: Party")
print("5: Rest")
print("6: Save")
playerChoice = inputAndCheck("Your Call: ", selections)
if playerChoice == 0:
y += 1
if playerChoice == 1:
x += 1
if playerChoice == 2:
y -= 1
if playerChoice == 3:
x -= 1
if playerChoice == 4:
menu.displayGameMenu()
if playerChoice == 5:
characters = rest(characters, local)
Lauren = characters[1]
Lori = characters[0]
Marcus = characters[2]
Julius = characters[3]
if playerChoice == 6:
save(characters, x, y, z, chapter,gold)
region = regionCheck(x, y, z)
regionDisplay = fetchRegionDisplay(region)
Checker = encounterCheck(region)
if (Checker[0] == True):
runCombat([Checker[1]], characters, region)
Checker= locationCheck(x, y, z, locations, region) #list: [bool, list of locations, locationDisplay]
local = Checker[0]
locations = Checker[1]

os.system("cls")

     I've added the ability to rest via the new rest() function. It is bound to the 5th selection. On the 6th selection, we have our new save feature! AOEScanner(), encounterCheck(), and locationCheck() was made for the adaptive descriptions, arriving at locations, and determining if there will be a fight. runCombat() was created to call on the Combat class. It doesn't do much now because the Combat() class has not been finished yet.

 The Rest() function:


def rest(charecters, local):
updatedCharacters = []
if local:
for wifu in charecters:
wifu.currentHealth = wifu.Health
wifu.currentEnergy = wifu.energyValue
updatedCharacters.append(wifu)
else:
for wifu in charecters:
luck = int(random.random() * 10)
wifu.currentHealth = wifu.currentHealth + luck
wifu.currentEnergy = wifu.currentEnergy + luck
if wifu.currentHealth > wifu.health:
wifu.currentHealth = wifu.health
if wifu.currentEnergy > wifu.energyValue:
wifu.currentEnergy = wifu.energyValue
updatedCharacters.append(wifu)
return updatedCharacters
    Rest() takes two parameters: the list of characters and the boolean "local" for whether or not the party is in a special location. if we are in a special location, the characters get fully restored hp and energy. Otherwise, we use a randomly determined integer for how much they get restored. The if statements inside the for loop are for ensuring that characters don't have more than their max energy and max hp.

AOEscanner() function:

def AOEScanner(x, y, z, locals, regionID):
finds = []
scan = locationCheck(x + 1, y, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "east"])
scan = locationCheck(x + 1, y + 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "north east"])
scan = locationCheck(x +1, y - 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "south east"])
scan = locationCheck(x - 1, y , z, locals, regionID)
if scan[0]:
finds.append([scan[2], "west"])
scan = locationCheck(x - 1, y + 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "north west"])
scan = locationCheck(x - 1, y - 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "south west"])
scan = locationCheck(x, y + 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "north"])
scan = locationCheck(x, y - 1, z, locals, regionID)
if scan[0]:
finds.append([scan[2], "south"])
return finds

     AOEscanner() takes the x, y, z, the locations list, and region ID as parameters and uses those to look for nearby locations that could be displayed in the description. It then returns those descriptions in a list.

locationCheck():

def locationCheck(x, y, z, locals, regionID):
areas = []
for place in locals:
if x == place.x and y == place.y and z == place.z:
return [True, locals, place.displayName]
if regionID == 0:
f = open("larmenPlains.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z)) #need to add a status to location class.
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 1:
return [False, locals]
elif regionID == 2:
return [False, locals]
elif regionID == 3:
f = open("desert3.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 4:
f = open("ruinedPlateau.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 5:
f = open("theDeathLands.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 6:
f = open("gobbiMontains.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 7:
f = open("drameKingdom.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 8:
f = open("miniPlatPen.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 9:
f = open("kingdomOfJavi.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]
elif regionID == 10:
f = open("igachiPlain.csv")
fileReader = csv.reader(f)
for line in fileReader:
if line == []:
continue
areas.append(line)
for place in areas:
if int(place[1]) == x and int(place[2]) == y and int(place[3]) == z:
if Location(Name= place[0],x= x,y= y, z=z) not in locals:
locals.append(Location(Name= place[0], x= x,y= y,z= z))
return [True, locals, place[0]]
else:
return [True, locals, place[0]]
return [False, locals]

     locationCheck() takes the x, y, z , list of locations and region ID, It checks for a location at the coordinates first in the location list and then in the region ID CSV. If it finds it in the CSV it will instantiate a new Location object and add it to the list. Then it returns a list containing a Boolean for weather or not location was found, the list of locations, and (if the bool was true) the display name of the location found.

encounterCheck():

def encounterCheck(RegionID):
f = open("encounters.csv")
Roll = int(random.random() * 100)
Reader = csv.reader(f)
PossibleFights = []
for region in Reader:
if region == []:
continue
PossibleFights.append(region)
f.close()
if int(PossibleFights[RegionID][0]) > Roll:
return [False]
up = 2
down = 0
for fight in PossibleFights[RegionID]:
try:
int(fight)
continue
except ValueError:
try:
if int(PossibleFights[RegionID][down]) < Roll < int(PossibleFights[RegionID][up]):
return [True, fight]
else:
up += 2
down += 2
except IndexError:
return [True, PossibleFights[RegionID][(PossibleFights[RegionID]) - 1]]
return [False]
    encounterCheck() takes the region ID as a parameter. It goes through encounter.csv to check if the random number lands between any of the encounter rates. The try-except blocks allow me to check through the file only checking the in-between values when it lands on a string. Then the IndexError, is for when it reaches the end of the file where there isn't a max value.

Save() and the new feature in bootSave().

def save(characters, x, y, z, ch, gp):
choice = inputAndCheck("What file would you like to save too? ", [1,2,3,4,5,6,7,8,9,10])
os.system("type nul > save" + str(choice)+ ".csv")
f = open("save" + str(choice) + ".csv", "w")
fWriter = csv.writer(f)
Row = [x, y, z, ch]
Rows = []
for playable in characters:
Row.append(playable.level)
Rows.append(Row)
Row = []
for playable in characters:
Row.append(playable.inventory)
Row.append(gp)
Rows.append(Row)
Row = []
for playable in characters:
Row.append(playable.currentHealth)
Rows.append(Row)
Row = []
for playable in characters:
Row.append(playable.currentEnergy)
Rows.append(Row)
Row = []
for playable in characters:
Row.append(playable.experience)
Rows.append(Row)
fWriter.writerows(Rows)
f.close()
choice = inputAndCheck("Would you like to keep playing? (1: Yes, 0: No) ", [0,1])
if choice == 0:
exit()

    Save() was created to, of course, save the game. It takes in the parameters of all game instance-specific data, like inventories, gold amount, character level, chapter, and the current amount of energy, health, and experience, and puts them all in a CSV. It also asks if you'd like to leave the game and closes the game if the player answers yes. 

With that complete, I updated bootSave() to be able to boot from those save files.

def bootSave(saveNum):
global x
global y
global z
global chapter
global Lori
global Lauren
global Marcus
global Julius
global gold
print(saveNum)
print(type(saveNum))
if saveNum == 0:
input("we are in")
f = open("newGame.csv")
fReader = csv.reader(f)
content = next(fReader)
print(type(content))
print(content)
x = int(content[0])
y = int(content[1])
z = int(content[2])
chapter = int(content[3])
Lori.level = int(content[4])
Lauren.level = int(content[5])
Marcus.level = int(content[6])
Julius.level = int(content[7])
print(Lori.level)
f.close()
else:
try:
f = open("save" + str(saveNum) +".csv")
fReader = csv.reader(f)
content = next(fReader)
x = int(content[0])
y = int(content[1])
z = int(content[2])
chapter = int(content[3])
Lori.level = int(content[4])
Lauren.level = int(content[5])
Marcus.level = int(content[6])
Julius.level = int(content[7])
next(fReader)
content = next(fReader)
Lori.inventory = content[0]
Lauren.inventory = content[1]
Marcus.inventory = content[2]
Julius.inventory = content[3]
gold = int(content[4])
next(fReader)
content = next(fReader)
Lori.currentHealth = int(content[0])
Lauren.currentHealth = int(content[1])
Marcus.currentHealth = int(content[2])
Julius.currentHealth = int(content[3])
next(fReader)
content = next(fReader)
Lori.currentEnergy = int(content[0])
Lauren.currentEnergy = int(content[1])
Marcus.currentEnergy = int(content[2])
Julius.currentEnergy = int(content[3])
except FileNotFoundError:
bootSave(inputAndCheck("how would you like to boot? 0 New game or integer of save you are booting", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
With all this done I finally have some gameplay to show:
Walking around the overworld!
Here we can see that AOEscanner works because it detected the church of light.

We can now arrive at locations!




Comments

Popular posts from this blog

Shop() run down

 This class is responsible for running the shop and creating the Item() objects. Constructor: def __init__ ( self ): self .items = [] f = open ( "items.csv" ) fReader = csv.reader(f) for line in fReader: if line == []: continue self .items.append(Item(line[ 2 ] , line[ 0 ] , int (line[ 1 ]) , int (line[ 3 ]))) f.close() When the class is called the class list items are filled with Item() objects created by opening items.csv and taking the data in there to instantiate the items. Then we close the file. WhoIsShopping(): def whoIsShopping ( self , squad : list ): counter = 0 choices = [] print ( "Who is shopping?" ) for member in squad: if member.level > 0 : print ( str (counter) + ": " + member.displayName) choices.append(counter) counter += 1 selection = inputAndCheck( "Selection: " , choices) return squad[selection] T...

Explorer() progress

I decided to start with the explorer() method because of how central it is to the program. I quickly realized I'd need new functions for accessing specific pieces of data from the CVSs, so I made a few for detecting what region the part is in, another for fetching the region name and fetching the region z coordinate. Here is what explorer looks like now. def explorer (): global x global y global z global chapter global region global regionDisplay global Lori global Lauren global Julius global Marcus menu = GameMenu() characters = [Lori , Lauren , Julius , Marcus] menu.update(characters) selections = [ 4 , 5 ] #Code goes here print (regionDisplay + ":" ) print (regionDiscribe(region)) # need and area scanner for detecting nearby locations if regionCheck(x+ 1 , y , z) >= 0 and \ (fetchRegionZ(regionCheck(x+ 1 , y , z))-fetchRegionZ(region) <= 5 and fetchRegionZ(region)-fetchRegionZ(regionCheck...

Flow Charts are Born

Flow charts weren't that difficult to make. I honestly already had a decent idea of how my program would run, so this was really taking what was on my mind and putting it into a graphic. For those who don't know, I'm using a common key for software design for all of the flow charts: Source:  https://www.zenflowchart.com/flowchart-symbols First I have the simplest of my flow charts: theInstaller.py Flow chart. Then I made the Flow chart for theMain.py: Finally, I decided to include 2 flow charts for the important subprocess in the game: Explore() and runCombat(). For all of these, I used color codes to help subdivide the pieces of the code into their smaller loops or different paths. I'll be using these flow charts a lot to point out where exactly I'm at in the game as I go along with this blog.