player can add items to inventory
This commit is contained in:
parent
ea0c475074
commit
3613ca45dd
1
main.py
1
main.py
@ -15,6 +15,7 @@ def titleScreen():
|
||||
|
||||
def mainGame():
|
||||
tools.clearScreen()
|
||||
#load items
|
||||
tradeableItems = [
|
||||
obj.Item("flour", 0.5),
|
||||
obj.Item("Rice Cakes", 1),
|
||||
|
@ -1,3 +1,4 @@
|
||||
from time import sleep
|
||||
from .player import Player
|
||||
import tools
|
||||
|
||||
@ -24,21 +25,53 @@ class GameManager:
|
||||
self.player.printInventory()
|
||||
print()
|
||||
|
||||
def getTradeHubItems(self):
|
||||
return self.planets[
|
||||
self.player.getLocation()].getTradeHub().getItems()
|
||||
|
||||
def buyMenu(self):
|
||||
print()
|
||||
tools.clearScreen()
|
||||
tradeHubItems = self.getTradeHubItems()
|
||||
while True:
|
||||
tools.clearScreen()
|
||||
i=0
|
||||
for item in self.planets[self.player.getLocation()].getTradeHub().getItems().getInventory():
|
||||
for item in tradeHubItems:
|
||||
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
|
||||
|
||||
try:
|
||||
itemNumber = int(userInput)
|
||||
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):
|
||||
tools.clearScreen()
|
||||
|
@ -8,3 +8,4 @@ class Item:
|
||||
return self.name
|
||||
def getPrice(self):
|
||||
return self.price
|
||||
|
||||
|
@ -13,7 +13,7 @@ class TradeHub:
|
||||
self.items.addItem(item, 100)
|
||||
|
||||
def getItems(self):
|
||||
return self.items
|
||||
return self.items.getInventory()
|
||||
def printItems(self):
|
||||
print(f"{'Name' : <15}{'- - - - - | - - - - -' : ^10}{'Cost' : >6}")
|
||||
print()
|
||||
|
Loading…
x
Reference in New Issue
Block a user