Compare commits

..

2 Commits

Author SHA1 Message Date
2570974192 Remove deprecated code 2024-05-24 15:20:00 +02:00
83b9f4f9d4 Add stickers counters 2024-05-24 15:19:43 +02:00
2 changed files with 37 additions and 7 deletions

40
main.py
View File

@ -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':

View File

@ -273,7 +273,3 @@ class MamaOConnel:
if len(cross) > 1: # multiple cities remaining after 3 hints
return False
return True
# myMama = MamaOConnel()
# while not myMama.solver():
# myMama = MamaOConnel()