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
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]
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]))
![]() |
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
Post a Comment