-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshop.py
More file actions
82 lines (67 loc) · 2.21 KB
/
shop.py
File metadata and controls
82 lines (67 loc) · 2.21 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
import random
from player import currentPlayer
from items import *
import clock as clock
buyItemTypes = [string, cloth, fruit_dish]
#every item
allItemTypes = {
"blueberry" : blueberry,
"strawberry" : strawberry,
"apple" : apple,
"shijemi" : shijemi,
"onion" : onion,
"ginger" : ginger,
"mint" : mint,
"branch" : branch,
"twig" : twig,
"bark" : bark,
"stone" : stone,
"pebbles" : pebbles,
"sand" : sand,
"vine" : vine,
"string" : string,
"cloth" : cloth,
"dirt" : dirt,
"brick" : brick,
"pole" : pole,
"glass" : glass,
"fruit_dish" : fruit_dish
}
class Shop(object):
def __init__(self):
pass
@staticmethod
def buyPrompt(player):
global buyItemTypes
itemForSale = Item(random.choice(buyItemTypes))
print ("Here's a cool item to buy: the %s!! Only %s g!!!" % (itemForSale, itemForSale.buyPrice))
purchase = input(">")
if not purchase in ["yes", "y"]:
return False
if player.money < itemForSale.buyPrice:
print ("You can't afford that. It costs %s g and you only have %s." % (itemForSale.buyPrice, player.money))
return
player.money -= itemForSale.buyPrice
player.inventory.add(itemForSale)
currentPlayer.addCount(1)
print ("You bought a shiny new %s for %s g." % (itemForSale, itemForSale.buyPrice))
@staticmethod
def sellPrompt(player):
print ("Here's what you can sell right now:")
player.inventory.printSellable()
playerInput = input(">")
if playerInput not in allItemTypes.keys():
print ("That's not a type of item.")
return
itemType = allItemTypes[playerInput]
if not itemType.sellable:
print ("Nobody wants to buy that.")
return
if not player.inventory.containsType(itemType):
print ("You don't have one to sell.")
return
itemToSell = player.inventory.findType(itemType)
player.inventory.remove(itemToSell)
player.money += itemToSell.sellPrice
currentPlayer.addCount(1)
print ("You sold your %s for %s g." % (itemToSell, itemToSell.sellPrice))