Seperate classes/tools into files
This commit is contained in:
parent
c58efad369
commit
1f254ad35d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__
|
121
main.py
121
main.py
@ -1,100 +1,9 @@
|
||||
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')
|
||||
import obj
|
||||
import tools
|
||||
|
||||
def titleScreen():
|
||||
while(True):
|
||||
clearScreen()
|
||||
tools.clearScreen()
|
||||
print("Space Game Title To Be Disclosed!!!")
|
||||
userInput = input("(n)ew game\n(q)uit:\n>> ").lower()
|
||||
|
||||
@ -105,17 +14,17 @@ def titleScreen():
|
||||
mainGame()
|
||||
|
||||
def mainGame():
|
||||
clearScreen()
|
||||
tools.clearScreen()
|
||||
tradeableItems = {
|
||||
"flour" : Item("flour", 0.5),
|
||||
"Rice Cakes" : Item("Rice Cakes", 1),
|
||||
"Water" : Item("Water", 25)
|
||||
"flour" : obj.Item("flour", 0.5),
|
||||
"Rice Cakes" : obj.Item("Rice Cakes", 1),
|
||||
"Water" : obj.Item("Water", 25)
|
||||
}
|
||||
|
||||
#Create TradeHubs
|
||||
tradeHubs = {
|
||||
"The Jackel" : TradeHub("The Jackel"),
|
||||
"Star Crapper" : TradeHub("Star Crapper")
|
||||
"The Jackel" : obj.TradeHub("The Jackel"),
|
||||
"Star Crapper" : obj.TradeHub("Star Crapper")
|
||||
}
|
||||
|
||||
tradeHubs["The Jackel"].addItems(tradeableItems)
|
||||
@ -127,8 +36,8 @@ def mainGame():
|
||||
|
||||
# Create Planets
|
||||
planets = {
|
||||
"BoB" : Planet("BoB"),
|
||||
"Luna" : Planet("Luna")
|
||||
"BoB" : obj.Planet("BoB"),
|
||||
"Luna" : obj.Planet("Luna")
|
||||
}
|
||||
planets["BoB"].addTradeHub(tradeHubs["Star Crapper"])
|
||||
planets["Luna"].addTradeHub(tradeHubs["The Jackel"])
|
||||
@ -143,9 +52,9 @@ def mainGame():
|
||||
userInput = "(none)"
|
||||
|
||||
# Start Game
|
||||
Game = GameManager(userInput, planets)
|
||||
Game = obj.GameManager(userInput, planets)
|
||||
|
||||
clearScreen()
|
||||
tools.clearScreen()
|
||||
|
||||
while Game.isGameRunning():
|
||||
userInput = ""
|
||||
@ -158,11 +67,11 @@ def mainGame():
|
||||
Game.printPlayerStats()
|
||||
|
||||
elif userInput == "c":
|
||||
clearScreen()
|
||||
tools.clearScreen()
|
||||
elif userInput == "e":
|
||||
Game.enterTradeHub()
|
||||
else:
|
||||
clearScreen()
|
||||
tools.clearScreen()
|
||||
|
||||
def main():
|
||||
titleScreen()
|
||||
|
5
obj/__init__.py
Normal file
5
obj/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from .tradeHub import TradeHub
|
||||
from .planet import Planet
|
||||
from .item import Item
|
||||
from .gameManager import GameManager
|
||||
#from .player import Player
|
39
obj/gameManager.py
Normal file
39
obj/gameManager.py
Normal file
@ -0,0 +1,39 @@
|
||||
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())
|
||||
print()
|
||||
|
||||
def enterTradeHub(self):
|
||||
tools.clearScreen()
|
||||
while True:
|
||||
userInput = input("(e)xit\n\n(l)ist items\n>> ").lower()
|
||||
|
||||
if userInput == 'e':
|
||||
tools.clearScreen()
|
||||
break;
|
||||
|
||||
elif userInput == 'l':
|
||||
tools.clearScreen()
|
||||
self.planets[self.player.getLocation()].getTradeHub().printItems()
|
||||
else:
|
||||
tools.clearScreen()
|
10
obj/item.py
Normal file
10
obj/item.py
Normal file
@ -0,0 +1,10 @@
|
||||
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
|
13
obj/planet.py
Normal file
13
obj/planet.py
Normal file
@ -0,0 +1,13 @@
|
||||
from .tradeHub import TradeHub
|
||||
|
||||
class Planet:
|
||||
'Contains trade hub'
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.tradeHub = TradeHub
|
||||
def addTradeHub(self, tradeHub):
|
||||
self.tradeHub = tradeHub
|
||||
def getTradeHub(self):
|
||||
return self.tradeHub
|
||||
def getName(self):
|
||||
return self.name
|
15
obj/player.py
Normal file
15
obj/player.py
Normal file
@ -0,0 +1,15 @@
|
||||
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
|
||||
|
15
obj/tradeHub.py
Normal file
15
obj/tradeHub.py
Normal file
@ -0,0 +1,15 @@
|
||||
class TradeHub:
|
||||
'Contains items to sell'
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.items = {}
|
||||
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()
|
2
tools/__init__.py
Normal file
2
tools/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .text import clearScreen
|
||||
|
4
tools/text.py
Normal file
4
tools/text.py
Normal file
@ -0,0 +1,4 @@
|
||||
import os
|
||||
|
||||
def clearScreen():
|
||||
os.system('clear')
|
Loading…
x
Reference in New Issue
Block a user