Thursday, May 1, 2014

Day 26

Explored some Python at Gork Learning. Worked on, Hour of Code: The Dark Tunnel – adventure game! Learned to use the elif function to store the user's current location in a variable room, and updating that variable based on their chosen action.

The code I used:
print("Actions available: forward, backward, look")
action = input("> ")
if action == "forward":
room = "end"
elif action == "backward":
room = "start"
elif action == "look":
room = "look"
else:
room = "middle"
if room == "end":
print("You have escaped the tunnel. You win!")
elif room == "start":
print("You are standing at the entrance to a long tunnel.")
elif room == "middle":
print("I don’t know about that but You are in the depths of the tunnel.")
print("A Troll hit you over the head and now you are dead!")
elif room == "look":
print("You can barely see a few feet around you but there is a small light in front of you and behind you.")

The interactions looked like this:
Actions available: forward, backward, look
> forward
You have escaped the tunnel. You win!

Actions available: forward, backward, look
> backward
You are standing at the entrance to a long tunnel.

Actions available: forward, backward, look
> look
You can barely see a few feet around you but there is a small light in front of you and behind you.

Actions available: forward, backward, look
> No
I don’t know about that but you are in the depths of the tunnel.
A Troll hits you over the head and now you are dead!

No comments:

Post a Comment