-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
119 lines (109 loc) · 3.54 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
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
#include <iostream>
#include <cstdlib>
#include "MapLoader.h"
#include "RenderEngine.h"
#include "ConfigurationManager.h"
#include "Utilities.h"
#include "Image.h"
#include "Command.h"
using namespace std;
ConfigurationManager configuration;
MapLoader mapLoader;
RenderEngine renderEngine;
Utilities utility;
Command command;
int playerX, playerY;
string map;
int pos;
void init(){
configuration = ConfigurationManager("next0.txt");
mapLoader = configuration.GetMapLoader();
renderEngine = configuration.GetRenderEngine();
system("mode 650");
utility = Utilities();
playerX = 5;
playerY = 7;
}
bool playerCanMove(char direction, char block){
switch(block){
case '/': return TRUE;
break;
case '^': return TRUE;
break;
case '\\': return TRUE;
break;
case '_': return TRUE;
break;
case '=': return TRUE;
break;
default:
return FALSE;
}
}
int main()
{
init();
map = mapLoader.FileMapper();
int x = mapLoader.GetX();
int y = mapLoader.GetY();
char** mapArr = mapLoader.GetMap(map, x, y);
char** safetyCopy = mapLoader.GetMap(map, x, y);
ostringstream os;
Image title = Image("title.txt");
renderEngine.Render(title);
getch();
system("cls");
mapArr[playerX][playerY] = '0';
renderEngine.DrawMap(mapArr, x, y);
while(true){
mapArr[playerX][playerY] = safetyCopy[playerX][playerY];
switch(getch()){
case 'w': if(playerCanMove('w', safetyCopy[playerX][playerY-1])){playerY--;}
break;
case 's': if(playerCanMove('s', safetyCopy[playerX][playerY+1])){playerY++;}
break;
case 'a': if(playerCanMove('a', safetyCopy[playerX-1][playerY])){playerX--;}
break;
case 'd': if(playerCanMove('d', safetyCopy[playerX+1][playerY])){playerX++;}
break;
case '0': return EXIT_SUCCESS;
break;
default:
break;
}
switch(command.Interact(safetyCopy[playerX][playerY])){
case 'a': pos++;
os.str("");
os << "next" << pos << ".txt";
mapLoader.SetPath(os.str());
renderEngine.SetEnvironment("fields");
map = mapLoader.FileMapper();
x = mapLoader.GetX();
y = mapLoader.GetY();
playerX = 20;
playerY = 2;
mapArr = mapLoader.GetMap(map, x, y);
safetyCopy = mapLoader.GetMap(map, x, y);
break;
case 'p': pos--;
os.str("");
os << "next" << pos << ".txt";
mapLoader.SetPath(os.str());
renderEngine.SetEnvironment("house");
map = mapLoader.FileMapper();
x = mapLoader.GetX();
y = mapLoader.GetY();
playerX = 8;
playerY = 12;
mapArr = mapLoader.GetMap(map, x, y);
safetyCopy = mapLoader.GetMap(map, x, y);
break;
case 'n':
break;
}
system("cls");
mapArr[playerX][playerY] = '0';
renderEngine.DrawMap(mapArr, x, y);
}
return EXIT_SUCCESS;
}