Add Game printStatus method which display already defined elements
This commit is contained in:
parent
fa2cde4c44
commit
1e3b96e689
@ -27,6 +27,12 @@ class Circus:
|
||||
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):
|
||||
self.state = 1
|
||||
|
||||
def getNextColor(self):
|
||||
return self.wagons[self.state - 1]
|
||||
|
||||
def getWagon(self):
|
||||
if self.state == 0:
|
||||
print("Circus is not or no longer in game.")
|
||||
@ -35,7 +41,7 @@ class Circus:
|
||||
self.state = self.state + 1
|
||||
if self.state == len(self.wagons) - 1:
|
||||
print("Circus stickers are now depleted.")
|
||||
self.state = 0
|
||||
self.state = 0 # effectively disable circus
|
||||
|
||||
|
||||
class ConcessionCard: # name may be different in English
|
||||
@ -52,13 +58,16 @@ class ConcessionCard: # name may be different in English
|
||||
choice = random.randint(0, pepitesNb - n)
|
||||
self.pepites.append(availableValues[choice])
|
||||
availableValues.pop(choice)
|
||||
self.taken = []
|
||||
self.taken = set()
|
||||
|
||||
def getRemainingPepites(self):
|
||||
return {1, 2, 3, 4, 5, 6, 7} - self.taken
|
||||
|
||||
def getReward(self, choice):
|
||||
if choice in self.taken:
|
||||
print(str(choice) + " has already been obtained.")
|
||||
return False
|
||||
self.taken.append(choice)
|
||||
self.taken.add(choice)
|
||||
print("Congrats! You obtained $" + str(self.pepites[choice]))
|
||||
return True
|
||||
|
||||
@ -73,6 +82,7 @@ class Game:
|
||||
def initGame(self, playersNb):
|
||||
# Game status
|
||||
self.year = 1858
|
||||
self.concession = False
|
||||
|
||||
# General data to generate
|
||||
self.circus = Circus(playersNb)
|
||||
@ -82,11 +92,24 @@ class Game:
|
||||
# Players
|
||||
self.players = []
|
||||
for n in range(0, playersNb):
|
||||
color = input("Enter the player's color: ")
|
||||
color = input("Enter player " + str(n + 1) + "'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 printStatus(self):
|
||||
print("Ticket to Ride Legacy: Legends of the West")
|
||||
print("")
|
||||
print("Campaign - Year: " + str(self.year))
|
||||
print("")
|
||||
print("Players:")
|
||||
for player in self.players:
|
||||
print(" " + player.color)
|
||||
if self.concession:
|
||||
print(" Concession card remaining pepites: " + str(player.concession.getRemainingPepites()))
|
||||
print("")
|
||||
if self.circus.state > 0:
|
||||
print("Circus next sticker color: " + self.circus.getNextColor())
|
||||
# TODO: treasures remaining to find)
|
||||
|
||||
|
||||
def saveData(self):
|
||||
savefile = open('./savefile.json', 'w+')
|
||||
@ -101,7 +124,7 @@ def loadData():
|
||||
|
||||
|
||||
# TESTS
|
||||
playersNb = 3
|
||||
playersNb = 2
|
||||
|
||||
# Test of data generation
|
||||
# myGame = Game()
|
||||
@ -114,18 +137,24 @@ playersNb = 3
|
||||
# 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)
|
||||
# cc = ConcessionCard()
|
||||
# userChoice = 3
|
||||
# print(cc.pepites)
|
||||
# cc.getReward(userChoice - 1)
|
||||
# print(cc.pepites)
|
||||
# print(cc.taken)
|
||||
# print("Remaining: " + str(cc.getRemainingPepites()))
|
||||
# cc.getReward(userChoice - 1)
|
||||
# print(cc.pepites)
|
||||
# print(cc.taken)
|
||||
# print("Remaining: " + str(cc.getRemainingPepites()))
|
||||
|
||||
# Test of Player
|
||||
# myGame = Game()
|
||||
# myGame.initGame(playersNb)
|
||||
# print(myGame.players[1].color)
|
||||
# print(myGame.players[1].concession.pepites)
|
||||
myGame = Game()
|
||||
myGame.initGame(playersNb)
|
||||
myGame.printStatus()
|
||||
myGame.concession = True
|
||||
myGame.printStatus()
|
||||
myGame.circus.enable()
|
||||
myGame.printStatus()
|
||||
print(myGame.circus.wagons)
|
||||
|
Loading…
Reference in New Issue
Block a user