2024-05-19 21:47:24 +02:00
|
|
|
# Generation of data for a campaign of Ticket to Ride Legacy: Legends of the West
|
2024-04-28 18:56:21 +02:00
|
|
|
|
|
|
|
# Imports
|
2024-05-01 14:46:15 +02:00
|
|
|
import os
|
|
|
|
import jsonpickle
|
2024-05-06 10:50:49 +02:00
|
|
|
|
2024-05-24 15:36:37 +02:00
|
|
|
from src.Circus import Circus
|
|
|
|
from src.TreasureCard import TreasureCard
|
|
|
|
from src.Player import Player, ConcessionCard
|
2024-05-24 15:39:19 +02:00
|
|
|
from src.MamaOConnell import MamaOConnell
|
2024-04-28 18:56:21 +02:00
|
|
|
|
2024-05-01 14:46:15 +02:00
|
|
|
class Game:
|
2024-04-28 18:56:21 +02:00
|
|
|
|
2024-05-01 14:46:15 +02:00
|
|
|
# initGame() is used to generate all data for a campaign and initialize status variables
|
2024-05-19 22:12:30 +02:00
|
|
|
def initGame(self):
|
2024-05-19 21:47:24 +02:00
|
|
|
self.years = 1865, 1868, 1871, 1874, 1877, 1880, 1883, 1886, 1889, 1892, 1895, 1898
|
|
|
|
|
2024-05-19 22:12:30 +02:00
|
|
|
playersNb = input("Enter the number of players (2-5): ")
|
|
|
|
while not playersNb.isdigit() or int(playersNb) not in range(2, 6):
|
|
|
|
playersNb = input("OUT OF RANGE! Enter the number of players (2-5): ")
|
|
|
|
playersNb = int(playersNb)
|
|
|
|
|
2024-05-05 16:51:06 +02:00
|
|
|
# Game status
|
2024-05-19 21:47:24 +02:00
|
|
|
self.yearId = 0
|
2024-05-06 10:02:08 +02:00
|
|
|
self.concession = False
|
2024-05-05 16:51:06 +02:00
|
|
|
|
|
|
|
# General data to generate
|
|
|
|
self.circus = Circus(playersNb)
|
2024-05-06 10:50:49 +02:00
|
|
|
self.treasure = TreasureCard()
|
2024-05-24 15:39:19 +02:00
|
|
|
self.mamaoc = MamaOConnell()
|
2024-05-23 21:24:00 +02:00
|
|
|
while not self.mamaoc.solver():
|
2024-05-24 15:39:19 +02:00
|
|
|
self.mamaoc = MamaOConnell()
|
2024-05-05 16:51:06 +02:00
|
|
|
|
|
|
|
# Players
|
|
|
|
self.players = []
|
|
|
|
for n in range(0, playersNb):
|
2024-05-06 10:02:08 +02:00
|
|
|
color = input("Enter player " + str(n + 1) + "'s color: ")
|
2024-05-05 16:51:06 +02:00
|
|
|
self.players.append(Player(color))
|
|
|
|
|
2024-05-24 15:19:43 +02:00
|
|
|
# Stickers pools
|
|
|
|
self.stickers = {'White': 0, 'Red': 0, 'Blue': 0, 'Yellow': 0, 'Green': 0, 'Black': 0}
|
|
|
|
|
2024-05-23 20:44:07 +02:00
|
|
|
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
|
|
|
|
|
2024-05-24 15:39:19 +02:00
|
|
|
# if number = 0 print Mama O'Connell's location, else print hint #number
|
2024-05-23 21:24:00 +02:00
|
|
|
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:
|
2024-05-24 15:39:19 +02:00
|
|
|
print("Mama O'Connell is at: " + self.mamaoc.location.name)
|
2024-05-23 21:24:00 +02:00
|
|
|
case 1:
|
2024-05-24 15:39:19 +02:00
|
|
|
print("Mama O'Connell is " + str(self.mamaoc.hint1[1]) + " cities from " + self.mamaoc.hint1[0].name)
|
2024-05-23 21:24:00 +02:00
|
|
|
case 2:
|
2024-05-24 15:39:19 +02:00
|
|
|
print("Mama O'Connell is " + str(self.mamaoc.hint2[1]) + " cities from " + self.mamaoc.hint2[0].name)
|
2024-05-23 21:24:00 +02:00
|
|
|
case 3:
|
2024-05-24 15:39:19 +02:00
|
|
|
print("Mama O'Connell is " + str(self.mamaoc.hint3[1]) + " cities from " + self.mamaoc.hint3[0].name)
|
2024-05-23 21:24:00 +02:00
|
|
|
print("")
|
|
|
|
input("When you are done, press Enter.")
|
|
|
|
os.system('clear')
|
|
|
|
|
2024-05-24 15:19:43 +02:00
|
|
|
def takeSticker(self, color, nb):
|
|
|
|
if not nb.isdigit() or int(nb) < 1:
|
|
|
|
print("ERROR: Not a positive number")
|
|
|
|
return False
|
|
|
|
nb = int(nb)
|
|
|
|
for c, n in self.stickers.items():
|
|
|
|
if c.lower() == color.lower():
|
|
|
|
if nb > n:
|
|
|
|
print("ERROR: not enough stickers remaining.")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.stickers[c] = n - nb
|
|
|
|
return True
|
|
|
|
print("ERROR: color not found.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
def newStickersBatch(self):
|
|
|
|
self.stickers = {x: self.stickers[x] + 7 for x in self.stickers}
|
|
|
|
|
2024-05-06 10:02:08 +02:00
|
|
|
def printStatus(self):
|
2024-05-23 20:44:07 +02:00
|
|
|
print("")
|
|
|
|
print("---------------------------------------------------------------------")
|
2024-05-19 11:34:14 +02:00
|
|
|
print("")
|
2024-05-06 10:02:08 +02:00
|
|
|
print("Ticket to Ride Legacy: Legends of the West")
|
|
|
|
print("")
|
2024-05-19 21:47:24 +02:00
|
|
|
print("Campaign - Year: " + str(self.years[self.yearId]))
|
2024-05-06 10:02:08 +02:00
|
|
|
print("")
|
|
|
|
print("Players:")
|
|
|
|
for player in self.players:
|
|
|
|
print(" " + player.color)
|
|
|
|
if self.concession:
|
2024-05-19 11:34:14 +02:00
|
|
|
print(" Concession card remaining nuggets: " + str(player.concession.getRemainingPepites()))
|
2024-05-06 10:02:08 +02:00
|
|
|
print("")
|
|
|
|
if self.circus.state > 0:
|
|
|
|
print("Circus next sticker color: " + self.circus.getNextColor())
|
2024-05-24 15:19:43 +02:00
|
|
|
print("")
|
2024-05-06 10:50:49 +02:00
|
|
|
if self.treasure.state > -1:
|
|
|
|
print(f"Treasures found: {self.treasure.getFoundNumber()}")
|
2024-05-24 15:19:43 +02:00
|
|
|
print("")
|
|
|
|
print("Road stickers:")
|
|
|
|
for color, nb in self.stickers.items():
|
|
|
|
print(" " + color + ": " + str(nb))
|
2024-04-28 18:56:21 +02:00
|
|
|
|
2024-05-19 23:09:08 +02:00
|
|
|
def saveData(self, path):
|
|
|
|
savefile = open('./' + path, 'w+')
|
2024-05-01 14:46:15 +02:00
|
|
|
savefile.write(jsonpickle.encode(self))
|
|
|
|
savefile.close()
|
|
|
|
|
2024-05-19 22:12:30 +02:00
|
|
|
def loadData(path):
|
|
|
|
with open('./' + path, 'r') as savefile:
|
2024-05-01 14:46:15 +02:00
|
|
|
content = savefile.read()
|
|
|
|
data = jsonpickle.decode(content)
|
|
|
|
return data
|
|
|
|
|
2024-05-05 16:51:06 +02:00
|
|
|
|
2024-05-19 22:12:30 +02:00
|
|
|
print("")
|
|
|
|
print("Ticket to Ride Legacy: Legends of the West")
|
|
|
|
print("")
|
|
|
|
choice = input("What do you want to do (new/load)? ")
|
|
|
|
while choice not in ("new", "load"):
|
|
|
|
choice = input("UNDEFINED! What do you want to do (new/load)? ")
|
|
|
|
if choice == "new":
|
|
|
|
myGame = Game()
|
|
|
|
myGame.initGame()
|
|
|
|
elif choice == "load":
|
|
|
|
path = input("Path to save file (defaults to savefile.json)? ")
|
|
|
|
if path == "":
|
|
|
|
path = "savefile.json"
|
|
|
|
myGame = loadData(path)
|
|
|
|
|
2024-05-19 23:09:08 +02:00
|
|
|
while True:
|
|
|
|
myGame.printStatus()
|
|
|
|
command = input("==> ")
|
2024-05-24 15:19:43 +02:00
|
|
|
while command not in ('load', 'save', 'next year', 'exit', 'take sticker', 'batch sticker', 'enable circus',\
|
|
|
|
'take circus', 'enable concession', 'take concession', 'disable concession', 'enable treasure', 'take treasure',\
|
|
|
|
'mama hint 1', 'mama hint 2', 'mama hint 3', 'mama location'):
|
2024-05-19 23:09:08 +02:00
|
|
|
print("")
|
|
|
|
print("Available commands:")
|
|
|
|
print(" Main: 'load', 'save', 'next year', 'exit'")
|
2024-05-24 15:19:43 +02:00
|
|
|
print(" Stickers: 'take sticker', 'batch sticker'")
|
2024-05-19 23:09:08 +02:00
|
|
|
print(" Circus: 'enable circus', 'take circus'")
|
|
|
|
print(" Treasure: 'enable treasure', 'take treasure'")
|
2024-05-23 20:44:07 +02:00
|
|
|
print(" Concessions: 'enable concession', 'take concession', 'disable concession'")
|
2024-05-24 15:39:19 +02:00
|
|
|
print(" Mama O'Connell tracking: 'mama hint 1', 'mama hint 2', 'mama hint 3', 'mama location'")
|
2024-05-19 23:09:08 +02:00
|
|
|
command = input("==> ")
|
2024-05-23 20:44:07 +02:00
|
|
|
print("")
|
2024-05-19 23:09:08 +02:00
|
|
|
match command:
|
|
|
|
case 'load':
|
|
|
|
choice = input("WARNING! If you load, you will loose all unsaved changes. Are you sure? (type YES if you are) ")
|
|
|
|
if choice == "YES":
|
|
|
|
path = input("Path to save file (defaults to savefile.json)? ")
|
|
|
|
if path == "":
|
|
|
|
path = "savefile.json"
|
|
|
|
myGame = loadData(path)
|
|
|
|
case 'save':
|
|
|
|
path = input("Path to save file (defaults to savefile.json)? ")
|
|
|
|
if path == "":
|
|
|
|
path = "savefile.json"
|
|
|
|
myGame.saveData(path)
|
|
|
|
print("Game saved!")
|
|
|
|
case 'next year':
|
|
|
|
myGame.yearId = myGame.yearId + 1
|
|
|
|
case 'exit':
|
|
|
|
exit()
|
2024-05-24 15:19:43 +02:00
|
|
|
case 'take sticker':
|
|
|
|
choice = input("Color ? ==> ")
|
|
|
|
number = input("Nb ? ==> ")
|
|
|
|
myGame.takeSticker(choice, number)
|
|
|
|
case 'batch sticker':
|
|
|
|
myGame.newStickersBatch()
|
2024-05-23 20:44:07 +02:00
|
|
|
case 'enable circus':
|
|
|
|
myGame.circus.enable()
|
|
|
|
case 'take circus':
|
|
|
|
myGame.circus.takeWagon()
|
|
|
|
case 'enable treasure':
|
|
|
|
myGame.treasure.enable()
|
|
|
|
case 'take treasure':
|
|
|
|
myGame.treasure.takeTreasure()
|
|
|
|
case 'enable concession':
|
|
|
|
myGame.enableConcession()
|
|
|
|
case 'take concession':
|
|
|
|
choice = input("Player? ==> ")
|
|
|
|
player = myGame.getPlayerByColor(choice)
|
|
|
|
if player == False:
|
|
|
|
print("Not a valid player.")
|
|
|
|
else:
|
|
|
|
choice = input("Which nugget? ==> ")
|
|
|
|
print("")
|
|
|
|
player.concession.takeReward(choice)
|
|
|
|
case 'disable concession':
|
|
|
|
myGame.disableConcession()
|
2024-05-23 21:24:00 +02:00
|
|
|
case 'mama hint 1':
|
|
|
|
myGame.printMamaHint(1)
|
|
|
|
case 'mama hint 2':
|
|
|
|
myGame.printMamaHint(2)
|
|
|
|
case 'mama hint 3':
|
|
|
|
myGame.printMamaHint(3)
|
|
|
|
case 'mama location':
|
|
|
|
myGame.printMamaHint(0)
|