You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
666 B

#ifndef SNAKE_H
#define SNAKE_H
#include <deque>
#include "point.h"
#include "food.h"
class Food;
class Snake
{
public:
enum Direction {UP, DOWN, LEFT, RIGHT};
Snake() {
snake.emplace_back(14, 8);
snake.emplace_back(15, 8);
snake.emplace_back(16, 8);
direction = Direction::DOWN;
}
void InitSnake();
void Move();
void NormalMove();
bool OverEdge();
bool HitItself();
bool ChangeDirection();
bool GetFood(const Food&);
bool GetBigFood(Food&);
private:
std::deque<Point> snake;
Direction direction;
friend class Food;//将Food类置为友元,以便访问其私有元素
};
#endif // SNAKE_H