Skip to content

Commit 4d1b1b2

Browse files
committed
revision one
0 parents  commit 4d1b1b2

File tree

4 files changed

+1284
-0
lines changed

4 files changed

+1284
-0
lines changed

adventure.py

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Text Adventure Game
4+
An adventure in making adventure games.
5+
6+
To test your current solution, run the `test_my_solution.py` file.
7+
8+
Refer to the instructions on Canvas for more information.
9+
10+
"I have neither given nor received help on this assignment."
11+
author: Kane van Doorn
12+
"""
13+
__version__ = 8
14+
15+
# 2) print_introduction: Print a friendly welcome message for your game
16+
def print_introduction():
17+
# print the introduction including the setting and some story.
18+
19+
print("You're riding your horse when you hear a scream coming from a dark and looming tower in the distance")
20+
print("You think back to a few weeks ago.")
21+
print("You overheard some men at the local brothel talking about a missing princess.")
22+
print("You decide to take this as an opportunity to prove yourself to your guild.")
23+
print("You approach the tower and dismount your horse.")
24+
print("\nYou notice alligators are lurking in the water.")
25+
26+
# 3) get_initial_state: Create the starting player state dictionary
27+
28+
def get_initial_state():
29+
# Start the player states for the beginning of the game
30+
31+
initial_states = {'game status': 'playing',
32+
'location': 'The moat in front of the Tower',
33+
'Sword': False,
34+
'Crown': False
35+
}
36+
return initial_states
37+
38+
# 4) print_current_state: Print some text describing the current game world
39+
40+
def print_current_state(a_dict):
41+
# Current location in the world, updates as the player chooses options and moves through the world.
42+
43+
print("\nCurrent Location: "+ a_dict['location'] + ".")
44+
45+
# 5) get_options: Return a list of commands available to the player right now
46+
47+
def get_options(the_player):
48+
# Returns a list of options depending on where the player is in the world.
49+
50+
if the_player['location'] == 'The moat in front of the Tower':
51+
a_list = ['Take the sword out of the rock, kill the alligators.',
52+
'Attack the alligators with your fists.'
53+
]
54+
if the_player['location'] == 'Top of the Tower':
55+
a_list = ['Knock on the door.',
56+
'Use the sword to silently pick the lock.'
57+
]
58+
if the_player['location'] == 'Inside the bedroom':
59+
a_list = ['Steal the crown.',
60+
'Untie and save the princess.'
61+
]
62+
return a_list
63+
64+
# 6) print_options: Print out the list of commands available
65+
66+
def print_options(a_list):
67+
# Prints the options from get_options()
68+
69+
print('Your options are:')
70+
for x in a_list:
71+
print(x)
72+
73+
# 7) get_user_input: Repeatedly prompt the user to choose a valid command
74+
75+
def get_user_input(a_list):
76+
# While loop that will ask the user for input until a valid option is chosen or quit is chosen.
77+
78+
command = ""
79+
a = True
80+
while a == True:
81+
command = input('What would you like to do: ')
82+
if command in a_list:
83+
a = False
84+
if command.lower() == 'quit':
85+
a = False
86+
return command
87+
88+
89+
# 8) process_command: Change the player state dictionary based on the command
90+
91+
def process_command(a_command, a_player):
92+
# Process the command, this involves updating if the sword and crown have been picked up based off of what options are chosen.
93+
94+
if a_command == 'Take the sword out of the rock, kill the alligators.':
95+
a_player['location'] = 'Top of the Tower'
96+
a_player['Sword'] = True
97+
if a_command == 'Attack the alligators with your fists.':
98+
a_player['location'] = 'Bottom of the moat'
99+
a_player['game status'] = 'lose'
100+
if a_command == 'Knock on the door.':
101+
a_player['location'] = 'Bottom of the moat'
102+
a_player['game status'] = 'lose'
103+
if a_command == 'Use the sword to silently pick the lock.':
104+
a_player['location'] = 'Inside the bedroom'
105+
if a_command == 'Untie and save the princess.':
106+
a_player['location'] = 'Inside the bedroom'
107+
a_player['game status'] = 'lose'
108+
if a_command == 'Steal the crown.':
109+
a_player['location'] = 'Outside the tower'
110+
a_player['game status'] = 'win'
111+
if a_command.lower() == 'quit':
112+
a_player['game status'] = 'quit'
113+
114+
# 9) print_game_ending: Print a victory, lose, or quit message at the end
115+
116+
def print_game_ending(a_player):
117+
# Prints an ending based off if the player chooses a losing option, winning option, or inputs quit.
118+
119+
if a_player['location'] == 'Bottom of the moat' and a_player['game status'] == 'lose':
120+
print('You lost. The alligators ate you and you died. :(')
121+
if a_player['location'] == 'Bottom of the moat' and a_player['game status'] == 'lose':
122+
print('You lost. The evil witch heard you knocking and she killed you. :(')
123+
if a_player['location'] == 'Inside the bedroom' and a_player['game status'] == 'lose':
124+
print('You lost. Why would you save the princess if you could steal her crown? You are in a thiefs guild, STEAL THE CROWN')
125+
if a_player['location'] == 'Outside the tower' and a_player['game status'] == 'win':
126+
print('YOU WIN. You bring the crown back to the guild and sell it for a bag of gold.')
127+
if a_player['game status'] == 'quit':
128+
print('You quit the game. Goodbye!')
129+
else:
130+
print('Invalid Journey')
131+
132+
# Command Paths to give to the unit tester
133+
WIN_PATH = ['Take the sword out of the rock, kill the alligators.', 'Use the sword to silently pick the lock.', 'Steal the crown.']
134+
LOSE_PATH = ['Take the sword out of the rock, kill the alligators.', 'Use the sword to silently pick the lock.', 'Untie and save the princess.']
135+
136+
# 1) Main function that runs your game, read it over and understand
137+
# how the player state flows between functions.
138+
def main():
139+
# Print an introduction to the game
140+
print_introduction()
141+
# Make initial state
142+
the_player = get_initial_state()
143+
# Check victory or defeat
144+
while the_player['game status'] == 'playing':
145+
# Give current state
146+
print_current_state(the_player)
147+
# Get options
148+
available_options = get_options(the_player)
149+
# Give next options
150+
print_options(available_options)
151+
# Get Valid User Input
152+
chosen_command = get_user_input(available_options)
153+
# Process Commands and change state
154+
process_command(chosen_command, the_player)
155+
# Give user message
156+
print_game_ending(the_player)
157+
158+
# Executes the main function
159+
if __name__ == "__main__":
160+
'''
161+
You might comment out the main function and call each function
162+
one at a time below to try them out yourself '''
163+
main()
164+
## e.g., comment out main() and uncomment the line(s) below
165+
# print_introduction()
166+
# print(get_initial_state())
167+
# ...

practice.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import matplotlib as mp
2+

0 commit comments

Comments
 (0)