-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextbasedadventure.cpp
More file actions
79 lines (79 loc) · 2.05 KB
/
textbasedadventure.cpp
File metadata and controls
79 lines (79 loc) · 2.05 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
#include <iostream>
#include <string>
using namespace std;
void display() {
cout << "Welcome to the Text Adventure Game!" << endl;
cout << "You find yourself in a mysterious land with several rooms." << endl;
cout << "Your goal is to find the hidden treasure and escape." << endl;
cout << "Good luck!" << endl << endl;
}
int getplayer() {
int c;
cout << "Enter your choice: ";
cin >> c;
return c;
}
void room1();
void room2();
void room3();
void room1() {
cout << "You are in Room 1. There are doors to Room 2 and Room 3." << endl;
cout << "1. Go to Room 2" << endl;
cout << "2. Go to Room 3" << endl;
int choice = getplayer();
if (choice == 1) {
room2();
} else if (choice == 2) {
room3();
} else {
cout << "Invalid choice. Try again." << endl;
room1();
}
}
void room2() {
cout << "You are in Room 2. There are doors to Room 1 and Room 3." << endl;
cout << "1. Go to Room 1" << endl;
cout << "2. Go to Room 3" << endl;
int choice = getplayer();
if (choice == 1) {
room1();
} else if (choice == 2) {
room3();
} else {
cout << "Invalid choice. Try again." << endl;
room2();
}
}
void room3() {
cout << "You are in Room 3. There is a door to Room 1 and a hidden treasure here!" << endl;
cout << "1. Go to Room 1" << endl;
cout << "2. Take the treasure and win the game!" << endl;
int choice = getplayer();
if (choice == 1) {
room1();
} else if (choice == 2) {
cout << "Congratulations! You found the hidden treasure and won the game!" << endl;
} else {
cout << "Invalid choice. Try again." << endl;
room3();
}
}
int main() {
display();
int m;
cout<<"Enter the room number(1,2,3):"<<endl;
cin>>m;
if(m==1){
room1();
}
else if(m==2){
room2();
}
else if(m==3){
room3();
}
else{
cout<<"Invalid !"<<endl;
}
return 0;
}