-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshop.py
More file actions
90 lines (88 loc) · 4.2 KB
/
shop.py
File metadata and controls
90 lines (88 loc) · 4.2 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
from game_data import get_shop_items
def shop_loop(game_state):
option = input("Check coins, buy armor, buy sword, buy trinket, buy potion, list inventory, or exit? ").lower()
if option == "check coins":
print("You have " + str(game_state.player.coins) + " coins")
shop_loop(game_state)
elif option == "exit":
print("Before entering battle what would you like to do?")
from main import pre_battle
pre_battle(game_state)
elif option == "buy armor":
for armor in game_state.shop_items["armors"]:
print(f"{armor['type'].title()} - {armor['cost']} coin(s)")
print("or None")
shop_armor = input("Which armor type would you like? ").lower()
if shop_armor == "none":
print("You didn't buy anything")
shop_loop(game_state)
for armor in game_state.shop_items["armors"]:
if armor["type"] == shop_armor:
if game_state.player.coins >= armor["cost"]:
print("Armor Successfully Bought")
game_state.player.coins -= armor["cost"]
game_state.player.inventory.append(armor["name"])
shop_loop(game_state)
else:
print("You couldn't afford it")
shop_loop(game_state)
elif option == "buy sword":
for sword in game_state.shop_items["swords"]:
print(f"{sword['type'].title()} - {sword['cost']} coin(s)")
print("or None")
shop_sword = input("Which sword type would you like? ").lower()
if shop_sword == "none":
print("You didn't buy anything")
shop_loop(game_state)
for sword in game_state.shop_items["swords"]:
if sword["type"] == shop_sword:
if game_state.player.coins >= sword["cost"]:
print("Sword Successfully Bought")
game_state.player.coins -= sword["cost"]
game_state.player.inventory.append(sword["name"])
shop_loop(game_state)
else:
print("You couldn't afford it")
shop_loop(game_state)
elif option == "buy trinket":
print("What type of trinket would you like? They're all 5 coins!")
print("They can give health, speed, and strength!")
print("They come as rings, amulets, and charms!")
shop_trinket = input("Please type the name of the trinket you would like (type + power)").title()
for trinket in game_state.shop_items["trinkets"]:
if trinket["name"] == shop_trinket:
if game_state.player.coins >= trinket["cost"]:
print("Trinket Successfully Bought")
game_state.player.coins -= trinket["cost"]
game_state.player.inventory.append(trinket["name"])
shop_loop(game_state)
else:
print("You left the shop.")
shop_loop(game_state)
elif option == "list inventory":
print("Your inventory contains " + str(game_state.player.inventory) + "!")
shop_loop(game_state)
elif option == "buy potion":
types = set()
for potion in game_state.shop_items["potions"]:
types.add(potion["type"])
for potion_type in types:
print(potion_type.title())
print("or None")
potionchoice = input("Which type would you like ").lower()
if potionchoice == "none":
shop_loop(game_state)
potionpotent = int(input("What potentcy 1-4 ").strip())
for potion in game_state.shop_items["potions"]:
if potion["type"] == potionchoice and potion["potentcy"] == potionpotent:
if game_state.player.coins >= potion["cost"]:
game_state.player.coins -= potion["cost"]
game_state.player.inventory.append(potion["name"])
print("Successfully bought potion!")
shop_loop(game_state)
else:
print("You couldn't afford it")
shop_loop(game_state)
else:
print("Unknown command please try again")
shop_loop(game_state)