Add Player + Concession + getWagons

This commit is contained in:
Alexandre CATTEAU 2024-05-05 16:51:06 +02:00
parent c18209402c
commit fa2cde4c44

View File

@ -5,7 +5,6 @@ import os
import random import random
import jsonpickle import jsonpickle
# Class for Circus: list of <number> wagons, of the 5 colors
class Circus: class Circus:
# There are: # There are:
# 4 wagons of each colors (until 2 players' stop) # 4 wagons of each colors (until 2 players' stop)
@ -26,17 +25,68 @@ class Circus:
color = colors[random.randint(0, 4)] color = colors[random.randint(0, 4)]
self.wagons.append(color) self.wagons.append(color)
remaining[color] = remaining[color] - 1 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 getWagon(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) - 1:
print("Circus stickers are now depleted.")
self.state = 0
class ConcessionCard: # name may be different in English
# Each card contains:
# 6 cities to connect to the player's concession. There is no need to implement those.
# 7 gold "pepites", as rewards when the player succefully connects a city to their concession. The player can choose
# which "pepite" to earn, and then discovers the associated reward (between 11 and 17 coins).
# A ConcessionCard is then composed of 7 pepites, with the rewards randomly distributed.
def __init__(self):
availableValues = [11, 12, 13, 14, 15, 16, 17]
pepitesNb = len(availableValues) - 1
self.pepites = []
for n in range(0, 7):
choice = random.randint(0, pepitesNb - n)
self.pepites.append(availableValues[choice])
availableValues.pop(choice)
self.taken = []
def getReward(self, choice):
if choice in self.taken:
print(str(choice) + " has already been obtained.")
return False
self.taken.append(choice)
print("Congrats! You obtained $" + str(self.pepites[choice]))
return True
class Player:
def __init__(self, color):
self.color = color
self.concession = ConcessionCard()
class Game: class Game:
# initGame() is used to generate all data for a campaign and initialize status variables # initGame() is used to generate all data for a campaign and initialize status variables
def initGame(self, playersNb): def initGame(self, playersNb):
self.circusList = Circus(playersNb) # Game status
self.year = 1858
# General data to generate
self.circus = Circus(playersNb)
# Mama O'Connell # Mama O'Connell
# Treasures # Treasures
# Concessions
self.circusState = 0 # 0 means Circus is not used in game yet, 1 means next wagon in list is #1, and so on # Players
self.year = 1858 self.players = []
for n in range(0, playersNb):
color = input("Enter the player's color: ")
self.players.append(Player(color))
# TODO: print status of the game (year, players (color, concession pepites), circus next wagon, treasures remaining to find)
#def printStatus(self):
def saveData(self): def saveData(self):
savefile = open('./savefile.json', 'w+') savefile = open('./savefile.json', 'w+')
@ -49,11 +99,33 @@ def loadData():
data = jsonpickle.decode(content) data = jsonpickle.decode(content)
return data return data
# Test of data generation
# TESTS
playersNb = 3 playersNb = 3
# Test of data generation
# myGame = Game() # myGame = Game()
# myGame.initGame(playersNb) # myGame.initGame(playersNb)
# myGame.saveData() # myGame.saveData()
myGame = loadData()
print(myGame.year) # Test of data loading
print(myGame.circusList.wagons) # myGame = loadData()
# print(myGame.year)
# print(myGame.circus.wagons)
# Test of ConcessionCard
cc = ConcessionCard()
userChoice = 3
print(cc.pepites)
cc.getReward(userChoice - 1)
print(cc.pepites)
print(cc.taken)
cc.getReward(userChoice - 1)
print(cc.pepites)
print(cc.taken)
# Test of Player
# myGame = Game()
# myGame.initGame(playersNb)
# print(myGame.players[1].color)
# print(myGame.players[1].concession.pepites)