Snoke
snake.h
Go to the documentation of this file.
1 
11 #ifndef SNAKE_H
12 #define SNAKE_H
13 #include <list>
14 #include <deque>
15 #include "../Common/common.h"
16 #include "../Labyrinth/labyrinth.h"
17 #include "../Labyrinth/change.h"
18 #include "../Ball/ball.h"
19 
23 const int WALLUP = -3;
27 const int WALLBOT = +3;
31 const int WALLLEFT = -4;
35 const int WALLRIGHT = +4;
39 const int COLL = 5;
43 const int NOCOLL = 6;
47 const int BALL = 7;
48 
52 const int MVRIGHT = +1;
56 const int MVDOWN = +2;
60 const int MVLEFT = -1;
64 const int MVUP = -2;
65 
70 extern Point gameFieldSize;
71 
79 class Snake
80 {
81  private:
82  short direction;
83  std::list<PointStyle> style;
84  std::deque<Point> snakeBody;
85  short checkIntersection(Point check, Labyrinth* laryrinth);
86  short checkWisely(Point coords, Point bcoords);
87  void moveHead(Point p, Change* change);
88  void moveBack(Point p, Change* change);
89  public:
90  bool init(Point begin, short direction, int length);
91  void setScheme();
92  void getCoords(std::list<Point>* currBody);
94  bool setDirection(int dir);
95  short getDirection();
96  bool move(Labyrinth* labyrinth);
97 };
98 #endif //SNAKE_H
short checkIntersection(Point check, Labyrinth *laryrinth)
Checking the given point for intersections with Ball, borders, obstacles.
Definition: snake.cpp:248
class for containing and displaying the game field
Definition: labyrinth.h:66
std::deque< Point > snakeBody
Definition: snake.h:84
bool move(Labyrinth *labyrinth)
The snake movement on the game field(should be called in each iteration of the game cycle...
Definition: snake.cpp:80
const int NOCOLL
the tested segment is NOT intersecting with any Point of the game labyrinth
Definition: snake.h:43
short checkWisely(Point coords, Point bcoords)
If the Point of the labyrinth we are checking is not free then decide the type of collision...
Definition: snake.cpp:264
Point gameFieldSize
Definition: game.cpp:17
void moveHead(Point p, Change *change)
Moving snake head to a described by parameters position and updating the addition to the labyrinth...
Definition: snake.cpp:222
void getCoords(std::list< Point > *currBody)
The method to get the snake whole body coordinates(x ,y) without giving the direct access...
Definition: snake.cpp:331
const int BALL
the tested segment is intersecting with the Ball
Definition: snake.h:47
short getDirection()
The method to get the current direction without giving the direct access.
Definition: snake.cpp:313
void setScheme()
std::list< PointStyle > style
Definition: snake.h:83
A Support Change class.
Definition: change.h:21
bool setDirection(int dir)
The method to set the direction where the snake is heading.
Definition: snake.cpp:294
const int WALLLEFT
the tested segment is intersecting with the left boundary of the game field
Definition: snake.h:31
const int WALLUP
the tested segment is intersecting with the upper boundary of the game field
Definition: snake.h:23
bool init(Point begin, short direction, int length)
Initializes snake as an entity without ancoring it anywhere.
Definition: snake.cpp:20
const int WALLBOT
the tested segment is intersecting with the bottom boundary of the game field
Definition: snake.h:27
const int MVLEFT
snake&#39;s head is moving left
Definition: snake.h:60
const int COLL
the tested segment is intersecting with a non-boundary Point of the game field
Definition: snake.h:39
void moveBack(Point p, Change *change)
Checking if we need to remove the back of the snake from the labyrinth(we don&#39;t in case it has eaten ...
Definition: snake.cpp:233
Point getHeadCoords()
The method to get the coordinates(x, y) of the snake&#39;s head without giving the direct access...
Definition: snake.cpp:321
const int MVUP
snake&#39;s head is moving up
Definition: snake.h:64
Describes the Snake entity of the game.
Definition: snake.h:79
short direction
Definition: snake.h:82
const int MVRIGHT
snake&#39;s head is moving right
Definition: snake.h:52
const int WALLRIGHT
the tested segment is intersecting with the right boundary of the game field
Definition: snake.h:35
Coordinates and style of the cell in console window.
Definition: common.h:52
const int MVDOWN
snake&#39;s head is moving down
Definition: snake.h:56