Compare commits
2 Commits
1f254ad35d
...
ea0c475074
Author | SHA1 | Date | |
---|---|---|---|
ea0c475074 | |||
42885f4a52 |
14
main.py
14
main.py
@ -15,11 +15,11 @@ def titleScreen():
|
|||||||
|
|
||||||
def mainGame():
|
def mainGame():
|
||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
tradeableItems = {
|
tradeableItems = [
|
||||||
"flour" : obj.Item("flour", 0.5),
|
obj.Item("flour", 0.5),
|
||||||
"Rice Cakes" : obj.Item("Rice Cakes", 1),
|
obj.Item("Rice Cakes", 1),
|
||||||
"Water" : obj.Item("Water", 25)
|
obj.Item("Water", 25)
|
||||||
}
|
]
|
||||||
|
|
||||||
#Create TradeHubs
|
#Create TradeHubs
|
||||||
tradeHubs = {
|
tradeHubs = {
|
||||||
@ -29,8 +29,7 @@ def mainGame():
|
|||||||
|
|
||||||
tradeHubs["The Jackel"].addItems(tradeableItems)
|
tradeHubs["The Jackel"].addItems(tradeableItems)
|
||||||
|
|
||||||
|
tradeableItems.pop()
|
||||||
tradeableItems.pop("flour")
|
|
||||||
|
|
||||||
tradeHubs["Star Crapper"].addItems(tradeableItems)
|
tradeHubs["Star Crapper"].addItems(tradeableItems)
|
||||||
|
|
||||||
@ -42,7 +41,6 @@ def mainGame():
|
|||||||
planets["BoB"].addTradeHub(tradeHubs["Star Crapper"])
|
planets["BoB"].addTradeHub(tradeHubs["Star Crapper"])
|
||||||
planets["Luna"].addTradeHub(tradeHubs["The Jackel"])
|
planets["Luna"].addTradeHub(tradeHubs["The Jackel"])
|
||||||
|
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
userInput = ""
|
userInput = ""
|
||||||
|
|
||||||
|
@ -2,4 +2,5 @@ from .tradeHub import TradeHub
|
|||||||
from .planet import Planet
|
from .planet import Planet
|
||||||
from .item import Item
|
from .item import Item
|
||||||
from .gameManager import GameManager
|
from .gameManager import GameManager
|
||||||
|
from .inventorySlot import InventorySlot
|
||||||
#from .player import Player
|
#from .player import Player
|
||||||
|
@ -21,12 +21,29 @@ class GameManager:
|
|||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
print("Name: ", self.player.getName())
|
print("Name: ", self.player.getName())
|
||||||
print("Location: ", self.player.getLocation())
|
print("Location: ", self.player.getLocation())
|
||||||
|
self.player.printInventory()
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
def buyMenu(self):
|
||||||
|
print()
|
||||||
|
while True:
|
||||||
|
i=0
|
||||||
|
for item in self.planets[self.player.getLocation()].getTradeHub().getItems().getInventory():
|
||||||
|
print(f"{i}, {item.getName()}")
|
||||||
|
i+=1
|
||||||
|
userInput = input("Which Item would you like to buy? (e)xit \n>> ")
|
||||||
|
|
||||||
|
if userInput == "e":
|
||||||
|
break
|
||||||
|
#choose number
|
||||||
|
#ask for quantity
|
||||||
|
#Confirm
|
||||||
|
#add item with quantity to player inv
|
||||||
|
|
||||||
def enterTradeHub(self):
|
def enterTradeHub(self):
|
||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
while True:
|
while True:
|
||||||
userInput = input("(e)xit\n\n(l)ist items\n>> ").lower()
|
userInput = input("(e)xit\n\n(l)ist items\n(b)uy\n>> ").lower()
|
||||||
|
|
||||||
if userInput == 'e':
|
if userInput == 'e':
|
||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
@ -35,5 +52,8 @@ class GameManager:
|
|||||||
elif userInput == 'l':
|
elif userInput == 'l':
|
||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
self.planets[self.player.getLocation()].getTradeHub().printItems()
|
self.planets[self.player.getLocation()].getTradeHub().printItems()
|
||||||
|
|
||||||
|
elif userInput == 'b':
|
||||||
|
self.buyMenu()
|
||||||
else:
|
else:
|
||||||
tools.clearScreen()
|
tools.clearScreen()
|
||||||
|
24
obj/inventory.py
Normal file
24
obj/inventory.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from obj.item import Item
|
||||||
|
from obj.inventorySlot import InventorySlot
|
||||||
|
|
||||||
|
class Inventory:
|
||||||
|
'Object to hold items and quantity'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
#TODO Make limited slots
|
||||||
|
# __init__(self, numberOfSlots)
|
||||||
|
self.items = []
|
||||||
|
|
||||||
|
def addItem(self, item, quantity):
|
||||||
|
self.items.append(InventorySlot(item, quantity))
|
||||||
|
|
||||||
|
def printInventory(self):
|
||||||
|
print("Items: ")
|
||||||
|
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Quantity' : >8}")
|
||||||
|
print()
|
||||||
|
for slot in self.items:
|
||||||
|
print(f"{slot.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(slot.getQuantity()) : >5}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
def getInventory(self):
|
||||||
|
return self.items
|
23
obj/inventorySlot.py
Normal file
23
obj/inventorySlot.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
class InventorySlot:
|
||||||
|
'One item plus quantity'
|
||||||
|
|
||||||
|
#Do I want to add the value here too?
|
||||||
|
|
||||||
|
def __init__(self, item, quantity):
|
||||||
|
self.item = item
|
||||||
|
self.quantity = quantity
|
||||||
|
|
||||||
|
def incItem(self, amount):
|
||||||
|
self.quantity += amount
|
||||||
|
|
||||||
|
def decItem(self, amount):
|
||||||
|
self.quantity -=amount
|
||||||
|
|
||||||
|
def getQuantity(self):
|
||||||
|
return self.quantity
|
||||||
|
|
||||||
|
def getName(self):
|
||||||
|
return self.item.getName()
|
||||||
|
|
||||||
|
def getPrice(self):
|
||||||
|
return self.item.getPrice()
|
@ -1,8 +1,11 @@
|
|||||||
|
from obj.inventory import Inventory
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
|
|
||||||
def __init__(self, name, location):
|
def __init__(self, name, location):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.location = location
|
self.location = location
|
||||||
|
self.inventory = Inventory()
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -12,4 +15,8 @@ class Player:
|
|||||||
|
|
||||||
def getLocation(self):
|
def getLocation(self):
|
||||||
return self.location
|
return self.location
|
||||||
|
def addItem(self, item, quantity):
|
||||||
|
self.inventory.addItem(item, quantity)
|
||||||
|
|
||||||
|
def printInventory(self):
|
||||||
|
self.inventory.printInventory()
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from obj.inventory import Inventory
|
||||||
|
|
||||||
|
|
||||||
class TradeHub:
|
class TradeHub:
|
||||||
'Contains items to sell'
|
'Contains items to sell'
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.items = {}
|
self.items = Inventory()
|
||||||
def addItems(self, items):
|
def addItems(self, items):
|
||||||
self.items = items
|
for item in items:
|
||||||
|
self.items.addItem(item, 100)
|
||||||
|
|
||||||
def getItems(self):
|
def getItems(self):
|
||||||
return self.items
|
return self.items
|
||||||
def printItems(self):
|
def printItems(self):
|
||||||
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}")
|
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}")
|
||||||
print()
|
print()
|
||||||
for item in self.items.values():
|
for slot in self.items.getInventory():
|
||||||
print(f"{item.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(item.getPrice()) : >5}")
|
print(f"{slot.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(slot.getPrice()) : >5}")
|
||||||
print()
|
print()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user