Add inventory

This commit is contained in:
Logen Kain 2021-05-11 14:58:22 -04:00
parent 1f254ad35d
commit 42885f4a52
6 changed files with 71 additions and 4 deletions

View File

@ -29,7 +29,6 @@ def mainGame():
tradeHubs["The Jackel"].addItems(tradeableItems)
tradeableItems.pop("flour")
tradeHubs["Star Crapper"].addItems(tradeableItems)
@ -42,7 +41,6 @@ def mainGame():
planets["BoB"].addTradeHub(tradeHubs["Star Crapper"])
planets["Luna"].addTradeHub(tradeHubs["The Jackel"])
# Create user
userInput = ""

View File

@ -2,4 +2,5 @@ from .tradeHub import TradeHub
from .planet import Planet
from .item import Item
from .gameManager import GameManager
from .inventorySlot import InventorySlot
#from .player import Player

View File

@ -21,12 +21,22 @@ class GameManager:
tools.clearScreen()
print("Name: ", self.player.getName())
print("Location: ", self.player.getLocation())
self.player.printInventory()
print()
def buyMenu(self):
print()
#list items
#assign each item a number
#choose number
#ask for quantity
#Confirm
#add item with quantity to player inv
def enterTradeHub(self):
tools.clearScreen()
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':
tools.clearScreen()
@ -35,5 +45,8 @@ class GameManager:
elif userInput == 'l':
tools.clearScreen()
self.planets[self.player.getLocation()].getTradeHub().printItems()
elif userInput == 'b':
self.buyMenu()
else:
tools.clearScreen()

28
obj/inventory.py Normal file
View File

@ -0,0 +1,28 @@
from obj.item import Item
from obj.inventorySlot import InventorySlot
class Inventory:
'Object to hold items and quantity'
def __init__(self):
self.slot1 = InventorySlot(Item("empty", 0), 0)
self.slot2 = InventorySlot(Item("empty", 0), 0)
self.items = [self.slot1, self.slot2]
def addItem(self, item, quantity):
for slot in self.items:
if slot.getName() == "empty":
self.slot1 = InventorySlot(item, quantity)
self.items.append(self.slot1)
break
else:
self.slot1.incItem(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()

20
obj/inventorySlot.py Normal file
View File

@ -0,0 +1,20 @@
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()

View File

@ -1,8 +1,11 @@
from obj.inventory import Inventory
class Player:
def __init__(self, name, location):
self.name = name
self.location = location
self.inventory = Inventory()
def getName(self):
return self.name
@ -12,4 +15,8 @@ class Player:
def getLocation(self):
return self.location
def addItem(self, item, quantity):
self.inventory.addItem(item, quantity)
def printInventory(self):
self.inventory.printInventory()