游戏规则开始后会介绍,按wsad前进
#include <iostream>
#include <termios.h>
#include <cstring>
#include <iomanip>
#include <list>
#include <unistd.h>
#define clear() cout << "\033c" << flush
using namespace std;
struct node
{
int x, y;
};
int num[15][15];
int x, y;
node head, food;
bool Food = false;
list<node> snake;
char ch = 0;
int score = 0;
static struct termios initial_settings, new_settings;
static int peek_character = -1;
void init_keyboard();
void close_keyboard();
bool kbhit();
char readch();
void changeNum();
void drawBoard();
void move();
int scanKeyboard();
void init_snake();
void fullFood();
bool getFood();
void longer();
bool gameOver();
void intro();
int getch(); // 不回显函数
//主函数
int main()
{
init_snake(); //初始化蛇
init_keyboard(); //初始化键盘
x = 0, y = 0; //初始化移动方向
intro(); //介绍游戏规则
char a = getch();
fullFood(); //填充食物
drawBoard(); //绘制游戏界面
while(ch != 'n') {
usleep(150000);
if(kbhit()) //如果按下按键
{
ch = readch(); //读取按键值
}
int nx = x, ny = y;
if (ch == 'w') nx = -1,ny = 0; //预设移动方向
if (ch == 's') nx = 1, ny = 0;
if (ch == 'a') nx = 0, ny = -1;
if (ch == 'd') nx = 0, ny