Compare commits
2 Commits
2570974192
...
master
Author | SHA1 | Date | |
---|---|---|---|
22a7798ed5 | |||
2ba1340ce8 |
129
main.py
129
main.py
@ -2,117 +2,12 @@
|
||||
|
||||
# Imports
|
||||
import os
|
||||
import random
|
||||
import jsonpickle
|
||||
from src.MamaOConnel import MamaOConnel
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
from src.Circus import Circus
|
||||
from src.TreasureCard import TreasureCard
|
||||
from src.Player import Player, ConcessionCard
|
||||
from src.MamaOConnell import MamaOConnell
|
||||
|
||||
class Game:
|
||||
|
||||
@ -132,9 +27,9 @@ class Game:
|
||||
# General data to generate
|
||||
self.circus = Circus(playersNb)
|
||||
self.treasure = TreasureCard()
|
||||
self.mamaoc = MamaOConnel()
|
||||
self.mamaoc = MamaOConnell()
|
||||
while not self.mamaoc.solver():
|
||||
self.mamaoc = MamaOConnel()
|
||||
self.mamaoc = MamaOConnell()
|
||||
|
||||
# Players
|
||||
self.players = []
|
||||
@ -158,7 +53,7 @@ class Game:
|
||||
def disableConcession(self):
|
||||
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):
|
||||
if number not in range(0, 4):
|
||||
return False
|
||||
@ -167,13 +62,13 @@ class Game:
|
||||
print("")
|
||||
match number:
|
||||
case 0:
|
||||
print("Mama O'Connel is at: " + self.mamaoc.location.name)
|
||||
print("Mama O'Connell is at: " + self.mamaoc.location.name)
|
||||
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:
|
||||
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:
|
||||
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("")
|
||||
input("When you are done, press Enter.")
|
||||
os.system('clear')
|
||||
@ -261,7 +156,7 @@ while True:
|
||||
print(" Circus: 'enable circus', 'take circus'")
|
||||
print(" Treasure: 'enable treasure', 'take treasure'")
|
||||
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("==> ")
|
||||
print("")
|
||||
match command:
|
||||
|
43
src/Circus.py
Normal file
43
src/Circus.py
Normal 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
|
@ -208,7 +208,7 @@ class Board:
|
||||
i = i + 1
|
||||
return result
|
||||
|
||||
class MamaOConnel:
|
||||
class MamaOConnell:
|
||||
|
||||
def __init__(self):
|
||||
board = Board() # TODO Board should be a "static" or "constant" class, see what we can do
|
41
src/Player.py
Normal file
41
src/Player.py
Normal 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
24
src/TreasureCard.py
Normal 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
|
Reference in New Issue
Block a user