import os PLAYER_INIT_LOCATION = "Luna" class Player: def __init__(self, name, location): self.name = name self.location = location def getName(self): return self.name def setName(self, name): self.name = name def getLocation(self): return self.location 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): clearScreen() print("Name: ", self.player.getName()) print("Location: ", self.player.getLocation()) print() def enterTradeHub(self): clearScreen() while True: userInput = input("(e)xit\n\n(l)ist items\n>> ").lower() if userInput == 'e': clearScreen() break; elif userInput == 'l': clearScreen() self.planets[self.player.getLocation()].getTradeHub().printItems() else: clearScreen() class Planet: 'Contains trade hub' def __init__(self, name): self.name = name def addTradeHub(self, tradeHub): self.tradeHub = tradeHub def getTradeHub(self): return self.tradeHub def getName(self): return self.name class TradeHub: 'Contains items to sell' def __init__(self, name): self.name = name def addItems(self, items): self.items = items def getItems(self): return self.items def printItems(self): print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}") print() for item in self.items.values(): print(f"{item.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(item.getPrice()) : >5}") print() class Item: 'items to buy/sell' def __init__(self, name, price): self.name = name self.price = price def getName(self): return self.name def getPrice(self): return self.price def clearScreen(): os.system('clear') def titleScreen(): while(True): clearScreen() print("Space Game Title To Be Disclosed!!!") userInput = input("(n)ew game\n(q)uit:\n>> ").lower() if userInput == "q": break if userInput == "n": mainGame() def mainGame(): clearScreen() tradeableItems = { "flour" : Item("flour", 0.5), "Rice Cakes" : Item("Rice Cakes", 1), "Water" : Item("Water", 25) } #Create TradeHubs tradeHubs = { "The Jackel" : TradeHub("The Jackel"), "Star Crapper" : TradeHub("Star Crapper") } tradeHubs["The Jackel"].addItems(tradeableItems) tradeableItems.pop("flour") tradeHubs["Star Crapper"].addItems(tradeableItems) # Create Planets planets = { "BoB" : Planet("BoB"), "Luna" : Planet("Luna") } planets["BoB"].addTradeHub(tradeHubs["Star Crapper"]) planets["Luna"].addTradeHub(tradeHubs["The Jackel"]) # Create user userInput = "" userInput = input("What is your name... peasant?\n>> ") if userInput == "": userInput = "(none)" # Start Game Game = GameManager(userInput, planets) clearScreen() while Game.isGameRunning(): userInput = "" userInput = input("(q)uit\n\n(p)layer stats\n(e)nter trade hub\n(c)lear screen:\n>> ").lower() if userInput == "q": Game.stopGame() elif userInput == "p": Game.printPlayerStats() elif userInput == "c": clearScreen() elif userInput == "e": Game.enterTradeHub() else: clearScreen() def main(): titleScreen() main()