player can add items to inventory

This commit is contained in:
Logen Kain 2021-05-11 18:35:04 -04:00
parent ea0c475074
commit 3613ca45dd
4 changed files with 42 additions and 7 deletions

View File

@ -15,6 +15,7 @@ def titleScreen():
def mainGame(): def mainGame():
tools.clearScreen() tools.clearScreen()
#load items
tradeableItems = [ tradeableItems = [
obj.Item("flour", 0.5), obj.Item("flour", 0.5),
obj.Item("Rice Cakes", 1), obj.Item("Rice Cakes", 1),

View File

@ -1,3 +1,4 @@
from time import sleep
from .player import Player from .player import Player
import tools import tools
@ -24,21 +25,53 @@ class GameManager:
self.player.printInventory() self.player.printInventory()
print() print()
def getTradeHubItems(self):
return self.planets[
self.player.getLocation()].getTradeHub().getItems()
def buyMenu(self): def buyMenu(self):
print() tools.clearScreen()
tradeHubItems = self.getTradeHubItems()
while True: while True:
tools.clearScreen()
i=0 i=0
for item in self.planets[self.player.getLocation()].getTradeHub().getItems().getInventory(): for item in tradeHubItems:
print(f"{i}, {item.getName()}") print(f"{i}, {item.getName()}")
i+=1 i+=1
userInput = input("Which Item would you like to buy? (e)xit \n>> ") userInput = input("Which Item would you like to buy? (e)xit \n>> ")
if userInput == "e": if userInput == "e":
break break
#choose number
#ask for quantity try:
#Confirm itemNumber = int(userInput)
#add item with quantity to player inv except ValueError:
continue
if itemNumber < i and itemNumber > -1:
print("You have choosen: " + tradeHubItems[itemNumber].getName())
userInput = input("How many would you like?\n>> ")
try:
itemQuantity = int(userInput)
except ValueError:
continue
else:
continue
if itemQuantity == 0:
print("NO ITEMS ADDED!")
break
userInput = input(f"Are you sure you want {itemQuantity} {tradeHubItems[itemNumber].getName()}? (y/n)\n>> ").lower()
if userInput == "y":
self.player.addItem(tradeHubItems[itemNumber], itemQuantity)
else:
print("NO ITEMS ADDED!")
sleep(1)
break
def enterTradeHub(self): def enterTradeHub(self):
tools.clearScreen() tools.clearScreen()

View File

@ -8,3 +8,4 @@ class Item:
return self.name return self.name
def getPrice(self): def getPrice(self):
return self.price return self.price

View File

@ -13,7 +13,7 @@ class TradeHub:
self.items.addItem(item, 100) self.items.addItem(item, 100)
def getItems(self): def getItems(self):
return self.items return self.items.getInventory()
def printItems(self): def printItems(self):
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}") print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}")
print() print()