Refactor; start buy menu
Change tradeable items from dict to list; give tradehubs proper inventory; Make inventory adding dumber
This commit is contained in:
parent
42885f4a52
commit
ea0c475074
12
main.py
12
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,7 +29,7 @@ def mainGame():
|
|||||||
|
|
||||||
tradeHubs["The Jackel"].addItems(tradeableItems)
|
tradeHubs["The Jackel"].addItems(tradeableItems)
|
||||||
|
|
||||||
tradeableItems.pop("flour")
|
tradeableItems.pop()
|
||||||
|
|
||||||
tradeHubs["Star Crapper"].addItems(tradeableItems)
|
tradeHubs["Star Crapper"].addItems(tradeableItems)
|
||||||
|
|
||||||
|
@ -26,8 +26,15 @@ class GameManager:
|
|||||||
|
|
||||||
def buyMenu(self):
|
def buyMenu(self):
|
||||||
print()
|
print()
|
||||||
#list items
|
while True:
|
||||||
#assign each item a number
|
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
|
#choose number
|
||||||
#ask for quantity
|
#ask for quantity
|
||||||
#Confirm
|
#Confirm
|
||||||
|
@ -5,20 +5,13 @@ class Inventory:
|
|||||||
'Object to hold items and quantity'
|
'Object to hold items and quantity'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.slot1 = InventorySlot(Item("empty", 0), 0)
|
#TODO Make limited slots
|
||||||
self.slot2 = InventorySlot(Item("empty", 0), 0)
|
# __init__(self, numberOfSlots)
|
||||||
self.items = [self.slot1, self.slot2]
|
self.items = []
|
||||||
|
|
||||||
def addItem(self, item, quantity):
|
def addItem(self, item, quantity):
|
||||||
for slot in self.items:
|
self.items.append(InventorySlot(item, quantity))
|
||||||
if slot.getName() == "empty":
|
|
||||||
self.slot1 = InventorySlot(item, quantity)
|
|
||||||
self.items.append(self.slot1)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.slot1.incItem(quantity)
|
|
||||||
|
|
||||||
|
|
||||||
def printInventory(self):
|
def printInventory(self):
|
||||||
print("Items: ")
|
print("Items: ")
|
||||||
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Quantity' : >8}")
|
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Quantity' : >8}")
|
||||||
@ -26,3 +19,6 @@ class Inventory:
|
|||||||
for slot in self.items:
|
for slot in self.items:
|
||||||
print(f"{slot.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(slot.getQuantity()) : >5}")
|
print(f"{slot.getName() : <15}{'* * * * * | * * * * *' : ^10}{str(slot.getQuantity()) : >5}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
def getInventory(self):
|
||||||
|
return self.items
|
||||||
|
@ -18,3 +18,6 @@ class InventorySlot:
|
|||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
return self.item.getName()
|
return self.item.getName()
|
||||||
|
|
||||||
|
def getPrice(self):
|
||||||
|
return self.item.getPrice()
|
||||||
|
@ -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