forked from codinggrace/text_based_adventure_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_08.py
143 lines (114 loc) · 5.23 KB
/
game_08.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Now we have a premise. We are in a room and we have two door to choose from.
# We are still in the blue room. What do we do with the treasure chest?
#
##### 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.
'''
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.
If player chooses
- Treasure chest: show its contents; option to take treasure or ignore it (proceeds to guard)
- Guard: nothing for now
'''
# 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!")
print("Open it? Press '1'")
print("Leave it alone. Press '2'")
choice = input("> ")
if choice == "1":
print("Let's see what's in here... /grins")
print("The chest creaks open, and the guard is still sleeping. That's one heavy sleeper!")
print("You find some")
# for each treasure (variable created on the fly in the for loop)
# in the treasure_chest list, print the treasure.
for treasure in treasure_chest:
print(treasure)
# So much treasure, what to do? Take it or leave it.
print("What do you want to do?")
# Get number of items in treasure chest with len))
num_items_in_chest = len(treasure_chest)
print(f"Take all {num_items_in_chest} treasure, press '1'")
print("Leave it, press '2'")
treasure_choice = input("> ")
if treasure_choice == "1":
treasure_chest.remove("sword")
print("\tYou take the shinier sword from the treasure chest. It does looks exceedingly shiney.")
print("\tWoohoo! Bounty and a shiney new sword. /drops your crappy sword in the empty treasure chest.")
temp_treasure_list = treasure_chest[:]
treasure_contents = ", ".join(treasure_chest)
print(f"\tYou also receive {treasure_contents}.")
# Removing all the rest of the items in the treasure chest
for treasure in temp_treasure_list:
# Use list remove() function to remove each item in the chest.
treasure_chest.remove(treasure)
# Add the old sword in place of the new sword
treasure_chest.append("crappy sword")
print(f"\tYou close the lid of the chest containing {treasure_chest} for the next adventurer. /grins")
print("Now onward to get past this sleeping guard and the door to freedom.")
elif treasure_choice == "2":
print("It will still be here (I hope), right after I get past this guard")
elif choice == "2":
print("The guard is more interesting, let's go that way!")
elif action.lower() in ["guard", "right"]:
print("The guard is more interesting, let's go that way!")
else:
print("Well, not sure what you picked there, let's poke the guard cos it's fun!")
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()