Created
August 12, 2012 18:40
-
-
Save RyanBreaker/3333646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def go(direc): | |
direcs = ["north",'n', "south",'s', "east",'e', "west",'w'] | |
diags = ["northeast",'ne', "northwest",'nw', "southeast",'se', "southwest",'sw'] | |
if direc in direcs: | |
if direc == direcs[0] or direc == direcs[1]: | |
x += 1 | |
elif direc == direcs[2] or direc == direcs[3]: | |
x -= 1 | |
elif direc == direcs[4] or direc == direcs[5]: | |
y += 1 | |
elif direc == direcs[6] or direc == direcs[7]: | |
y -= 1 | |
else: | |
exit("ERROR: In go()") | |
elif direc in diags: | |
if direc == diags[0] or direc == diags[1]: | |
x += 1 | |
y += 1 | |
elif direc == diags[2] or direc == diags[3]: | |
x += 1 | |
y -= 1 | |
elif direc == diags[4] or direc == diags[5]: | |
x -= 1 | |
y += 1 | |
elif direc == diags[6] or direc == diags[7]: | |
x -= 1 | |
y -= 1 | |
else: | |
exit("ERROR: In go()") | |
else: | |
if direc == "": | |
print "Go where?" | |
else: | |
print "I have no idea where that is." | |
x = 5 | |
y = 2 | |
go('north') | |
print x,y | |
go('w') | |
print x,y | |
go('') | |
print x,y | |
go() | |
print x,y | |
""" | |
ryan@crunchbang:~/py/game$ python movement.py | |
Traceback (most recent call last): | |
File "movement.py", line 39, in <module> | |
go('north') | |
File "movement.py", line 6, in go | |
x += 1 | |
UnboundLocalError: local variable 'x' referenced before assignment | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment