Compare commits
2 Commits
923655df9c
...
acd669ba34
Author | SHA1 | Date | |
---|---|---|---|
acd669ba34 | |||
507ef83607 |
127
main.py
127
main.py
@ -4,7 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import jsonpickle
|
import jsonpickle
|
||||||
import time
|
from src.MamaOConnel import MamaOConnel
|
||||||
|
|
||||||
class Circus:
|
class Circus:
|
||||||
# There are:
|
# There are:
|
||||||
@ -30,8 +30,8 @@ class Circus:
|
|||||||
self.state = 0 # 0 means Circus is not used in game yet, 1 means next wagon in list is #1, and so on
|
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):
|
def enable(self):
|
||||||
if self.state == 0:
|
if self.state > 0:
|
||||||
print("Circus is not or no longer in game.")
|
print("Circus is already in game.")
|
||||||
return False
|
return False
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
@ -67,6 +67,7 @@ class TreasureCard:
|
|||||||
if self.state == -1:
|
if self.state == -1:
|
||||||
print("Treasure hunt has not started yet or is completed.")
|
print("Treasure hunt has not started yet or is completed.")
|
||||||
return False
|
return False
|
||||||
|
print("Congrats! You obtained $" + str(self.treasures[self.state]))
|
||||||
self.state = self.state + 1
|
self.state = self.state + 1
|
||||||
if self.state == 5:
|
if self.state == 5:
|
||||||
print("All treasures have been found.")
|
print("All treasures have been found.")
|
||||||
@ -79,6 +80,7 @@ class ConcessionCard:
|
|||||||
# 7 gold nuggets, as rewards when the player succefully connects a city to their concession. The player can choose
|
# 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).
|
# 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.
|
# A ConcessionCard is then composed of 7 nuggets, with the rewards randomly distributed.
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
availableValues = [11, 12, 13, 14, 15, 16, 17]
|
availableValues = [11, 12, 13, 14, 15, 16, 17]
|
||||||
nuggetsNb = len(availableValues) - 1
|
nuggetsNb = len(availableValues) - 1
|
||||||
@ -93,11 +95,18 @@ class ConcessionCard:
|
|||||||
return {1, 2, 3, 4, 5, 6, 7} - self.taken
|
return {1, 2, 3, 4, 5, 6, 7} - self.taken
|
||||||
|
|
||||||
def takeReward(self, choice):
|
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:
|
if choice in self.taken:
|
||||||
print(str(choice) + " has already been obtained.")
|
print(str(choice) + " has already been obtained.")
|
||||||
return False
|
return False
|
||||||
self.taken.add(choice)
|
self.taken.add(choice)
|
||||||
print("Congrats! You obtained $" + str(self.nuggets[choice]))
|
print("Congrats! You obtained $" + str(self.nuggets[choice - 1]))
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
|
|
||||||
@ -122,8 +131,10 @@ class Game:
|
|||||||
|
|
||||||
# General data to generate
|
# General data to generate
|
||||||
self.circus = Circus(playersNb)
|
self.circus = Circus(playersNb)
|
||||||
# Mama O'Connell
|
|
||||||
self.treasure = TreasureCard()
|
self.treasure = TreasureCard()
|
||||||
|
self.mamaoc = MamaOConnel()
|
||||||
|
while not self.mamaoc.solver():
|
||||||
|
self.mamaoc = MamaOConnel()
|
||||||
|
|
||||||
# Players
|
# Players
|
||||||
self.players = []
|
self.players = []
|
||||||
@ -131,7 +142,42 @@ class Game:
|
|||||||
color = input("Enter player " + str(n + 1) + "'s color: ")
|
color = input("Enter player " + str(n + 1) + "'s color: ")
|
||||||
self.players.append(Player(color))
|
self.players.append(Player(color))
|
||||||
|
|
||||||
|
def getPlayerByColor(self, color):
|
||||||
|
for player in self.players:
|
||||||
|
if player.color.lower() == color.lower():
|
||||||
|
return player
|
||||||
|
print("ERROR: player '" + color + "' is not defined")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def enableConcession(self):
|
||||||
|
self.concession = True
|
||||||
|
|
||||||
|
def disableConcession(self):
|
||||||
|
self.concession = False
|
||||||
|
|
||||||
|
# if number = 0 print Mama O'Connel's location, else print hint #number
|
||||||
|
def printMamaHint(self, number):
|
||||||
|
if number not in range(0, 4):
|
||||||
|
return False
|
||||||
|
os.system('clear')
|
||||||
|
input("When you are ready, press Enter.")
|
||||||
|
print("")
|
||||||
|
match number:
|
||||||
|
case 0:
|
||||||
|
print("Mama O'Connel 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)
|
||||||
|
case 2:
|
||||||
|
print("Mama O'Connel 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("")
|
||||||
|
input("When you are done, press Enter.")
|
||||||
|
os.system('clear')
|
||||||
|
|
||||||
def printStatus(self):
|
def printStatus(self):
|
||||||
|
print("")
|
||||||
|
print("---------------------------------------------------------------------")
|
||||||
print("")
|
print("")
|
||||||
print("Ticket to Ride Legacy: Legends of the West")
|
print("Ticket to Ride Legacy: Legends of the West")
|
||||||
print("")
|
print("")
|
||||||
@ -174,21 +220,22 @@ elif choice == "load":
|
|||||||
if path == "":
|
if path == "":
|
||||||
path = "savefile.json"
|
path = "savefile.json"
|
||||||
myGame = loadData(path)
|
myGame = loadData(path)
|
||||||
myGame.printStatus()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
os.system('clear')
|
|
||||||
myGame.printStatus()
|
myGame.printStatus()
|
||||||
command = input("==> ")
|
command = input("==> ")
|
||||||
while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concessions',\
|
while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concession',\
|
||||||
'take concession', 'enable treasure', 'take treasure'):
|
'take concession', 'disable concession', 'enable treasure', 'take treasure', 'mama hint 1', 'mama hint 2',\
|
||||||
|
'mama hint 3', 'mama location'):
|
||||||
print("")
|
print("")
|
||||||
print("Available commands:")
|
print("Available commands:")
|
||||||
print(" Main: 'load', 'save', 'next year', 'exit'")
|
print(" Main: 'load', 'save', 'next year', 'exit'")
|
||||||
print(" Circus: 'enable circus', 'take circus'")
|
print(" Circus: 'enable circus', 'take circus'")
|
||||||
print(" Concessions: 'enable concessions', 'take concession'")
|
|
||||||
print(" Treasure: 'enable treasure', 'take treasure'")
|
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'")
|
||||||
command = input("==> ")
|
command = input("==> ")
|
||||||
|
print("")
|
||||||
match command:
|
match command:
|
||||||
case 'load':
|
case 'load':
|
||||||
choice = input("WARNING! If you load, you will loose all unsaved changes. Are you sure? (type YES if you are) ")
|
choice = input("WARNING! If you load, you will loose all unsaved changes. Are you sure? (type YES if you are) ")
|
||||||
@ -203,38 +250,36 @@ while True:
|
|||||||
path = "savefile.json"
|
path = "savefile.json"
|
||||||
myGame.saveData(path)
|
myGame.saveData(path)
|
||||||
print("Game saved!")
|
print("Game saved!")
|
||||||
time.sleep(3)
|
|
||||||
case 'next year':
|
case 'next year':
|
||||||
myGame.yearId = myGame.yearId + 1
|
myGame.yearId = myGame.yearId + 1
|
||||||
case 'exit':
|
case 'exit':
|
||||||
exit()
|
exit()
|
||||||
|
case 'enable circus':
|
||||||
|
myGame.circus.enable()
|
||||||
# TESTS
|
case 'take circus':
|
||||||
|
myGame.circus.takeWagon()
|
||||||
# Test of ConcessionCard
|
case 'enable treasure':
|
||||||
# cc = ConcessionCard()
|
myGame.treasure.enable()
|
||||||
# userChoice = 3
|
case 'take treasure':
|
||||||
# print(cc.nuggets)
|
myGame.treasure.takeTreasure()
|
||||||
# cc.takeReward(userChoice - 1)
|
case 'enable concession':
|
||||||
# print(cc.nuggets)
|
myGame.enableConcession()
|
||||||
# print(cc.taken)
|
case 'take concession':
|
||||||
# print("Remaining: " + str(cc.getRemainingPepites()))
|
choice = input("Player? ==> ")
|
||||||
# cc.takeReward(userChoice - 1)
|
player = myGame.getPlayerByColor(choice)
|
||||||
# print(cc.nuggets)
|
if player == False:
|
||||||
# print(cc.taken)
|
print("Not a valid player.")
|
||||||
# print("Remaining: " + str(cc.getRemainingPepites()))
|
else:
|
||||||
|
choice = input("Which nugget? ==> ")
|
||||||
# Test of Player
|
print("")
|
||||||
# myGame = Game()
|
player.concession.takeReward(choice)
|
||||||
# myGame.initGame()
|
case 'disable concession':
|
||||||
# myGame.printStatus()
|
myGame.disableConcession()
|
||||||
# myGame.treasure.enable()
|
case 'mama hint 1':
|
||||||
# myGame.printStatus()
|
myGame.printMamaHint(1)
|
||||||
# myGame.treasure.takeTreasure()
|
case 'mama hint 2':
|
||||||
# myGame.treasure.takeTreasure()
|
myGame.printMamaHint(2)
|
||||||
# myGame.treasure.takeTreasure()
|
case 'mama hint 3':
|
||||||
# myGame.treasure.takeTreasure()
|
myGame.printMamaHint(3)
|
||||||
# myGame.printStatus()
|
case 'mama location':
|
||||||
# myGame.treasure.takeTreasure()
|
myGame.printMamaHint(0)
|
||||||
# myGame.printStatus()
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
class City:
|
class City:
|
||||||
@ -275,6 +274,6 @@ class MamaOConnel:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
myMama = MamaOConnel()
|
# myMama = MamaOConnel()
|
||||||
while not myMama.solver():
|
# while not myMama.solver():
|
||||||
myMama = MamaOConnel()
|
# myMama = MamaOConnel()
|
Loading…
Reference in New Issue
Block a user