-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
77 lines (63 loc) · 2.06 KB
/
GameManager.cpp
File metadata and controls
77 lines (63 loc) · 2.06 KB
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
//
// Created by c on 6/19/24.
//
#include "GameManager.h"
#include "SnakeModel.h"
#include "Board.h"
#include "View.h"
#include "Controller.h"
GameManager::GameManager(sf::RenderWindow &windowRef) :window(windowRef){}
void GameManager::play_recordsScreen(sf::Event &event, bool &reset, RecordsScreen &recordsScreen) const{
while(window.isOpen() and !reset){
while(window.pollEvent(event)) {
if(event.type==sf::Event::Closed) window.close();
recordsScreen.controllRecordScreen(event, reset);
}
window.clear();
recordsScreen.drawRecordsScreen();
window.display();
}
}
void GameManager::play_gamingScreen(sf::Event &event, bool &reset,const Menu &menu) const{
SnakeModel snake(menu.getGameMode());
Board board(snake,28,28);
View view(snake,board);
Controller controller(snake, board);
sf::Clock clock;
float elapseTime=0.0f;
while(window.isOpen() and !reset) {
while(window.pollEvent(event)) {
if(event.type==sf::Event::Closed) window.close();
}
float deltaTime=clock.restart().asSeconds();
elapseTime+=deltaTime;
controller.play(event,elapseTime);
window.clear();
view.draw(window);
window.display();
if(board.updateGameState()!=RUNNING) {
sleep(sf::seconds(1.0f));
RecordsScreen recordsScreen(window, menu.getGameMode(), snake.getEatenFood());
play_recordsScreen(event, reset, recordsScreen);
}
}
}
void GameManager::play() const {
while(window.isOpen()) {
Menu menu(window);
bool reset=false;
while(window.isOpen() and !reset) {
sf::Event event;
while(window.pollEvent(event)) {
if(event.type==sf::Event::Closed) window.close();
menu.controllMenu(event);
}
window.clear();
menu.drawMenu();
window.display();
if(menu.isChosen()) {
play_gamingScreen(event, reset, menu);
}
}
}
}