Improve main interface
This commit is contained in:
parent
0000c38cee
commit
31dee57c01
51
main.py
51
main.py
@ -4,6 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import jsonpickle
|
import jsonpickle
|
||||||
|
import time
|
||||||
|
|
||||||
class Circus:
|
class Circus:
|
||||||
# There are:
|
# There are:
|
||||||
@ -17,7 +18,8 @@ class Circus:
|
|||||||
def __init__(self, playersNb):
|
def __init__(self, playersNb):
|
||||||
wagonsPerColors = 2 * playersNb
|
wagonsPerColors = 2 * playersNb
|
||||||
colors = "blue", "green", "black", "red", "yellow"
|
colors = "blue", "green", "black", "red", "yellow"
|
||||||
remaining = {"blue": wagonsPerColors, "green": wagonsPerColors, "black": wagonsPerColors, "red": wagonsPerColors, "yellow": wagonsPerColors}
|
remaining = {"blue": wagonsPerColors, "green": wagonsPerColors, "black": wagonsPerColors, "red": wagonsPerColors,\
|
||||||
|
"yellow": wagonsPerColors}
|
||||||
self.wagons = []
|
self.wagons = []
|
||||||
for n in range(0, 5 * wagonsPerColors):
|
for n in range(0, 5 * wagonsPerColors):
|
||||||
color = colors[random.randint(0, 4)]
|
color = colors[random.randint(0, 4)]
|
||||||
@ -146,8 +148,8 @@ class Game:
|
|||||||
if self.treasure.state > -1:
|
if self.treasure.state > -1:
|
||||||
print(f"Treasures found: {self.treasure.getFoundNumber()}")
|
print(f"Treasures found: {self.treasure.getFoundNumber()}")
|
||||||
|
|
||||||
def saveData(self):
|
def saveData(self, path):
|
||||||
savefile = open('./savefile.json', 'w+')
|
savefile = open('./' + path, 'w+')
|
||||||
savefile.write(jsonpickle.encode(self))
|
savefile.write(jsonpickle.encode(self))
|
||||||
savefile.close()
|
savefile.close()
|
||||||
|
|
||||||
@ -174,17 +176,42 @@ elif choice == "load":
|
|||||||
myGame = loadData(path)
|
myGame = loadData(path)
|
||||||
myGame.printStatus()
|
myGame.printStatus()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
os.system('clear')
|
||||||
|
myGame.printStatus()
|
||||||
|
command = input("==> ")
|
||||||
|
while command not in ('load', 'save', 'next year', 'exit', 'enable circus', 'take circus', 'enable concessions',\
|
||||||
|
'take concession', 'enable treasure', 'take treasure'):
|
||||||
|
print("")
|
||||||
|
print("Available commands:")
|
||||||
|
print(" Main: 'load', 'save', 'next year', 'exit'")
|
||||||
|
print(" Circus: 'enable circus', 'take circus'")
|
||||||
|
print(" Concessions: 'enable concessions', 'take concession'")
|
||||||
|
print(" Treasure: 'enable treasure', 'take treasure'")
|
||||||
|
command = input("==> ")
|
||||||
|
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!")
|
||||||
|
time.sleep(3)
|
||||||
|
case 'next year':
|
||||||
|
myGame.yearId = myGame.yearId + 1
|
||||||
|
case 'exit':
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
# TESTS
|
# TESTS
|
||||||
|
|
||||||
# Test of data generation
|
|
||||||
# myGame = Game()
|
|
||||||
# myGame.initGame()
|
|
||||||
# myGame.saveData()
|
|
||||||
|
|
||||||
# Test of data loading
|
|
||||||
# myGame = loadData('savefile.json')
|
|
||||||
# myGame.printStatus()
|
|
||||||
|
|
||||||
# Test of ConcessionCard
|
# Test of ConcessionCard
|
||||||
# cc = ConcessionCard()
|
# cc = ConcessionCard()
|
||||||
# userChoice = 3
|
# userChoice = 3
|
||||||
|
Loading…
Reference in New Issue
Block a user