space-game-proto/obj/gameManager.py

93 lines
2.6 KiB
Python
Raw Permalink Normal View History

2021-05-11 18:35:04 -04:00
from time import sleep
2021-05-11 10:34:56 -04:00
from .player import Player
import tools
PLAYER_INIT_LOCATION = "Luna"
class GameManager:
'Manage the game'
def __init__(self, userInput, planets):
self.gameIsRunning = True
self.player = Player(userInput, PLAYER_INIT_LOCATION)
self.planets = planets
def isGameRunning(self):
return self.gameIsRunning
def stopGame(self):
self.gameIsRunning = False
def printPlayerStats(self):
tools.clearScreen()
print("Name: ", self.player.getName())
print("Location: ", self.player.getLocation())
2021-05-11 14:58:22 -04:00
self.player.printInventory()
2021-05-11 10:34:56 -04:00
print()
2021-05-11 18:35:04 -04:00
def getTradeHubItems(self):
return self.planets[
self.player.getLocation()].getTradeHub().getItems()
2021-05-11 14:58:22 -04:00
def buyMenu(self):
2021-05-11 18:35:04 -04:00
tools.clearScreen()
tradeHubItems = self.getTradeHubItems()
while True:
2021-05-11 18:35:04 -04:00
tools.clearScreen()
i=0
2021-05-11 18:35:04 -04:00
for item in tradeHubItems:
print(f"{i}, {item.getName()}")
i+=1
userInput = input("Which Item would you like to buy? (e)xit \n>> ")
if userInput == "e":
break
2021-05-11 18:35:04 -04:00
try:
itemNumber = int(userInput)
except ValueError:
continue
if itemNumber < i and itemNumber > -1:
print("You have choosen: " + tradeHubItems[itemNumber].getName())
userInput = input("How many would you like?\n>> ")
try:
itemQuantity = int(userInput)
except ValueError:
continue
else:
continue
if itemQuantity == 0:
print("NO ITEMS ADDED!")
break
userInput = input(f"Are you sure you want {itemQuantity} {tradeHubItems[itemNumber].getName()}? (y/n)\n>> ").lower()
if userInput == "y":
self.player.addItem(tradeHubItems[itemNumber], itemQuantity)
else:
print("NO ITEMS ADDED!")
sleep(1)
break
2021-05-11 14:58:22 -04:00
2021-05-11 10:34:56 -04:00
def enterTradeHub(self):
tools.clearScreen()
while True:
2021-05-11 14:58:22 -04:00
userInput = input("(e)xit\n\n(l)ist items\n(b)uy\n>> ").lower()
2021-05-11 10:34:56 -04:00
if userInput == 'e':
tools.clearScreen()
break;
elif userInput == 'l':
tools.clearScreen()
self.planets[self.player.getLocation()].getTradeHub().printItems()
2021-05-11 14:58:22 -04:00
elif userInput == 'b':
self.buyMenu()
2021-05-11 10:34:56 -04:00
else:
tools.clearScreen()