diff --git a/main.py b/main.py index 5aaae3b..b260405 100644 --- a/main.py +++ b/main.py @@ -30,8 +30,8 @@ class Circus: self.state = 0 # 0 means Circus is not used in game yet, 1 means next wagon in list is #1, and so on def enable(self): - if self.state == 0: - print("Circus is not or no longer in game.") + if self.state > 0: + print("Circus is already in game.") return False self.state = 1 @@ -67,6 +67,7 @@ class TreasureCard: if self.state == -1: print("Treasure hunt has not started yet or is completed.") return False + print("Congrats! You obtained $" + str(self.treasures[self.state])) self.state = self.state + 1 if self.state == 5: print("All treasures have been found.") @@ -79,6 +80,7 @@ class ConcessionCard: # 7 gold nuggets, as rewards when the player succefully connects a city to their concession. The player can choose # which nugget to earn, and then discovers the associated reward (between 11 and 17 coins). # A ConcessionCard is then composed of 7 nuggets, with the rewards randomly distributed. + def __init__(self): availableValues = [11, 12, 13, 14, 15, 16, 17] nuggetsNb = len(availableValues) - 1 @@ -93,11 +95,18 @@ class ConcessionCard: return {1, 2, 3, 4, 5, 6, 7} - self.taken def takeReward(self, choice): + if not choice.isdigit(): + print("Please choose a number.") + return False + choice = int(choice) + if choice not in range(1, 8): + print("This is not a valid number") + return False if choice in self.taken: print(str(choice) + " has already been obtained.") return False self.taken.add(choice) - print("Congrats! You obtained $" + str(self.nuggets[choice])) + print("Congrats! You obtained $" + str(self.nuggets[choice - 1])) class Player: @@ -131,7 +140,22 @@ class Game: color = input("Enter player " + str(n + 1) + "'s color: ") self.players.append(Player(color)) + def getPlayerByColor(self, color): + for player in self.players: + if player.color.lower() == color.lower(): + return player + print("ERROR: player '" + color + "' is not defined") + return False + + def enableConcession(self): + self.concession = True + + def disableConcession(self): + self.concession = False + def printStatus(self): + print("") + print("---------------------------------------------------------------------") print("") print("Ticket to Ride Legacy: Legends of the West") print("") @@ -174,21 +198,20 @@ elif choice == "load": if path == "": path = "savefile.json" myGame = loadData(path) -myGame.printStatus() while True: - os.system('clear') myGame.printStatus() command = input("==> ") - while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concessions',\ - 'take concession', 'enable treasure', 'take treasure'): + while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concession',\ + 'take concession', 'disable concession', 'enable treasure', 'take treasure'): print("") print("Available commands:") print(" Main: 'load', 'save', 'next year', 'exit'") print(" Circus: 'enable circus', 'take circus'") - print(" Concessions: 'enable concessions', 'take concession'") print(" Treasure: 'enable treasure', 'take treasure'") + print(" Concessions: 'enable concession', 'take concession', 'disable concession'") command = input("==> ") + print("") match command: case 'load': choice = input("WARNING! If you load, you will loose all unsaved changes. Are you sure? (type YES if you are) ") @@ -203,38 +226,28 @@ while True: path = "savefile.json" myGame.saveData(path) print("Game saved!") - time.sleep(3) case 'next year': myGame.yearId = myGame.yearId + 1 case 'exit': exit() - - -# TESTS - -# Test of ConcessionCard -# cc = ConcessionCard() -# userChoice = 3 -# print(cc.nuggets) -# cc.takeReward(userChoice - 1) -# print(cc.nuggets) -# print(cc.taken) -# print("Remaining: " + str(cc.getRemainingPepites())) -# cc.takeReward(userChoice - 1) -# print(cc.nuggets) -# print(cc.taken) -# print("Remaining: " + str(cc.getRemainingPepites())) - -# Test of Player -# 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() + case 'enable circus': + myGame.circus.enable() + case 'take circus': + myGame.circus.takeWagon() + case 'enable treasure': + myGame.treasure.enable() + case 'take treasure': + myGame.treasure.takeTreasure() + case 'enable concession': + myGame.enableConcession() + case 'take concession': + choice = input("Player? ==> ") + player = myGame.getPlayerByColor(choice) + if player == False: + print("Not a valid player.") + else: + choice = input("Which nugget? ==> ") + print("") + player.concession.takeReward(choice) + case 'disable concession': + myGame.disableConcession()