Engine.hpp (1878B)
1 #ifndef _ENGINE_HPP_ 2 #define _ENGINE_HPP_ 3 4 #include <algorithm> 5 #include <cmath> 6 #include <cstdlib> 7 #include <cstring> 8 #include <ctime> 9 #include <iostream> 10 #include <fstream> 11 #include <map> 12 #include <stdexcept> 13 #include <string> 14 #include <vector> 15 16 #include <ncurses.h> 17 18 #include "Gem.hpp" 19 #include "Gnome.hpp" 20 #include "Potter.hpp" 21 #include "Traal.hpp" 22 #include "Score.hpp" 23 24 #ifndef ESC 25 #define ESC 27 26 #endif /* ESC */ 27 28 #define CENTER(x, y) (((x) >> 1) - ((y) >> 1)) 29 30 #define SYM_WALL '*' 31 #define SYM_PATH ' ' 32 #define SYM_POTTER 'P' 33 #define SYM_GNOME 'G' 34 #define SYM_TRAAL 'T' 35 #define SYM_STONE '+' 36 #define SYM_PARCHMENT 'O' 37 38 class Engine { 39 private: 40 41 std::vector<Movable *> entities; 42 std::vector<Gem *> gems; 43 std::vector<std::string> map; 44 std::vector<std::string> p_ctrls; 45 std::vector<std::string> p_rules; 46 std::vector<std::string> p_win; 47 std::vector<std::string> p_lose; 48 Potter *player; 49 Score *score; 50 Gem *prch; 51 WINDOW *gw; 52 int xmax; 53 int ymax; 54 int wxmax; 55 int wymax; 56 int w; 57 int h; 58 int nenemies = 2; 59 int ngems = 10; 60 int f_running; 61 62 public: 63 explicit Engine(const char *mapfile, const char *scorefile, 64 const char *name); 65 ~Engine(); 66 67 void kbd_input(); 68 void enemies_move(); 69 void collisions(); 70 void redraw() const; 71 bool is_running() const; 72 73 private: 74 void free_entities(); 75 void reset_entities(); 76 void init_curses(); 77 void init_gamewin(); 78 void load_map(const char *mapfile); 79 void calc_pos(int *x, int *y); 80 void init_entities(); 81 void init_popup_msgs(); 82 void spawn_parchment(); 83 bool collides_with_wall(int x, int y) const; 84 int popup(const std::vector<std::string>& lines) const; 85 void calc_dist(std::map<int, int>& dists, int ex, int ey, int dir) const; 86 void upd_score(int n); 87 void round_end(bool is_win); 88 void draw_map() const; 89 void draw_entities() const; 90 void draw_gems() const; 91 void draw_parchment() const; 92 }; 93 94 #endif /* _ENGINE_HPP_ */