-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (70 loc) · 1.91 KB
/
main.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
#include <iostream>
#include <string>
#include "h_files/world.h"
#include <vector>
using namespace std;
void clear(){
cout << string(1024, '\n');
}
int main(){
world world_container;
world_container.init();
int ch;
while(true){
int ch;
cout << "1) move to next room \nEnter your choice: ";
cin >> ch;
if(ch==1){
bool *connects = world_container.rooms_player_can_enter();
int dirs = 0;
for (int i = 0; i < 4;i++){
if(connects[i]==true){
dirs += 1;
}
}
vector<vector<int>> choices;
int *pos = world_container.get_active_room_pos();
int diff[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
for (int i = 0; i < 4;i++){
if(connects[i]==true){
choices.push_back({pos[0] + diff[i][0],pos[1] + diff[i][1]});
cout << choices.size();
if(i==0){
cout << ") go up" << endl;
}else if(i==1){
cout << ") go right" << endl;
}else if(i==2){
cout << ") go down" << endl;
}else if(i==3){
cout << ") go left" << endl;
}
}
}
if(world_container.is_exit(world_container.get_active_room_pos()) == true){
cout << choices.size() + 1 << ") exit" << endl;
}
cout <<"Enter your choice: ";
cin >> ch;
while(true){
if(ch < 1 || ch > choices.size()+1){
cout << "invalid input! try again! \nEnter your choice: ";
cin >> ch;
}else{
break;
}
}
if(ch == choices.size() + 1){
cout << "thanks for playing!" << endl;
break;
}
int new_pos[2] = {choices[ch-1][0], choices[ch-1][1]};
world_container.change_active_room(world_container.get_room_id(new_pos));
world_container.show_map();
}else if(ch==2){
cout << "thanks for playing!" << endl;
break;
}else{
cout << "invalid input!" << endl;
}
}
}