nsnake
Classic snake game for the terminal
Game.hpp
1 #ifndef GAME_H_DEFINED
2 #define GAME_H_DEFINED
3 
4 #include <Game/ScoreFile.hpp>
5 #include <Game/Player.hpp>
6 #include <Game/Board.hpp>
7 #include <Game/FruitManager.hpp>
8 #include <Misc/Timer.hpp>
9 #include <Interface/Menu/Menu.hpp>
10 
11 #include <vector>
12 
13 // Pre-defining it's layout to avoid circular dependency.
14 class LayoutGame;
15 
16 class Game
17 {
18  friend class LayoutGame;
19 
20 public:
21  Game();
22  virtual ~Game();
23 
34  void start(std::string levelName="");
35 
36  void handleInput();
37  void update();
38  void draw();
39 
40  bool isOver();
41 
43  bool willQuit();
44 
46  bool willReturnToMenu();
47 
50  int getDelay(int speed);
51 
52  void pause(bool option);
53 
54  // GameStateGame needs them to be public
55 
60 
67 
68 protected:
69  LayoutGame* layout;
70 
72  bool gameOver;
73 
74  bool userAskedToQuit;
75  bool userAskedToGoToMenu;
76 
80 
84 
85  // Times how long the user have been playing the game.
86  Timer timer;
87 
90  bool isPaused;
91 
95 
98  bool showHelp;
99 
102 
103  Player* player;
104  Board* board;
105  FruitManager* fruits;
106 };
107 
108 #endif //GAME_H_DEFINED
109 
bool showHelp
If it&#39;s showing the help screen.
Definition: Game.hpp:98
bool showPauseMenu
If it&#39;s showing the pause menu.
Definition: Game.hpp:94
Stores points the player made on the game.
Definition: ScoreFile.hpp:87
bool gameOver
If the game is over (board is full of blocks).
Definition: Game.hpp:72
Menu * pauseMenu
Menu that&#39;s shown only when the user presses Pause.
Definition: Game.hpp:101
void start(std::string levelName="")
Starts game, optionally loading a level.
Definition: Game.cpp:39
Controls how many Fruits are there and how they&#39;re spawned.
Timer timerBoard
Timer that tells when to scroll the board, if this game setting is activated.
Definition: Game.hpp:83
A level where the snake runs and eats fruits.
Definition: Board.hpp:32
Definition: Game.hpp:16
bool willReturnToMenu()
If we&#39;ll return to the main menu.
Definition: Game.cpp:323
A single entry on the high-score file.
Definition: ScoreFile.hpp:27
Timer timerSnake
Timer that tells when to move the player, based on the current speed).
Definition: Game.hpp:79
Window * pause
Contains the pause menu.
Definition: LayoutGame.hpp:42
List of selectable items.
Definition: Menu.hpp:28
int getDelay(int speed)
Returns how much time (millisseconds) we need to wait for a specific #speed.
Definition: Game.cpp:327
Definition: Timer.hpp:7
ScoreEntry * currentScore
Current score for this level.
Definition: Game.hpp:66
bool willQuit()
If we&#39;ll quit the game right away.
Definition: Game.cpp:319
bool isPaused
If the game is paused.
Definition: Game.hpp:90
ScoreFile * scores
All the current level&#39;s score.
Definition: Game.hpp:59