snake.h

来自「这是基于QT编写的一个linux下的贪吃蛇游戏。」· C头文件 代码 · 共 51 行

H
51
字号
#include <iostream> 
#include <string> 
#include <vector> 

using std::string; 
using std::cin; 
using std::cout; 
using std::endl; 
using std::vector; 

class Pos { 
public: 
int x; 
int y; 
}; 

class Body { 
public: 
Pos pos; 
Body *next; 
Body *prev; 
}; 

class Foods { 
vector<Pos> food; 
public: 
void init( int num, int x_max, int x_min, int y_max, int y_min ); 
int getX( int index ); 
int getY( int index ); 
}; 


class Snake { 
private: 
Body *head; 
Body *tail; 
string direction; 
string directionOld; 
public: 
Snake(); 
~Snake(); 
void move(); 
void turn( string direction ); 
void grow(); 
Body* getSnakeTail(); 
Body* getSnakeHead(); 
void display(); 
bool biteSelf(); 
int length(); 
}; 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?