-
Notifications
You must be signed in to change notification settings - Fork 1
/
PongGame.h
210 lines (173 loc) · 5 KB
/
PongGame.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***************************************************************************//**
* @file File containing the declaration for the PongGame class.
*
* @brief Contains the declaration for the PongGame class, the class that
* manages all aspects of games
*******************************************************************************/
#ifndef _PONGGAME_H_
#define _PONGGAME_H_
/*******************************************************************************
* DECLARATIONS, INCLUDES, AND NAMESPACES
*******************************************************************************/
class PongGame;
#include <list>
#include <string>
#include "Pong.h"
#include "Board.h"
#include "Paddle.h"
#include "Ball.h"
#include "Steppable.h"
#include "AIController.h"
#include "PlayerController.h"
#include "PaddleController.h"
using namespace std;
/***************************************************************************//**
* @brief The PongGame Class runs the entire game of pong, It is in charge
* of all parts of the game logic.
*
* @details PongGame determines whether the game is paused, restarts the
* game if space is pressed on the end screen. The only thing it
* doesn't do is handle the drawing of the parts and collision detection.
* It does, however, handle most input events and does event handling.
*******************************************************************************/
class PongGame : public Steppable
{
private:
bool game_active; /*!< determins if game is playing */
bool game_paused; /*!< determins if game is paused */
bool left_ai; /*!< determines if left_ai is on */
bool right_ai; /*!< determines if right_ai is on */
int left_score; /*!< Points made for left side */
int right_score; /*!< The score of the right side */
int width; /*!< View width from Pong.h */
int height; /*!< View_hieght from Pong.h */
double ball_speed; /*!< The x velocity of the ball */
int ball_timer; /*!< timer before ball is served */
int hit_count; /*!< amount of times the ball has hit a paddle */
Board* board; /*!< instance of the board class */
Paddle* left_paddle; /*!< instance of paddle on the left side */
Paddle* right_paddle; /*!< right instance of paddle */
Ball* ball; /*!< ball object */
PaddleController* left_controller; /*!< the object that controls the
left paddle*/
PaddleController* right_controller; /*!< the object that controls the
right paddle*/
int left_paddle_size; /*!< height of the left paddle */
int right_paddle_size; /*!< height of the right paddle */
/*!
* @brief Changes ai difficulty
*/
void updateDifficulty();
/*!
* @brief alternates serve
*/
void serve();
/*!
* @brief Deletes instance of classes that PongGame is in charge of
*/
void clear();
/*!
* @brief resets all data
*/
void reset();
public:
/*!
* @brief The constructor, initialize PongGame and gets a width and
* height from the Pong class
*/
PongGame();
/*!
* @brief The destructor, destroys subclasses and itself
*/
~PongGame();
/*!
* @brief Moves various parts of the game
*/
void step();
/*!
* @brief registers that a key was pressed
*/
void keyDownEvent(unsigned char key);
/*!
* @brief registers that a key was released
*/
void keyUpEvent(unsigned char key);
/*!
* @brief registers that an "arrow" key was pressed
*/
void keySpecialDownEvent(int key);
/*!
* @brief registers that an "arrow" key was released
*/
void keySpecialUpEvent(int key);
/*!
* @brief Starts the game with 0, 1, or 2 players
*/
void startGame(bool left_ai, bool right_ai);
/*!
* @brief Ends the game but leaves the board
*/
void quitGame();
/*!
* @brief Pauses the game and all parts of it from moving
*/
void pauseGame();
/*!
* @brief lets everything move again
*/
void resumeGame();
/*!
* @brief Increments the left score and ends game at 10
*/
void scoreLeft();
/*!
* @brief Increaments the right score and ends game at 10
*/
void scoreRight();
/*!
* @brief counts the amount of times the ball has been hit and
* shrinks the paddles accordingly
*/
void ballHit(bool right);
/*!
* @brief resets the ball after a score
*/
void resetBall();
/*!
* @brief quits the game and outputs "Left Side Wins"
*/
void leftWins();
/*!
* @brief quits the game and outputs "Right Side Wins"
*/
void rightWins();
/*!
* @brief acceses the board class
*/
Board* getBoard();
/*!
* @brief accesses the left paddle entity
*/
Paddle* getLeftPaddle();
/*!
* @brief accesses the right paddle entity
*/
Paddle* getRightPaddle();
/*!
* @brief accesses the ball entity
*/
Ball* getBall();
/*!
* @brief determines if the game is paused
*/
bool isPaused();
/*!
* @brief determines if the game is running
*/
bool isRunning();
/*!
* @brief Determins if current game is just a demo. (AI vs AI)
*/
bool isDemo();
};
#endif