-
Notifications
You must be signed in to change notification settings - Fork 5
/
adventure-game.cpp
98 lines (89 loc) · 2.08 KB
/
adventure-game.cpp
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
#include <iostream>
#include <string>
using namespace std;
// Function to get user input
string getUserInput()
{
string input;
cout << "> ";
getline(cin, input);
return input;
}
// Function to handle room interactions
void handleRoom(string roomName)
{
cout << "You are in the " << roomName << " room." << endl;
// Room-specific interactions
if (roomName == "kitchen")
{
cout << "You see a refrigerator and a stove." << endl;
}
else if (roomName == "bedroom")
{
cout << "You see a bed and a dresser." << endl;
}
else if (roomName == "bathroom")
{
cout << "You see a sink and a toilet." << endl;
}
}
int main()
{
string room = "kitchen"; // Starting room
// Game loop
while (true)
{
handleRoom(room);
// Get user input
string input = getUserInput();
// Handle user input
if (input == "exit")
{
cout << "Goodbye!" << endl;
break;
}
else if (input == "north")
{
if (room == "kitchen")
{
room = "bedroom";
}
else if (room == "bedroom")
{
cout << "There is no exit to the north." << endl;
}
else if (room == "bathroom")
{
room = "kitchen";
}
}
else if (input == "south")
{
if (room == "kitchen")
{
room = "bathroom";
}
else if (room == "bedroom")
{
room = "kitchen";
}
else if (room == "bathroom")
{
cout << "There is no exit to the south." << endl;
}
}
else if (input == "west")
{
cout << "There is no exit to the west." << endl;
}
else if (input == "east")
{
cout << "There is no exit to the east." << endl;
}
else
{
cout << "Invalid command." << endl;
}
}
return 0;
}