nsnake
Classic snake game for the terminal
Player.hpp
1 #ifndef PLAYER_H_DEFINED
2 #define PLAYER_H_DEFINED
3 
4 #include <Interface/Window.hpp>
5 
6 #include <vector>
7 
8 struct Body
9 {
10  int x;
11  int y;
12 
13  Body(int x, int y):
14  x(x),
15  y(y)
16  { }
17 };
18 
19 // Avoiding circular #include hell.
20 class Board;
21 
23 class Player
24 {
25 public:
26  enum Direction
27  {
28  UP, DOWN, LEFT, RIGHT
29  };
30 
31  Player(int x, int y);
32  virtual ~Player() { };
33 
34  bool isAlive();
35  int getSize();
36 
37  int getX();
38  int getY();
39 
40  void moveTo(int x, int y);
41 
42  void move(Direction direction);
43  void kill();
44 
45  void update(Board* board);
46  void draw(Window* win);
47 
48  bool headHit(int x, int y);
49 
56  bool bodyHit(int x, int y, bool isCheckingHead=false);
57 
58  void increase();
59 
60 private:
61  std::vector<Body> body;
62 
63  bool alive;
64 
65  Direction currentDirection;
66  Direction nextDirection;
67 };
68 
69 #endif //PLAYER_H_DEFINED
70 
A segment of the terminal screen (2D char matrix).
Definition: Window.hpp:16
Definition: Player.hpp:8
A level where the snake runs and eats fruits.
Definition: Board.hpp:32