Tower Defence 2
engine.h
1 #ifndef TOWER_DEFENCE_2_GAME_H
2 #define TOWER_DEFENCE_2_GAME_H
3 
4 
5 #include <vector>
6 #include "objects/enemy.h"
7 #include "objects/tower.h"
8 #include "map/tile.h"
9 #include "map/map.h"
10 #include "level.h"
11 
12 
13 // Deferred declaration
14 class graphicsEngine;
15 
16 
18 enum GameState {
20  level_unfinished,
21 
23  level_completed,
24 
26  game_over,
27 };
28 
29 
32 enum GameSpeed {
33  normal,
34  fast
35 };
36 
37 
41 class GameEngine {
42 public:
43  GameEngine(double time, double timestep, int score,
44  GameLevel &game_level, GameMap &game_map);
45 
46  ~GameEngine();
47 
48  double time() const;
49  const double timestep() const;
50  int score() const;
51  int money() const;
52  int lives() const;
53 
55  void change_game_speed(GameSpeed new_speed);
56 
58  void increment_time();
59 
61  void add_score(int amount);
62 
67  bool add_money(int amount);
68 
71  void reduce_life();
72 
74  void upgrade_tower(int x, int y, int index);
75 
77  void change_targeting(TargetingPolicy new_policy);
78 
80  void add_enemy(Enemy *enemy);
81 
84  void advance_game_level();
85 
91  void enemy_movement();
92 
96  Enemy* find_targets(Tower *tower, Enemies &enemies);
97 
100  void towers_attack(graphicsEngine& gE);
101 
104  GameState update(graphicsEngine& gE);
105 
107  GameMap game_map();
108 
109  friend bool update_high_score(const std::string &filename, GameEngine engine);
110 
111 private:
112  GameSpeed m_speed;
113  double m_time;
114  double m_timestep;
115  int m_score;
116  int m_money;
117  int m_lives;
118  GameLevel m_game_level;
119  GameMap m_game_map;
120 };
121 
128 std::vector<int> high_score(const std::string &filename);
129 
134 bool update_high_score(const std::string &filename, GameEngine engine);
135 
136 #include "Graphics/graphicsEngine.h"
137 
138 
139 #endif //TOWER_DEFENCE_2_GAME_H
void upgrade_tower(int x, int y, int index)
Upgrade existing tower into new one.
Definition: engine.cpp:80
GameMap game_map()
Getter for game map.
Definition: engine.cpp:41
void enemy_movement()
Definition: engine.cpp:122
Enemy class.
Definition: enemy.h:12
Definition: engine.h:41
void change_targeting(TargetingPolicy new_policy)
Change targeting policy of all towers.
Definition: engine.cpp:90
void add_enemy(Enemy *enemy)
Add new enemy to game map.
Definition: engine.cpp:102
Tower class.
Definition: tower.h:13
void change_game_speed(GameSpeed new_speed)
Change the game speed to fast or normal.
Definition: engine.cpp:53
GameState update(graphicsEngine &gE)
Definition: engine.cpp:236
void reduce_life()
Definition: engine.cpp:76
void advance_game_level()
Definition: engine.cpp:106
friend bool update_high_score(const std::string &filename, GameEngine engine)
Definition: engine.cpp:275
void towers_attack(graphicsEngine &gE)
Definition: engine.cpp:206
bool add_money(int amount)
Definition: engine.cpp:66
Definition: level.h:15
Enemy * find_targets(Tower *tower, Enemies &enemies)
Definition: engine.cpp:144
void increment_time()
Increments the game time by one timestep.
Definition: engine.cpp:232
void add_score(int amount)
Change player&#39;s score. Game score can&#39;t go below zero.
Definition: engine.cpp:45