711
« on: July 23, 2009, 05:53:23 pm »
After switching to python, I found I could write really simple games sans guides or tutorials. Likeprint "Typing run() brings up the semi menu. The four directions are north, east, west, and south. You're in the center of a 10 by 10 room."
c = 1
xaxis = 5
yaxis = 5
def move(prompt):
global xaxis
global yaxis
while True:
room = raw_input(prompt)
if room in ('north'):
print "You move forward."
xaxis = xaxis - 1
if xaxis <= 0:
print "You've run into a wall."
xaxis = xaxis + 1
checkforholes()
return False
elif room in ('south'):
print "You move backward."
xaxis = xaxis + 1
if xaxis >= 10:
print "You've run into a wall."
xaxis = xaxis - 1
checkforholes()
return False
elif room in ('west'):
print "You move to the left"
yaxis = yaxis - 1
if yaxis <= 0:
print "You've run into a wall."
yaxis = yaxis +1
checkforholes()
return False
elif room in ('east'):
print "You move to the right"
yaxis = yaxis + 1
if yaxis >= 10:
print "You've run into a wall"
yaxis = yaxis - 1
checkforholes()
return False
def checkforholes():
global c
global xaxis
global yaxis
if xaxis == 6 and yaxis == 5:
print "You have fallen through a hole. You have entered another 10x10 room."
if c >= 2:
print "You have entered", c, "holes",
c = c + 1
xaxis = 5
yaxis = 5
else:
c = c + 1
xaxis = 5
yaxis = 5
def show():
global xaxis
global yaxis
global c
while True:
show = raw_input()
if show in ('show'):
print "Your coordinates are", xaxis,",", yaxis, "and you have seen", c,"holes",
return False
def start(prompt):
mov = raw_input(prompt)
if mov in ('move'):
move('Where do you want to go?')
elif mov in ('show'):
show()
def run():
start('Type, move to move and show to show status')
Point of the game - fall down the hole.