Compare commits

..

2 Commits

Author SHA1 Message Date
22a7798ed5 Correcty wide typo on O'Connell 2024-05-24 15:39:19 +02:00
2ba1340ce8 Split main code file 2024-05-24 15:36:37 +02:00
5 changed files with 121 additions and 118 deletions

129
main.py
View File

@ -2,117 +2,12 @@
# Imports # Imports
import os import os
import random
import jsonpickle import jsonpickle
from src.MamaOConnel import MamaOConnel
class Circus: from src.Circus import Circus
# There are: from src.TreasureCard import TreasureCard
# 4 wagons of each colors (until 2 players' stop) from src.Player import Player, ConcessionCard
# 2 wagons of each colors (until 3 players' stop) from src.MamaOConnell import MamaOConnell
# 2 wagons of each colors (until 4 players' stop)
# 2 wagons of each colors (until 5 players' stop)
# NOTE: In the original distribution, the same color never appears twice in a row
# We chose to remove this constraint, for the sake of simplicity
def __init__(self, playersNb):
wagonsPerColors = 2 * playersNb
colors = "blue", "green", "black", "red", "yellow"
remaining = {"blue": wagonsPerColors, "green": wagonsPerColors, "black": wagonsPerColors, "red": wagonsPerColors,\
"yellow": wagonsPerColors}
self.wagons = []
for n in range(0, 5 * wagonsPerColors):
color = colors[random.randint(0, 4)]
while remaining[color] == 0:
color = colors[random.randint(0, 4)]
self.wagons.append(color)
remaining[color] = remaining[color] - 1
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 already in game.")
return False
self.state = 1
def getNextColor(self):
return self.wagons[self.state - 1]
def takeWagon(self):
if self.state == 0:
print("Circus is not or no longer in game.")
return False
print("Player obtained a " + self.wagons[self.state - 1] + " circus sticker!")
self.state = self.state + 1
if self.state > len(self.wagons):
print("Circus stickers are now depleted.")
self.state = 0 # effectively disable circus
class TreasureCard:
def __init__(self):
self.treasures = [36, 33, 29, 27, 24]
self.state = -1 # disabled
def enable(self):
self.state = 0 # 0 means 0 treasures have been found
def getFoundNumber(self):
if self.state == -1:
print("Treasure hunt has not started yet or is completed.")
return False
return self.state
def takeTreasure(self):
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.")
self.state = -1 # effectively disable treasure card
class ConcessionCard:
# Each card contains:
# 6 cities to connect to the player's concession. There is no need to implement those.
# 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
self.nuggets = []
for n in range(0, 7):
choice = random.randint(0, nuggetsNb - n)
self.nuggets.append(availableValues[choice])
availableValues.pop(choice)
self.taken = set()
def getRemainingPepites(self):
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 - 1]))
class Player:
def __init__(self, color):
self.color = color
self.concession = ConcessionCard()
class Game: class Game:
@ -132,9 +27,9 @@ class Game:
# General data to generate # General data to generate
self.circus = Circus(playersNb) self.circus = Circus(playersNb)
self.treasure = TreasureCard() self.treasure = TreasureCard()
self.mamaoc = MamaOConnel() self.mamaoc = MamaOConnell()
while not self.mamaoc.solver(): while not self.mamaoc.solver():
self.mamaoc = MamaOConnel() self.mamaoc = MamaOConnell()
# Players # Players
self.players = [] self.players = []
@ -158,7 +53,7 @@ class Game:
def disableConcession(self): def disableConcession(self):
self.concession = False self.concession = False
# if number = 0 print Mama O'Connel's location, else print hint #number # if number = 0 print Mama O'Connell's location, else print hint #number
def printMamaHint(self, number): def printMamaHint(self, number):
if number not in range(0, 4): if number not in range(0, 4):
return False return False
@ -167,13 +62,13 @@ class Game:
print("") print("")
match number: match number:
case 0: case 0:
print("Mama O'Connel is at: " + self.mamaoc.location.name) print("Mama O'Connell is at: " + self.mamaoc.location.name)
case 1: case 1:
print("Mama O'Connel is " + str(self.mamaoc.hint1[1]) + " cities from " + self.mamaoc.hint1[0].name) print("Mama O'Connell is " + str(self.mamaoc.hint1[1]) + " cities from " + self.mamaoc.hint1[0].name)
case 2: case 2:
print("Mama O'Connel is " + str(self.mamaoc.hint2[1]) + " cities from " + self.mamaoc.hint2[0].name) print("Mama O'Connell is " + str(self.mamaoc.hint2[1]) + " cities from " + self.mamaoc.hint2[0].name)
case 3: case 3:
print("Mama O'Connel is " + str(self.mamaoc.hint3[1]) + " cities from " + self.mamaoc.hint3[0].name) print("Mama O'Connell is " + str(self.mamaoc.hint3[1]) + " cities from " + self.mamaoc.hint3[0].name)
print("") print("")
input("When you are done, press Enter.") input("When you are done, press Enter.")
os.system('clear') os.system('clear')
@ -261,7 +156,7 @@ while True:
print(" Circus: 'enable circus', 'take circus'") print(" Circus: 'enable circus', 'take circus'")
print(" Treasure: 'enable treasure', 'take treasure'") print(" Treasure: 'enable treasure', 'take treasure'")
print(" Concessions: 'enable concession', 'take concession', 'disable concession'") print(" Concessions: 'enable concession', 'take concession', 'disable concession'")
print(" Mama O'Connel tracking: 'mama hint 1', 'mama hint 2', 'mama hint 3', 'mama location'") print(" Mama O'Connell tracking: 'mama hint 1', 'mama hint 2', 'mama hint 3', 'mama location'")
command = input("==> ") command = input("==> ")
print("") print("")
match command: match command:

