From 83b9f4f9d489827a20a2af75bc0f6815158ab856 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Fri, 24 May 2024 15:19:43 +0200 Subject: [PATCH] Add stickers counters --- main.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 5518679..cd8bcd2 100644 --- a/main.py +++ b/main.py @@ -142,6 +142,9 @@ class Game: color = input("Enter player " + str(n + 1) + "'s color: ") self.players.append(Player(color)) + # Stickers pools + self.stickers = {'White': 0, 'Red': 0, 'Blue': 0, 'Yellow': 0, 'Green': 0, 'Black': 0} + def getPlayerByColor(self, color): for player in self.players: if player.color.lower() == color.lower(): @@ -175,6 +178,25 @@ class Game: input("When you are done, press Enter.") os.system('clear') + def takeSticker(self, color, nb): + if not nb.isdigit() or int(nb) < 1: + print("ERROR: Not a positive number") + return False + nb = int(nb) + for c, n in self.stickers.items(): + if c.lower() == color.lower(): + if nb > n: + print("ERROR: not enough stickers remaining.") + return False + else: + self.stickers[c] = n - nb + return True + print("ERROR: color not found.") + return False + + def newStickersBatch(self): + self.stickers = {x: self.stickers[x] + 7 for x in self.stickers} + def printStatus(self): print("") print("---------------------------------------------------------------------") @@ -191,8 +213,13 @@ class Game: print("") if self.circus.state > 0: print("Circus next sticker color: " + self.circus.getNextColor()) + print("") if self.treasure.state > -1: print(f"Treasures found: {self.treasure.getFoundNumber()}") + print("") + print("Road stickers:") + for color, nb in self.stickers.items(): + print(" " + color + ": " + str(nb)) def saveData(self, path): savefile = open('./' + path, 'w+') @@ -224,12 +251,13 @@ elif choice == "load": while True: myGame.printStatus() command = input("==> ") - while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concession',\ - 'take concession', 'disable concession', 'enable treasure', 'take treasure', 'mama hint 1', 'mama hint 2',\ - 'mama hint 3', 'mama location'): + while command not in ('load', 'save', 'next year', 'exit', 'take sticker', 'batch sticker', 'enable circus',\ + 'take circus', 'enable concession', 'take concession', 'disable concession', 'enable treasure', 'take treasure',\ + 'mama hint 1', 'mama hint 2', 'mama hint 3', 'mama location'): print("") print("Available commands:") print(" Main: 'load', 'save', 'next year', 'exit'") + print(" Stickers: 'take sticker', 'batch sticker'") print(" Circus: 'enable circus', 'take circus'") print(" Treasure: 'enable treasure', 'take treasure'") print(" Concessions: 'enable concession', 'take concession', 'disable concession'") @@ -254,6 +282,12 @@ while True: myGame.yearId = myGame.yearId + 1 case 'exit': exit() + case 'take sticker': + choice = input("Color ? ==> ") + number = input("Nb ? ==> ") + myGame.takeSticker(choice, number) + case 'batch sticker': + myGame.newStickersBatch() case 'enable circus': myGame.circus.enable() case 'take circus':