-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
101 lines (73 loc) · 2.82 KB
/
player.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
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
import items
import world
import npcs
class Player():
def __init__(self):
# self.inventory = [items.Rock()]
self.inventory = [items.Pen()]
self.hp = 100
self.location_x, self.location_y = world.starting_position
self.victory = False
self.badge = False
def is_alive(self):
return self.hp > 0
def print_inventory(self):
if self.inventory:
print "\tYou are carrying:"
for item in self.inventory:
print"\t{}".format(item.name)
# def describe_item(self, itemname="A pen"):
def describe_item(self):
if self.inventory:
for item in self.inventory:
print "\t{}".format(item.name)
print "\t{}".format(item.description)
def describe_an_item(self, item):
if self.inventory:
if item in self.inventory:
print "\t{}".format(item.description)
def describe_npc(self, npc):
print npcs.npc.description
# if world(self.location_x, self.location_y) is type(NPCRoom):
# print "This is NPC room"
def move(self, dx, dy):
self.location_x += dx
self.location_y += dy
# print self.location_x, self.location_y
#print (world.tile_exists(self.location_x, self.location_y))
room = world.tile_exists(self.location_x, self.location_y)
print room.room_name()
print room.intro_text()
room.mydefault()
if room.inventory is not None:
for item in room.inventory:
print "\t{} is here.".format(item.name)
room.exits_text()
# print(world.tile_exists(self.location_x, self.location_y).room_name())
# print(world.tile_exists(self.location_x, self.location_y).intro_text())
def move_north(self):
self.move(dx=0, dy=-1)
def move_south(self):
self.move(dx=0, dy=1)
def move_east(self):
self.move(dx=1, dy=0)
def move_west(self):
self.move(dx=-1, dy=0)
# def attack(self, enemy):
# best_weapon = None
# max_dmg = 0
# for i in self.inventory:
# if isinstance(i, items.Weapon):
# if i.damage > max_dmg:
# max_dmg = i.damage
# best_weapon = i
# print("You use {} against {}!".format(best_weapon.name, enemy.name))
# enemy.hp -= best_weapon.damage
# if not enemy.is_alive():
# print("You killed {}!".format(enemy.name))
# else:
# print("{} HP is {}.".format(enemy.name, enemy.hp))
def do_action(self, action, **kwargs):
action_method = getattr(self, action.method.__name__)
if action_method:
action_method(**kwargs)