2021-05-10 16:14:23 -04:00
|
|
|
import os
|
|
|
|
|
2021-05-10 19:13:26 -04:00
|
|
|
PLAYER_INIT_LOCATION = "Luna"
|
2021-05-10 18:17:34 -04:00
|
|
|
|
2021-05-10 16:14:23 -04:00
|
|
|
class Player:
|
|
|
|
|
|
|
|
def __init__(self, name, location):
|
|
|
|
self.name = name
|
|
|
|
self.location = location
|
|
|
|
|
|
|
|
def getName(self):
|
|
|
|
return self.name
|
|
|
|
|
2021-05-10 16:25:51 -04:00
|
|
|
def setName(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
2021-05-10 16:14:23 -04:00
|
|
|
def getLocation(self):
|
|
|
|
return self.location
|
|
|
|
|
|
|
|
class GameManager:
|
|
|
|
'Manage the game'
|
|
|
|
|
2021-05-10 18:17:34 -04:00
|
|
|
def __init__(self, userInput, planets):
|
2021-05-10 16:14:23 -04:00
|
|
|
self.gameIsRunning = True
|
2021-05-10 16:25:51 -04:00
|
|
|
self.player = Player(userInput, PLAYER_INIT_LOCATION)
|
2021-05-10 18:17:34 -04:00
|
|
|
self.planets = planets
|
2021-05-10 16:14:23 -04:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2021-05-10 18:17:34 -04:00
|
|
|
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):
|
2021-05-10 19:13:26 -04:00
|
|
|
print(f"{'Name' : <15}{'* * * * * | * * * * *' : ^10}{'Cost' : >6}")
|
2021-05-10 18:17:34 -04:00
|
|
|
for item in self.items.values():
|
2021-05-10 19:13:26 -04:00
|
|
|
print(f"{item.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(item.getPrice()) : >5}")
|
2021-05-10 18:17:34 -04:00
|
|
|
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
|
|
|
|
|
2021-05-10 16:25:51 -04:00
|
|
|
def clearScreen():
|
|
|
|
os.system('clear')
|
2021-05-10 16:14:23 -04:00
|
|
|
|
2021-05-10 16:25:51 -04:00
|
|
|
def titleScreen():
|
2021-05-10 16:14:23 -04:00
|
|
|
while(True):
|
2021-05-10 16:25:51 -04:00
|
|
|
clearScreen()
|
|
|
|
print("Space Game Title To Be Disclosed!!!")
|
2021-05-10 16:14:23 -04:00
|
|
|
userInput = input("(n)ew game (q)uit:\n>> ").lower()
|
|
|
|
|
|
|
|
if userInput == "q":
|
|
|
|
break
|
|
|
|
|
|
|
|
if userInput == "n":
|
|
|
|
mainGame()
|
|
|
|
|
|
|
|
def mainGame():
|
2021-05-10 18:17:34 -04:00
|
|
|
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"])
|
2021-05-10 19:13:26 -04:00
|
|
|
planets["Luna"].addTradeHub(tradeHubs["The Jackel"])
|
2021-05-10 18:17:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Create user
|
2021-05-10 16:14:23 -04:00
|
|
|
userInput = ""
|
2021-05-10 16:25:51 -04:00
|
|
|
|
2021-05-10 18:17:34 -04:00
|
|
|
userInput = input("What is your name... peasant?\n>> ")
|
2021-05-10 16:25:51 -04:00
|
|
|
|
|
|
|
if userInput == "":
|
|
|
|
userInput = "(none)"
|
|
|
|
|
2021-05-10 18:17:34 -04:00
|
|
|
# Start Game
|
|
|
|
Game = GameManager(userInput, planets)
|
2021-05-10 16:14:23 -04:00
|
|
|
|
2021-05-10 16:25:51 -04:00
|
|
|
clearScreen()
|
2021-05-10 16:14:23 -04:00
|
|
|
|
|
|
|
while Game.isGameRunning():
|
2021-05-10 18:17:34 -04:00
|
|
|
userInput = input("(q)uit (p)layer stats (e)nter trade hub (c)lear screen:\n>> ").lower()
|
2021-05-10 16:14:23 -04:00
|
|
|
|
|
|
|
if userInput == "q":
|
|
|
|
Game.stopGame()
|
|
|
|
|
|
|
|
if userInput == "p":
|
|
|
|
Game.printPlayerStats()
|
|
|
|
|
|
|
|
if userInput == "c":
|
2021-05-10 16:25:51 -04:00
|
|
|
clearScreen()
|
2021-05-10 18:17:34 -04:00
|
|
|
if userInput == "e":
|
|
|
|
Game.enterTradeHub()
|
2021-05-10 16:14:23 -04:00
|
|
|
|
|
|
|
def main():
|
2021-05-10 16:25:51 -04:00
|
|
|
titleScreen()
|
2021-05-10 16:14:23 -04:00
|
|
|
|
|
|
|
main()
|