-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathㅤSolved-Questions-39.c
More file actions
233 lines (202 loc) · 7.48 KB
/
Copy pathㅤSolved-Questions-39.c
File metadata and controls
233 lines (202 loc) · 7.48 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
---------------------------------------------------------------------------------------Question-39---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Your task is to design a game where the player embarks on an adventurous treasure hunt. The game features an adventurer tasked with navigating a perilous treasure hunt in a mysterious labyrinth. The labyrinth is filled with traps, riddles, and challenges that will test his wit and bravery. The goal is to find the ultimate treasure hidden in one of the secret chambers. The objective is to simulate the treasure hunt journey and generate responses based on the player's decisions.
The game should display corresponding messages in new line for each action the player takes.
Game Description:
Starting Point: You begin at the entrance of the labyrinth. You must choose between three paths:
1: The Left Path (leads to a swamp).
2: The Middle Path (leads to a maze).
3: The Right Path (leads to an underground vault).
Left Path (Swamp):
You encounter a swamp. Your choices are:
1: Attempt to cross the swamp on foot.
Risk: Hidden quicksand which ends the game.
2: Search for a bridge to cross safely.
If you search for a bridge:
1: You find a sturdy bridge (safe crossing) and proceed to the final room.
2: The bridge collapses, and you fall into the swamp (lose the game).
Middle Path (Maze):
You enter a labyrinth filled with dead ends. To find the exit, you must solve a puzzle:
Puzzle: "I am a three-digit number. My second digit is four times bigger than the third digit, my first digit is three less than the second digit, and the sum of my digits is 15. What number am I?"
If you solve the puzzle correctly, you can proceed to the final room.
If incorrect, you trigger a trap and lose.
Right Path (Underground Vault):
You find a locked vault guarded by a puzzle.
Puzzle: "What number comes next in the sequence: 2, 6, 12, 20, __?"
A wrong answer triggers an alarm, and you are caught (game over).
If you solve the puzzle, you open the vault to find key to the final room.
Final Room:
Each successful path leads to a final treasure room.
There are three chests:
1: Take the Golden Chest (contains a deadly trap and ends the game).
2: Take the Silver Chest (an empty chest, player loses gaining nothing).
3: Take the Bronze Chest (contains the ultimate treasure, player wins the game).
Input Format
The first input is an integer representing the chosen path at the labyrinth entrance:
1 for the Left Path.
2 for the Middle Path.
3 for the Right Path.
Based on the chosen path:
For Left Path:
A second input, an integer, represents the action in the swamp:
1 to attempt crossing on foot.
2 to search for a bridge.
If 2, a third input is required:
1 if the bridge is sturdy.
2 if the bridge collapses.
For Middle Path:
A second input is the player's answer to the puzzle.
For Right Path:
A second input is the player's answer to the sequence puzzle.
After reaching the final room, a final input is required:
1 to choose the Golden Chest.
2 to choose the Silver Chest.
3 to choose the Bronze Chest.
Constraints
Path Choice:
Input must be 1, 2, or 3.
Action Choice:
Left Path: 1 or 2.
Middle Path: A valid 3-digit number.
Right Path: A valid single number.
Treasure Chest:
Input must be 1, 2, or 3.
Output Format
The game should print one message per decision, followed by the final outcome:
For the Entrance:
"Player chooses the [Left/Middle/Right] path."
For Left Path (Swamp):
If 1: "Poor choice, Game Over!"
If 2: "Player found a bridge.", and
1: "Player crosses the bridge safely"
2: "Poor luck, Game Over!"
For Middle Path (Maze):
If the puzzle is correct: "Player solved the puzzle."
If the puzzle is incorrect: "Foolish player, Game Over!"
For Right Path (Vault):
If the puzzle is correct: "Player solved the puzzle."
If the puzzle is incorrect: "Foolish player, Game Over!"
For the Final Room:
If 1: "All that glitters is not gold, Game Over!"
If 2: "All your efforts were for nothing, Game Over!"
If 3: "Congratulations!! You won the treasure."
Sample Input 0
1
2
1
3
Sample Output 0
Player chooses the Left path.
Player found a bridge.
Player crosses the bridge safely.
Congratulations!! You won the treasure.
Sample Input 1
1
1
3
Sample Output 1
Player chooses the Left path.
Poor choice, Game Over!
Sample Input 2
1
2
2
3
Sample Output 2
Player chooses the Left path.
Player found a bridge.
Poor luck, Game Over!
Sample Input 3
1
2
1
3
Sample Output 3
Player chooses the Left path.
Player found a bridge.
Player crosses the bridge safely.
Congratulations!! You won the treasure.
Sample Input 4
1
2
1
1
Sample Output 4
Player chooses the Left path.
Player found a bridge.
Player crosses the bridge safely.
All that glitters is not gold, Game Over!
Sample Input 5
1
2
1
2
Sample Output 5
Player chooses the Left path.
Player found a bridge.
Player crosses the bridge safely.
All your efforts were for nothing, Game Over!
---------------------------------------------------------------------------------------Answer-39---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
int main() {
int path;
scanf("%d", &path);
if (path == 1) {
printf("Player chooses the Left path.\n");
} else if (path == 2) {
printf("Player chooses the Middle path.\n");
} else if (path == 3) {
printf("Player chooses the Right path.\n");
}
int reaches_final = 0;
if (path == 1) {
int action;
scanf("%d", &action);
if (action == 1) {
printf("Poor choice, Game Over!\n");
return 0;
} else if (action == 2) {
printf("Player found a bridge.\n");
int bridge;
scanf("%d", &bridge);
if (bridge == 1) {
printf("Player crosses the bridge safely.\n");
reaches_final = 1;
} else if (bridge == 2) {
printf("Poor luck, Game Over!\n");
return 0;
}
}
} else if (path == 2) {
int answer;
scanf("%d", &answer);
if (answer == 582) {
printf("Player solved the puzzle.\n");
reaches_final = 1;
} else {
printf("Foolish player, Game Over!\n");
return 0;
}
} else if (path == 3) {
int answer;
scanf("%d", &answer);
if (answer == 30) {
printf("Player solved the puzzle.\n");
reaches_final = 1;
} else {
printf("Foolish player, Game Over!\n");
return 0;
}
}
if (reaches_final) {
int chest;
scanf("%d", &chest);
if (chest == 1) {
printf("All that glitters is not gold, Game Over!\n");
} else if (chest == 2) {
printf("All your efforts were for nothing, Game Over!\n");
} else if (chest == 3) {
printf("Congratulations!! You won the treasure.\n");
}
}
return 0;
}