Skip to content

Instantly share code, notes, and snippets.

@wujiang
Created February 24, 2016 18:26
Show Gist options
  • Save wujiang/e208f3eb25215b7dff1b to your computer and use it in GitHub Desktop.
Save wujiang/e208f3eb25215b7dff1b to your computer and use it in GitHub Desktop.
class mapNode(object):
def __init__(self):
self.num = None
self.e = None
self.w = None
self.n = None
self.s = None
self.lock = None
def main():
# create a map of n tiles
nodes = []
for i in range(n):
node = mapNode
node.num = 1
nodes.append(node)
doors[{e:node[2]},{w:1,e:3,s:4,t:'ruby'},{}]
for i in range(n):
for each in doors:
for k,v in each:
#k = e , v: 2
#node.e = node 2
if( k == 't'):
node[i].t = v
if( k == 'e'):
node[i].e = nodes[v]
if( k == 'w'):
node[i].w = nodes[v]
if( k == 'n'):
node[n].n = nodes[v]
if( k == 's'):
node[i].s = nodes[v]
#all doors and treasures are mapped
start = node[0]
player1 = player()
player2 = player()
player1.play(start)
player2.play(start)
class player(object:
def __init__(self):
self.path = None # list of mapNodes (path)
self.treasures = None # list of treasures collected {room: treasure}
def distance_travelled(self):
return len(self.path)
def play(self, start):
while true:
if start.lock not None:
continue
print "you are at tile:", start.num
if(start.e != None):
print "There is a door to the east"
if(start.w != None):
print "There is a door to the east"
if(start.n != None):
print "There is a door to the east"
if(start.s != None):
print "There is a door to the east"
if(start.t != None):
print "There is a treasure in the rooom:", start.t
player.path.append(start)
choice = raw_input("Pick a direction, e,w,n,s or t to take treasure)")
switch(choice): # there is no switch in python!
case 'e':
if(start.e !=None):
start.lock = None
start = start.e
break;
case 'w'
if(start.w !=None):
start = start.w
break;
case 'n'
if(start.n !=None):
start = start.w
break;
case 's'
if(start.s !=None):
start = start.s
break;
case 't'
if(start.t !=None):
player.treasures[start.num] = start.t
start.t = None
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment