-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathdungeon_adventure.py
More file actions
151 lines (122 loc) · 4.96 KB
/
dungeon_adventure.py
File metadata and controls
151 lines (122 loc) · 4.96 KB
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
144
145
146
147
148
149
150
151
import random
def main():
def setup_player():
"""
Prompts the user to create their player profile.
Returns:
dict: A dictionary containing player stats with the following keys:
- "name" (str): Player's name (entered by user)
- "health" (int): Starting health, set to 10
- "inventory" (list): Starts as an empty list
Example:
>>> setup_player()
Enter your name: Ailene
{'name': 'Ailene', 'health': 10, 'inventory': []}
"""
# TODO: Ask the user for their name using input()
# TODO: Initialize a dictionary with keys: "name", "health", and "inventory"
# TODO: Return the dictionary
def create_treasures():
"""
Creates a dictionary of treasures, where each treasure has a value.
Returns:
dict: Example:
{
"gold coin": 5,
"ruby": 10,
"ancient scroll": 7,
"emerald": 9,
"silver ring": 4
}
Tip:
You can customize treasures or randomize the values using random.randint(3, 12).
"""
# TODO: Create a dictionary of treasure names and integer values
# TODO: Return the dictionary
def display_options(room_number):
"""
Displays available options for the player in the current room.
Args:
room_number (int): The current room number.
Output Example:
You are in room 3.
What would you like to do?
1. Search for treasure
2. Move to next room
3. Check health and inventory
4. Quit the game
"""
# TODO: Print the room number and the 4 menu options listed above
def search_room(player, treasures):
"""
Simulates searching the current room.
If the outcome is 'treasure', the player gains an item from treasures.
If the outcome is 'trap', the player loses 2 health points.
Args:
player (dict): The player's current stats.
treasures (dict): Dictionary of available treasures.
Behavior:
- Randomly choose outcome = "treasure" or "trap"
- If treasure: choose a random treasure, add to player's inventory,
and print what was found.
- If trap: subtract 2 from player's health and print a warning.
"""
# TODO: Randomly assign outcome = random.choice(["treasure", "trap"])
# TODO: Write an if/else to handle treasure vs trap outcomes
# TODO: Update player dictionary accordingly
# TODO: Print messages describing what happened
def check_status(player):
"""
Displays the player’s current health and inventory.
Args:
player (dict): Player stats including health and inventory.
Example Output:
Health: 8
Inventory: ruby, gold coin
or:
Health: 10
Inventory: You have no items yet.
"""
# TODO: Print player health
# TODO: If the inventory list is not empty, print items joined by commas
# TODO: Otherwise print “You have no items yet.”
def end_game(player, treasures):
"""
Ends the game and displays a summary.
Args:
player (dict): Player stats.
treasures (dict): Treasure dictionary for item value lookup.
Output:
Prints player’s final health, inventory contents, and total score value.
"""
# TODO: Calculate total score by summing the value of collected treasures
# TODO: Print final health, items, and total value
# TODO: End with a message like "Game Over! Thanks for playing."
def run_game_loop(player, treasures):
"""
Main game loop that manages the rooms and player decisions.
Args:
player (dict): Player stats.
treasures (dict): Treasure dictionary.
Flow:
- There are 5 rooms (use for loop range(1, 6))
- Inside each room, use a while loop for player actions:
1. Search room
2. Move to next room
3. Check status
4. Quit
- Health below 1 ends the game early.
"""
# TODO: Loop through 5 rooms (1–5)
# TODO: Inside each room, prompt player choice using input()
# TODO: Use if/elif to handle each choice (1–4)
# TODO: Break or return appropriately when player quits or dies
# TODO: Call end_game() after all rooms are explored
# -----------------------------------------------------
# GAME ENTRY POINT (Leave this section unchanged)
# -----------------------------------------------------
player = setup_player()
treasures = create_treasures()
run_game_loop(player, treasures)
if __name__ == "__main__":
main()