-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
63 lines (52 loc) · 1.51 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
#include <iostream>
#include "window.hpp"
#include "model.hpp"
#include "gameview.hpp"
#include "menuview.hpp"
#include "endview.hpp"
using namespace std;
using namespace stf;
class Game : public Window
{
GameModel model = GameModel(renderer.Size);
PausedGameView paused = PausedGameView(&model);
MenuView menu = MenuView(&model, renderer.Size);
GameView game = GameView(&model);
EndView end = EndView(&model);
stf::smv::BaseView *current = &menu;
bool gameIsContinue = true;
public:
Game() : Window() {}
bool onUpdate(const float dt) override
{
current->update(dt);
current->show(renderer);
return gameIsContinue;
}
stf::smv::BaseView* viewSwitcher(stf::smv::ModelBaseState state)
{
switch (state) {
case stf::smv::ModelBaseState::start: return &game;
case stf::smv::ModelBaseState::end: return &end;
case stf::smv::ModelBaseState::menu: return &menu;
case stf::smv::ModelBaseState::pause: return &paused;
case stf::smv::ModelBaseState::none: return current;
case stf::smv::ModelBaseState::exit:
gameIsContinue = false;
return current;
}
}
void keyEvents(const int key) override
{
current = viewSwitcher(current->keyEventsHandler(key));
}
void mouseEvents(const MouseRecord &mr) override
{
current = viewSwitcher(current->mouseEventsHandler(mr));
}
};
int main()
{
Game snake;
return snake.run();
}