nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Player.hpp
1#ifndef PLAYER_H_DEFINED
2#define PLAYER_H_DEFINED
3
4#include <Interface/Window.hpp>
5
6#include <vector>
7
8struct 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.
20class Board;
21
23class Player
24{
25public:
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
60private:
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 level where the snake runs and eats fruits.
Definition Board.hpp:33
int getX()
Returns the head's x position.
Definition Player.cpp:25
int getY()
Returns the head's y position.
Definition Player.cpp:29
bool bodyHit(int x, int y, bool isCheckingHead=false)
Tells if something at #x and #y collides with any part of the snake.
Definition Player.cpp:146
A segment of the terminal screen (2D char matrix).
Definition Window.hpp:17
Definition Player.hpp:9