-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
77 lines (62 loc) · 2.13 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
import cmd
class CreateCharacterCmd(cmd.Cmd):
"""Command line interface to create a character"""
prompt = '\n> '
player = None
def preloop(self):
self.player = Player()
def default(self, arg):
print('You cannot do this right now. Type "ready" when your '
'character is finished and you\'re ready to explore '
'or type "help" for a list of available commands')
def do_name(self, arg):
"""Set a name for your Character"""
self.player.name = arg
def do_profession(self, arg):
professions = ['developer', 'sales rep', 'designer']
if arg in professions:
self.player.profession = arg
else:
print('Sorry, this is not a valid profession. '
'Try one of the following:\n')
for profession in professions:
print('- ' + profession)
def do_ready(self, arg):
"""Quit creating your character and start exploring"""
if not self.player.name:
print('Please set a name before you continue')
return False
return True
class Player(object):
"""docstring for Player"""
experience = 0
name = None
profession = None
def currentRoom():
doc = "The currentRoom property."
def fget(self):
return self._currentRoom
def fset(self, room):
try:
self._lastRoom = self._currentRoom
except AttributeError:
pass
self._currentRoom = room
self._currentRoom.visit()
def fdel(self):
del self._currentRoom
return locals()
currentRoom = property(**currentRoom())
def drinkCoffee(self):
"""Drink coffee from the current room"""
if self.currentRoom.consumeCoffee():
self.experience += 1
return True
return False
def drinkAllCoffee(self):
"""Drink all coffee from the current room"""
drankCoffee = False
while self.currentRoom.canConsumeCoffee:
self.drinkCoffee()
drankCoffee = True
return drankCoffee