-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.h
74 lines (65 loc) · 1.68 KB
/
game.h
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
#pragma oncev
#include "Clock.h"
#include <Windows.h>
#include "single.h"
#include "sprite.h"
#include "map.h"
#include "block.h"
#include <tchar.h>
#define NOMINMAX
class Game{
public:
enum class GameState { Menu, SinglePlayerGame, TwoPlayerGame, EXIT };
void runGame(){
while (state != GameState::EXIT){
switch (state){
case GameState::Menu:
menu(); break;
case GameState::SinglePlayerGame:
game(0); break;
case GameState::TwoPlayerGame:
game(1); break;
}
}
}
private:
sf::RenderWindow wndow;
GameState icon; // needed to determine the position of the tank in the menu
GameState state; // current manu status of the game (menu, single, multi etc)
Sprite spr; // class that stores textures
Map map; // class displaying the map
sf::Font font; // needed font
Timer FPSclock;
// functions related to the menu
void menu();
void game(bool x){
if (x == 0){
Single single{ x, font, map, spr, wndow, FPSclock };
single.runSingle();
state = GameState::Menu;
}
else{
Single single{ x, font, map, spr, wndow, FPSclock };
single.runSingle();
state = GameState::Menu;
}
}
void eventsMenu();
public:
Game(void) : map{ spr, FPSclock, wndow }, FPSclock{ font }{
std::srand(unsigned(std::time(nullptr)));
wndow.create(sf::VideoMode(1920, 1080), "Battle City", sf::Style::Fullscreen);
wndow.setFramerateLimit(60);
map.setProperties(wndow);
state = GameState::EXIT;
if (!spr.isGood()){
MessageBox(NULL, _T("Some image not found!"), _T("ERROR"), NULL);
return;
}
if (!font.loadFromFile("data/joystix monospace.ttf")){
MessageBox(NULL, _T("Font not found!"), _T("ERROR"), NULL);
return;
}
state = GameState::Menu;
}
};