nsnake
Classic snake game for the terminal
src
Game
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
Body
Definition:
Player.hpp:9
Window
A segment of the terminal screen (2D char matrix).
Definition:
Window.hpp:17
Player::bodyHit
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
Board
A level where the snake runs and eats fruits.
Definition:
Board.hpp:33
Player::getX
int getX()
Returns the head's x position.
Definition:
Player.cpp:25
Player
Definition:
Player.hpp:24
Player::getY
int getY()
Returns the head's y position.
Definition:
Player.cpp:29
Generated on Tue Jul 28 2020 00:00:00 for nsnake by
1.8.18