-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.py
131 lines (115 loc) · 4.15 KB
/
character.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import room
import house
import things
class Character(object):
def __init__(self, name, position):
self.content = []
self.name = name
self.position = position
self.scope = self
self.keychain = []
def choose_player(self, name):
if position != self.hallway:
return "You must be in the hallway to change player"
if name=="Elin":
return "You are playing as Elin"
if name=="Murneh":
return "You are playing as Murneh"
return "You must choose either Murneh or Elin"
def pick_up(self, obj):
"Pick up things from the room the character is in."
if type(obj) == things.Things:
if len(self.content)>10:
return "You can't carry anymore."
if obj in self.scope.content:
self.scope.content.remove(obj)
self.content.append(obj)
return "You picked up "+obj.name+"."
if obj not in self.position.content:
return "THERE IS NO SUCH THING! ARE YOU HALLUCINATING?"
else:
self.position.content.remove(obj)
self.content.append(obj)
return "You picked up "+obj.name+"."
if type(obj) == things.Key:
if obj in self.scope.content:
self.scope.content.remove(obj)
self.keychain.append(obj)
return "You added "+obj.name+" to you keychain."
if obj not in self.position.content:
return "THERE IS NO SUCH THING! ARE YOU HALLUCINATING?"
else:
self.position.content.remove(obj)
self.keychain.append(obj)
return "You added "+obj.name+" to your keychain."
else:
return "This is not something you can pick up."
def drop(self, obj):
"Drop things in the characters current room."
if not obj in self.content:
return "You can not drop what you do not have."
self.content.remove(obj)
self.position.content.append(obj)
return "You dropped "+str(obj)+"."
def look_inside(self, obj): #look inside objects. makes it possible to pick up things from inside objects. eg a single cigarette from inside a package.
things = []
if obj in self.position.content:
self.scope = obj
for Things in obj.content:
things.append(str(Things))
return "You see "+" and ".join(things)+"."
if obj in self.content:
self.scope = obj
for Things in obj.content:
things.append(str(Things))
return "You see "+" and ".join(things)+"."
if obj in self.scope.content:
self.scope = obj
for Things in obj.content:
things.append(str(Things))
return "You see "+" and ".join(things)+"."
else:
return "THERE IS NO SUCH THING! ARE YOU HALLUCINATING?"
def move(self, direction):
self.scope = self
if direction=="north":
if self.position.north == False:
return "You can't, there is no door here."
else:
return self.check_lock(self.position.north)
elif direction=="south":
if self.position.south == False:
return "You can't, there is no door here."
else:
return self.check_lock(self.position.south)
elif direction=="west":
if self.position.west == False:
return "You can't, there is no door here."
else:
return self.check_lock(self.position.west)
elif direction=="east":
if self.position.east == False:
return "You can't, there is no door here."
else:
return self.check_lock(self.position.east)
def check_lock(self, room):
key_count = 0
if room.lock == False:
self.position = room
return "You enter the "+self.position.name+"."
else:
for Key in self.keychain:
if Key.unlock == room:
key_count = key_count+1
if key_count == room.keys_required:
self.position = room
return "You unlock the door and enter the "+self.position.name+"."
else:
return "You can't, it's locked. Maybe you still need something to unlock it."
def __str__(self):
inventory = []
for obj in self.content:
inventory.append(str(obj))
return "You are in "+self.position.name+". "+"In your inventory there are " + " and ".join(inventory)+"."