-
Notifications
You must be signed in to change notification settings - Fork 0
/
loc.py
44 lines (34 loc) · 1.27 KB
/
loc.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
from obj import ObjectWithAttributes, NamedObject
class Neighborhood (ObjectWithAttributes):
def __init__ (self):
ObjectWithAttributes.__init__ (self)
class Connection (ObjectWithAttributes):
def __init__ (self, dest):
ObjectWithAttributes.__init__ (self)
self.m_dest = dest
def dest (self):
return self.m_dest
class Location (ObjectWithAttributes, NamedObject):
def __init__ (self, name, neighborhood = None):
ObjectWithAttributes.__init__ (self)
NamedObject.__init__ (self, name)
self.m_neighborhood = neighborhood
self.m_connections = set ()
self.m_clue_tokens = 0
def add_connection (self, conn):
assert conn not in self.m_connections
self.m_connections.add (conn)
def add_clue_tokens (self, n):
assert n >= 0
self.m_clue_tokens += n
def connections (self):
return list (self.m_connections)
class ObjectWithLocation:
def __init__ (self, initial_location):
self.m_location = initial_location
def location (self):
return self.m_location
def move_to (self, location):
print "ObjectWithLocation.move_to %s->%s" \
% (self.name (), location.name () if location else "None")
self.m_location = location