Add first elements for main input

This commit is contained in:
Alexandre CATTEAU 2024-05-19 22:12:30 +02:00
parent 4fd0987cda
commit 0000c38cee

56
main.py
View File

@ -106,9 +106,14 @@ class Player:
class Game:
# initGame() is used to generate all data for a campaign and initialize status variables
def initGame(self, playersNb):
def initGame(self):
self.years = 1865, 1868, 1871, 1874, 1877, 1880, 1883, 1886, 1889, 1892, 1895, 1898
playersNb = input("Enter the number of players (2-5): ")
while not playersNb.isdigit() or int(playersNb) not in range(2, 6):
playersNb = input("OUT OF RANGE! Enter the number of players (2-5): ")
playersNb = int(playersNb)
# Game status
self.yearId = 0
self.concession = False
@ -146,23 +151,38 @@ class Game:
savefile.write(jsonpickle.encode(self))
savefile.close()
def loadData():
with open('./savefile.json', 'r') as savefile:
def loadData(path):
with open('./' + path, 'r') as savefile:
content = savefile.read()
data = jsonpickle.decode(content)
return data
print("")
print("Ticket to Ride Legacy: Legends of the West")
print("")
choice = input("What do you want to do (new/load)? ")
while choice not in ("new", "load"):
choice = input("UNDEFINED! What do you want to do (new/load)? ")
if choice == "new":
myGame = Game()
myGame.initGame()
elif choice == "load":
path = input("Path to save file (defaults to savefile.json)? ")
if path == "":
path = "savefile.json"
myGame = loadData(path)
myGame.printStatus()
# TESTS
playersNb = 2
# Test of data generation
# myGame = Game()
# myGame.initGame(playersNb)
# myGame.initGame()
# myGame.saveData()
# Test of data loading
# myGame = loadData()
# myGame = loadData('savefile.json')
# myGame.printStatus()
# Test of ConcessionCard
@ -179,15 +199,15 @@ playersNb = 2
# print("Remaining: " + str(cc.getRemainingPepites()))
# Test of Player
myGame = Game()
myGame.initGame(playersNb)
myGame.printStatus()
myGame.treasure.enable()
myGame.printStatus()
myGame.treasure.takeTreasure()
myGame.treasure.takeTreasure()
myGame.treasure.takeTreasure()
myGame.treasure.takeTreasure()
myGame.printStatus()
myGame.treasure.takeTreasure()
myGame.printStatus()
# myGame = Game()
# myGame.initGame()
# myGame.printStatus()
# myGame.treasure.enable()
# myGame.printStatus()
# myGame.treasure.takeTreasure()
# myGame.treasure.takeTreasure()
# myGame.treasure.takeTreasure()
# myGame.treasure.takeTreasure()
# myGame.printStatus()
# myGame.treasure.takeTreasure()
# myGame.printStatus()