From 0000c38cee29415812ddba3c135e3d397fc68322 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Sun, 19 May 2024 22:12:30 +0200 Subject: [PATCH] Add first elements for main input --- main.py | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 8515b8d..375cb92 100644 --- a/main.py +++ b/main.py @@ -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()