forked from codinggrace/text_based_adventure_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_06.py
100 lines (82 loc) · 3.11 KB
/
game_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Now we have a premise. We are in a room and we have two door to choose from.
# We are in the blue room. We find a treasure chest and a sleeping guard in
# front of a door.
#
# It's all about lists in this section
#
# Run this code a few times and see what happens with different choices.
# It's good to test all options and see if that's what you expected.
##### ACTIONS #####
def you_died(why):
'''
In: Passing in the string showing player how they dies
Result:
Prints reason why they player died.
Programme exits without error.
'''
# You expect a reason why the player died. It's a string.
print(f"{why}. Good job!")
# This exits the program entirely.
exit(0)
### END ACTIONS ###
##### ROOMS #####
def blue_door_room():
'''
The player finds a treasure chest, options to investigate the treasure
chest or guard.
'''
# The variable treasure_chest is an object type called a list
# A list maybe empty as well.
# So our treasure_chest list contains 4 items.
treasure_chest = ["diamonds", "gold", "silver", "sword"]
print("You see a room with a wooden treasure chest on the left, and a sleeping guard on the right in front of the door")
# Ask player what to do.
action = input("What do you do? > ")
# This is a way to see if the text typed by player is in the list
if action.lower() in ["treasure", "chest", "left"]:
print("Oooh, treasure!")
else:
print("The guard is more interesting, let's go that way!")
def red_door_room():
'''
The red door rooom contains a red dragon.
If a player types "flee" as an answer, player returns to the room with
two doors, otherwise the player dies.
'''
print("There you see a great red dragon.")
print("It stares at you through one narrowed eye.")
print("Do you flee for your life or stay?")
next_move = input("> ")
# Flee to return to the start of the game, in the room with the blue and
# red door or die!
if "flee" in next_move:
start_adventure()
else:
# You call the function you_died and pass the reason why you died as
# a string as an argument.
you_died("It eats you. Well, that was tasty!")
### END ROOMS ###
def start_adventure():
'''
This function starts the adventure by allowing two options for
players to choose from: red or blue door
Chosen option will print out the door chosen.
'''
print("You enter a room, and you see a red door to your left and a blue door to your right.")
door_picked = input("Do you pick the red door or blue door? > ")
# Pick a door and we go to a room and something else happens
if door_picked == "red":
red_door_room()
elif door_picked == "blue":
blue_door_room()
else:
print("Sorry, it's either 'red' or 'blue' as the answer. You're the weakest link, goodbye!")
def main():
'''
Gets the players name, print it out and starts the adventure.
'''
player_name = input("What's your name? >")
print(f"Your name is {player_name.upper()}")
start_adventure()
if __name__ == '__main__':
main()