-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpc.py
67 lines (58 loc) · 2.26 KB
/
npc.py
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
import items
class NonPlayableCharacter():
def __init__(self):
raise NotImplementedError("Do not create raw NPC objects.")
def __str__(self):
return self.name
class Trader(NonPlayableCharacter):
def __init__(self):
self.name = "Trader"
self.gold = 100
self.inventory = [items.CrustyBread(),
items.CrustyBread(),
items.CrustyBread(),
items.HealingPotion(),
items.HealingPotion()]
def trader(self, buyer, seller):
for i, item in enumerate(seller.inventory, 1):
print("{}. {} - {} Gold".format(i, item.name, item.value))
while True:
user_input = input("Choose an item or press Q to Exit: ")
if user_input in ['q', 'Q']:
return
else:
try:
choice = int(user_input)
to_swap = seller.inventory[choice - 1]
self.swap(seller, buyer, to_swap)
except ValueError:
print("Invalid choice!")
def swap(self, seller, buyer, item):
if item.value > buyer.gold:
print("That's too expensive")
return
seller.inventory.remove(item)
buyer.inventory.append(item)
seller.gold = seller.gold + item.value
buyer.gold = buyer.gold - item.value
print("Trade complete!")
def check_if_trade(self, player):
while True:
print("Would you like to (B)uy, (S)ell, or (Q)uit?")
user_input = input()
if user_input in ['Q', 'q']:
return
elif user_input in ['B', 'b']:
print("Here's whats available to buy: ")
self.trade(buyer=player, seller=self.trader)
elif user_input in ['S', 's']:
print("Here's whats available to sell: ")
self.trade(buyer=self.trader, seller=player)
else:
print("Invalid choice!")
def intro_text(self):
return """
A frail not-quite-human,
not-quite-creature squats in the corner
clinking his gold coins together. He looks willing to trade.
"""