开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
Mac OS (g++)
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
ncurses.h
问题(Question):
目前写的贪食蛇练习题,可以分别让蛇自动前进及按上下左右键盘前进
但尝试想把两个功能合并,却疑似发生阻断,已经爬文过但还不知道怎么解
在下面的程式码有highlight,求解
喂入的资料(Input):
预期的正确结果(Expected Output):
错误结果(Wrong Output):
程式码(Code):(请善用置底文网页, 记得排版)
#include <iostream>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
using namespace std;
//int move(int y , int x);
#define Initial_Length 5
#define width 50
#define hieght 20
typedef struct snack{
int x;
int y;
}Snack;
Snack Sbody[1000];
Snack Newbody;
Snack Food;
void Show_Bulletinboard()
{
mvaddstr(2,55,"Press Enter or Space to start.");
mvaddstr(6,55,"Press P or p to pause.");
mvaddstr(10,55,"Press to arrow key to move.");
//加一个状态字段
//mvaddch(10,55,'\x18\x19\x1a\x1b');
mvaddstr(14,55,"Grade:");
mvaddstr(18,55,"Speed:");
}
void Initial_Snack_Position()
{
for (int i = 0; i < Initial_Length ; i++)
{
Sbody[i].y = 2;
Sbody[i].x = Initial_Length + 1 - (i);
}
}
void Print_Snack(int *Length)
{
for (int i = 0; i < *Length ; i++)
{
if (i == 0)
{
//改变头的颜色
mvaddstr(Sbody[i].y, Sbody[i].x , "@");
//printf("\033[33m@");
}
else
{
mvaddstr(Sbody[i].y, Sbody[i].x , "@");
}
}
}
void Print_Dot(int Pos_y, int Pos_x, char ch )
{
mvaddch(Pos_y, Pos_x , ch);
//printf("\033[33m@");
}
void Initial_GameZone()
{
for (int j = 1 ; j <= hieght ; j++)
{
for (int i = 1; i <= width ; i++)
{
if (j == 1 || j == hieght)
{
Print_Dot(j,i,'#');
}
else if(i == 1 || i == width)
{
Print_Dot(j,i,'#');
}
}
}
}
void Change_Snack_Position(int * Length)
{
for(int i = *Length -1 ; i >= 0 ; i