-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShopProgramV2.py
More file actions
109 lines (97 loc) · 3.92 KB
/
ShopProgramV2.py
File metadata and controls
109 lines (97 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Dummy Player for shop testing
# Code made by Thomas Morrissey, Jacob Snipes, Luke Gosnell, and Bryson Mueller.
# Pseudocode:
# Shop program. You can buy/sell items here.
# Thanks to the Inventory team to giving us the Inventory Items we can now complete the program.
# Modified by Jacob Snipes to import the Inventory program and take the items from there.
import Inventory
class item(object):
def __init__(self,cost,name):
self.name=name
self.cost=cost
def __str__(self):
print("n\Cost:",self.cost)
class Player(object):
def __init__(self,name):
self.name=name
self.items=[]
self.money=200
def SellItems(self):
Continue=""
while Continue != "n":
print("Money:",self.money)
for item in self.items:
print(item.name,":",item.cost/2)
Selection=input("Which item would you like to sell: ")
sellItem=[]
sellItem2=[]
for i in self.items:
sellItem.append(i.name)
sellItem2.append(i.cost)
count=0
missell=True
for i in sellItem:
if Selection == i:
self.money += sellItem2[count]/2
self.items.remove(self.items[count])
print("Inventory:")
missell=False
for item in self.items:
print(item.name,":",item.cost)
else:
count+=1
if missell==True:
print("Please enter a valid item")
Continue=input("Would you like to sell more? (y/n): ")
def BuyItems(self):
Continue=""
while Continue not in ("no","No","n","N"):
print("Money:",self.money)
Inventory.Print()
Selection=input("Which item would you like to buy: ")
if Selection in Inventory.myInventory.weapons:
item=Inventory.myInventory.weapons[Selection]
print("Success")
if item.cost > self.money:
print("You don't have enough cash!")
else:
self.money -= item.cost
self.items.append(item)
elif Selection in Inventory.myInventory.items:
item=Inventory.myInventory.items[Selection]
if item.cost > self.money:
print("You don't have enough cash!")
else:
self.money -= item.cost
self.items.append(item)
elif Selection in Inventory.myInventory.consumables:
item=Inventory.myInventory.consumables[Selection]
if item.cost > self.money:
print("You don't have enough cash!")
else:
self.money -= item.cost
self.items.append(item)
elif Selection in Inventory.myInventory.armors:
item=Inventory.myInventory.armors[Selection]
if item.cost > self.money:
print("You don't have enough cash!")
else:
self.money -= item.cost
self.items.append(item)
else:
print("That's not an item,",self.name)
print("Money left:",self.money)
Continue=input("Would you like to buy more? (y/n): ")
return self.items
def NewShopHomeBase():
choice=""
name=input("Enter name: ")
player = Player(name)
print("Info")
while choice not in ("N","No","no","n"):
choice=input("Would you like to buy or sell items? (B/S) or would you like to exit?(N): ")
if choice in("buy","b","Buy", "B"):
player.BuyItems()
elif choice in("sell","s","Sell", "S"):
player.SellItems()
NewShopHomeBase()