-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWindow.hpp
executable file
·73 lines (67 loc) · 1.48 KB
/
GameWindow.hpp
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
#ifndef GAMEWINDOW_HPP___
#define GAMEWINDOW_HPP___
#ifdef _WIN32
#include <SDL.h>
#endif
#ifdef _WIN64
#include <SDL.h>
#endif
#ifdef __unix__
#include <SDL2/SDL.h>
#endif
#include <iostream>
#include <thread>
#include <chrono>
#include <memory>
#include <random>
#include "Error.hpp"
#include "Racket.hpp"
#include "Ball.hpp"
#include "Scoreboard.hpp"
#include "Text.hpp"
#include "Menu.hpp"
class Ball;
class Racket;
class Scoreboard;
class Text;
class Menu;
class GameWindow
{
public:
friend class Ball;
friend class Racket;
friend class Scoreboard;
friend class Text;
friend class Menu;
private:
const int MAX_SCORE;
int speed;
SDL_Window* window;
SDL_Renderer* renderer;
int width, height, margin;
bool game_running;
SDL_Event event;
std::unique_ptr<Racket> racket1, racket2;
std::unique_ptr<Ball> ball;
std::unique_ptr<Scoreboard> scoreboard;
std::unique_ptr<Menu> menu;
public:
GameWindow(const int& window_width, const int& window_height, const int& max_score);
~GameWindow();
GameWindow(const GameWindow&) = delete;
GameWindow(GameWindow&&) = delete;
GameWindow& operator=(const GameWindow&) = delete;
GameWindow& operator=(GameWindow&&) = delete;
void play();
private:
void init();
void render_background() const;
void render_objects();
void event_handler();
void delay(const int& ms) const;
void display_menu();
void pause_handler();
void detect_game_end();
void game_end_handler();
};
#endif