Monday, May 5, 2014

Day 30

Explored some Python at Gork Learning. Worked on, Hour of Code: The Dark Tunnel – adventure game! Put all learned functions into a copy of the completed game, with some added elements. Played the game a few times to finished the tutorial.

The code used:
monster_dead = False
has_sword = False
room = 1
end = False

print('The Dark Tunnel')
while not end:
# start room
if room == 1:
print("You are standing at the entrance to a long tunnel.")
if monster_dead == False:
print("You hear a low rumble in the distance.")
print("Actions available: look, forward")
cmd = input("> ")
if cmd == 'look':
if has_sword:
print("You look around in the darkness, but there is nothing here.")
else:
print("You look around in the darkness, and see something shiny.")
print("It is a sword. Would you like to pick it up (yes/no)? ")
get = input('> ')
if get == 'yes':
print('You pick up the sword.')
has_sword = True
else:
print('You leave the sword in the dust.')
elif cmd == 'forward':
room = 2
# monster room
elif room == 2:
if not monster_dead:
print("When you enter the room, a monster jumps out at you,")
print("its fangs white and sharp in the darkness.")
if has_sword:
print("You draw your sword and thrust it towards the leaping body.")
print("Your strike hits true and kills the monster.")
monster_dead = True
else:
print("With no way of defending yourself, the monster crushes")
print("your body and sinks its teeth into your flesh.")
print("You are dead.")
print("Game Over.")
end = True
else:
print("The monster's dead carcass lies on the floor,")
print("the sword still embedded in its flesh.")
# if the player is still alive, they can move
if not end:
print("Actions available: forward, backward")
cmd = input("> ")
if cmd == 'forward':
room = 3
elif cmd == 'backward':
room = 1
# exit - win condition
else:
print("You made it past the monster and have escaped the tunnel.")
print("Congratulations, you win.")
end = True

The interaction looked like this:
The Dark Tunnel
You are standing at the entrance to a long tunnel.
You hear a low rumble in the distance.
Actions available: look, forward
> look
You look around in the darkness, and see something shiny.
It is a sword. Would you like to pick it up (yes/no)?
> yes
You pick up the sword.
You are standing at the entrance to a long tunnel.
You hear a low rumble in the distance.
Actions available: look, forward
> look
You look around in the darkness, but there is nothing here.
You are standing at the entrance to a long tunnel.
You hear a low rumble in the distance.
Actions available: look, forward
> forward
When you enter the room, a monster jumps out at you,
its fangs white and sharp in the darkness.
You draw your sword and thrust it towards the leaping body.
Your strike hits true and kills the monster.
Actions available: forward, backward
> forward
You made it past the monster and have escaped the tunnel.
Congratulations, you win.

No comments:

Post a Comment