nsnake
Classic snake game for the terminal
Board.hpp
1 #ifndef BOARD_H_DEFINED
2 #define BOARD_H_DEFINED
3 
4 #include <Misc/Array2D.hpp>
5 #include <Interface/Window.hpp>
6 
7 #include <map>
8 
9 // Avoiding circular #include hell.
10 class Player;
11 
12 // Default starting point for
13 // the player on every level
14 #define BOARD_DEFAULT_PLAYER_X 2
15 #define BOARD_DEFAULT_PLAYER_Y 2
16 
32 class Board
33 {
34 public:
35  static int small_width;
36  static int small_height;
37 
38  static int medium_width;
39  static int medium_height;
40 
41  static int large_width;
42  static int large_height;
43 
46  enum Style { SOLID, TELEPORT };
47 
54  Board(int width, int height, Style style);
55 
56  virtual ~Board();
57 
59  bool isWall(int x, int y);
60  bool isBorder(int x, int y);
61 
62  int getW();
63  int getH();
64 
65  void draw(Window* win);
66 
70  void randomlyFillExceptBy(int x, int y);
71 
73  void teleport(Player* player);
74 
76  void clear();
77 
83  void setBoard(std::vector<std::vector<bool> >& newBoard);
84 
91 
92  int getStartX();
93  int getStartY();
94 
95  void setStartX(int x);
96  void setStartY(int y);
97 
98  // Things related to metadata
99  // (author name, date made, comments, and more)
100 
102  void setMetadata(std::string name, std::string value);
103 
108  std::string getMetadata(std::string name);
109 
111  bool hasMetadata(std::string name);
112 
113  void scrollLeft();
114  void scrollRight();
115  void scrollUp();
116  void scrollDown();
117 
118 private:
122  Array2D<bool>* board;
123 
124  int start_x;
125  int start_y;
126 
128  std::map<std::string, std::string> metadata;
129 };
130 
131 #endif //BOARD_H_DEFINED
132 
void randomlyFillExceptBy(int x, int y)
Places random walls all over the Board except by #x and #y, allowing the Player to move a little bit ...
Definition: Board.cpp:83
bool hasMetadata(std::string name)
Tells if this level has a specific information attached.
Definition: Board.cpp:176
A segment of the terminal screen (2D char matrix).
Definition: Window.hpp:16
std::string getMetadata(std::string name)
Gets a meta information from this level.
Definition: Board.cpp:169
Style
If the player will teleport when reaching the Board&#39;s limits or not.
Definition: Board.hpp:46
Style style
Tells if the player will teleport when reaching the Board&#39;s limits or not.
Definition: Board.hpp:90
Board(int width, int height, Style style)
Creates a new Board.
Definition: Board.cpp:15
A level where the snake runs and eats fruits.
Definition: Board.hpp:32
void setMetadata(std::string name, std::string value)
Sets a meta information from this level.
Definition: Board.cpp:165
bool isWall(int x, int y)
Tells if there&#39;s a wall at #x #y.
Definition: Board.cpp:36
void setBoard(std::vector< std::vector< bool > > &newBoard)
Sets the whole level content.
Definition: Board.cpp:139
void teleport(Player *player)
Makes the Player teleport if it&#39;s on a border.
Definition: Board.cpp:98
void clear()
Makes the whole level empty.
Definition: Board.cpp:132