-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
121 lines (108 loc) · 3.57 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
120
121
#include <iostream>
#include "state.h"
using namespace std;
int main() {
int x, y; // x = width of map, y = length/height of map
int timer = 0; // Used for daytime
string team;
// Select dimensions of map
cout << "Welcome to Werewolves vs Vampires!" << endl;
cout << "Suggested width [20,140] and length [15,35]" << endl;
cout << "Please type the width of the map: ";
do{
cin >> x;
} while (x < 20 || x > 140);
cout << "Please type the height of the map: ";
do {
cin >> y;
} while (y < 15 || y > 35);
cout << endl;
// Create map of the game
Map* ptr = new Map(y , x, false);
// Create state of the game
State state = state_create(ptr);
// Select team Werewolves or Vampires
cout << "Please select team. Type 'W' or 'w' for Werewolves, 'V' or 'v' for Vampires: ";
do {
cin >> team;
if (team != "W" && team != "w" && team != "V" && team != "v") {
cout << "Wrong team input. Try again: ";
}
else if (team == "W" || team == "w") {
state->info.Team_W = true;
}
else if (team == "V" || team == "v") {
state->info.Team_W = false;
}
} while (team != "W" && team != "w" && team != "V" && team != "v");
cout << endl;
// Printing results for test debugging
cout << "Map is: " << ptr->get_length() << "x" << ptr->get_width() << endl;
if (state->info.Team_W) {
cout << "Team: Werewolves\n";
}
else {
cout << "Team: Vampires\n";
}
system("cls");
// Game proceeds
while (state->info.playing) { // If game has started
if (state->info.paused == false) { // If game is not paused
board(x, y, state); // Print board, creatures and objects
Sleep(500); // After delay of 500 milliseconds
state_update(state); // Update game state
timer++;
if (timer == 20) { // After 20 updates, change time
if (state->map->get_time()) {
state->map->set_time(false);
}
else {
state->map->set_time(true);
}
timer = 0;
}
}
if (!_kbhit() && state->info.paused == false) { // If there is not any key pressed and game is not paused
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), { 0, 0 }); // Cursor goes at (0,0)
continue;
}
else if (_kbhit()) { // If any key is pressed
switch (_getch()) { // Get key pressed
case 'w': state->At.at(0)->movement(state, 'w'); break;
case 'd': state->At.at(0)->movement(state, 'd'); break;
case 's': state->At.at(0)->movement(state, 's'); break;
case 'a': state->At.at(0)->movement(state, 'a'); break;
case 'q': // If q is pressed
state->info.playing = false; // Game ends
system("cls"); // Clear screen
break;
case 'p': // If p is pressed, change the pause condition
if (state->info.paused == false) {
state->info.paused = true;
system("cls");
menu(state); // Print menu
}
else { // If p pressed and already in menu
state->info.paused = false;
system("cls"); // Clear screen
}
break;
case 'h': state->At.at(0)->help_team(state); break;
}
}
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), { 0, 0 }); // Cursor goes at (0,0)
}
system("cls"); // Clear screen
if (state->info.number_W == 0) { // If all werewolves died
cout << "VAMPIRES WON!" << endl;
}
else if (state->info.number_V == 0) { // If all vampires died
cout << "WEREWOLVES WON!" << endl;
}
else { // If game ended for any other reason, for example player quit
cout << "YOU QUIT :(" << endl;
}
//Deallocation of remaining objects
deallocation(state);
return 0;
}