Add Planets, Items, TradeHubs, tradehubs menu

This commit is contained in:
Logen Kain 2021-05-10 18:17:34 -04:00
parent 74244d953e
commit 13eb7979e9

91
main.py
View File

@ -1,6 +1,7 @@
import os import os
PLAYER_INIT_LOCATION = "1" PLAYER_INIT_LOCATION = "BoB"
class Player: class Player:
def __init__(self, name, location): def __init__(self, name, location):
@ -19,9 +20,10 @@ class Player:
class GameManager: class GameManager:
'Manage the game' 'Manage the game'
def __init__(self, userInput): def __init__(self, userInput, planets):
self.gameIsRunning = True self.gameIsRunning = True
self.player = Player(userInput, PLAYER_INIT_LOCATION) self.player = Player(userInput, PLAYER_INIT_LOCATION)
self.planets = planets
def isGameRunning(self): def isGameRunning(self):
return self.gameIsRunning return self.gameIsRunning
@ -34,6 +36,52 @@ class GameManager:
print("Location: ", self.player.getLocation()) print("Location: ", self.player.getLocation())
print() 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):
for item in self.items.values():
print("Name:", item.getName())
print("Cost:",item.getPrice())
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(): def clearScreen():
os.system('clear') os.system('clear')
@ -51,19 +99,50 @@ def titleScreen():
mainGame() mainGame()
def 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"])
planetLuna = Planet("Luna")
planetLuna.addTradeHub(tradeHubs["The Jackel"])
# Create user
userInput = "" userInput = ""
userInput = input("What is your name... peasant?") userInput = input("What is your name... peasant?\n>> ")
if userInput == "": if userInput == "":
userInput = "(none)" userInput = "(none)"
Game = GameManager(userInput) # Start Game
Game = GameManager(userInput, planets)
clearScreen() clearScreen()
while Game.isGameRunning(): while Game.isGameRunning():
userInput = input("(q)uit (p)layer stats (c)lear screen:\n>> ").lower() userInput = input("(q)uit (p)layer stats (e)nter trade hub (c)lear screen:\n>> ").lower()
if userInput == "q": if userInput == "q":
Game.stopGame() Game.stopGame()
@ -73,6 +152,8 @@ def mainGame():
if userInput == "c": if userInput == "c":
clearScreen() clearScreen()
if userInput == "e":
Game.enterTradeHub()
def main(): def main():
titleScreen() titleScreen()