43
src/Circus.py Normal file
View File

@ -0,0 +1,43 @@
import random
class Circus:
# There are:
# 4 wagons of each colors (until 2 players' stop)
# 2 wagons of each colors (until 3 players' stop)
# 2 wagons of each colors (until 4 players' stop)
# 2 wagons of each colors (until 5 players' stop)
# NOTE: In the original distribution, the same color never appears twice in a row
# We chose to remove this constraint, for the sake of simplicity
def __init__(self, playersNb):
wagonsPerColors = 2 * playersNb
colors = "blue", "green", "black", "red", "yellow"
remaining = {"blue": wagonsPerColors, "green": wagonsPerColors, "black": wagonsPerColors, "red": wagonsPerColors,\
"yellow": wagonsPerColors}
self.wagons = []
for n in range(0, 5 * wagonsPerColors):
color = colors[random.randint(0, 4)]
while remaining[color] == 0:
color = colors[random.randint(0, 4)]
self.wagons.append(color)
remaining[color] = remaining[color] - 1
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 already in game.")
return False
self.state = 1
def getNextColor(self):
return self.wagons[self.state - 1]
def takeWagon(self):
if self.state == 0:
print("Circus is not or no longer in game.")
return False
print("Player obtained a " + self.wagons[self.state - 1] + " circus sticker!")
self.state = self.state + 1
if self.state > len(self.wagons):
print("Circus stickers are now depleted.")
self.state = 0 # effectively disable circus

View File

@ -208,7 +208,7 @@ class Board:
i = i + 1 i = i + 1
return result return result
class MamaOConnel: class MamaOConnell:
def __init__(self): def __init__(self):
board = Board() # TODO Board should be a "static" or "constant" class, see what we can do board = Board() # TODO Board should be a "static" or "constant" class, see what we can do

41
src/Player.py Normal file
View File

@ -0,0 +1,41 @@
import random
class ConcessionCard:
# Each card contains:
# 6 cities to connect to the player's concession. There is no need to implement those.
# 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
self.nuggets = []
for n in range(0, 7):
choice = random.randint(0, nuggetsNb - n)
self.nuggets.append(availableValues[choice])
availableValues.pop(choice)
self.taken = set()
def getRemainingPepites(self):
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 - 1]))
class Player:
def __init__(self, color):
self.color = color
self.concession = ConcessionCard()

24
src/TreasureCard.py Normal file
View File

@ -0,0 +1,24 @@
class TreasureCard:
def __init__(self):
self.treasures = [36, 33, 29, 27, 24]
self.state = -1 # disabled
def enable(self):
self.state = 0 # 0 means 0 treasures have been found
def getFoundNumber(self):
if self.state == -1:
print("Treasure hunt has not started yet or is completed.")
return False
return self.state
def takeTreasure(self):
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.")
self.state = -1 # effectively disable treasure card