160 lines
3.7 KiB
Python

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):
print("Name: ", self.player.getName())
print("Location: ", self.player.getLocation())
print()
def enterTradeHub(self):
while True:
userInput = input("(l)ist items (e)xit\n>> ").lower()
if userInput == 'e':
break;
if userInput == 'l':
self.planets[self.player.getLocation()].getTradeHub().printItems()
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}")
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 (q)uit:\n>> ").lower()
if userInput == "q":
break
if userInput == "n":
mainGame()
def mainGame():
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 = input("(q)uit (p)layer stats (e)nter trade hub (c)lear screen:\n>> ").lower()
if userInput == "q":
Game.stopGame()
if userInput == "p":
Game.printPlayerStats()
if userInput == "c":
clearScreen()
if userInput == "e":
Game.enterTradeHub()
def main():
titleScreen()
main()