贪吃蛇,C++
好久之前写的,登陆博客看了下好久没更新了,就随手发出来吧。
用这份代码,QT套了个界面设置速度和地图大小。QT的代码就不发了hhh,毕竟源代码分好几个文件 懒
。
用了Windows.h 所以只能在Windows下运行。
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MAXC=100,MAXR=100;
typedef pair pii;
class Game{
public:
int mat[MAXC][MAXR];
int dx[5],dy[5];
deque q;
int d,col,row;
bool food;
HANDLE hOut;
void pt(int x, int y,char c){
COORD pos;
pos.X=x*3+2;
pos.Y=y*2+1;
SetConsoleCursorPosition(hOut, pos);
putchar(c);
}
int dir(){
char c1,c2;
if(!_kbhit())
return 4;
c1=getch(),c2=getch();
switch(c2){
case 72:return 1;//up
case 75:return 0;//left
case 77:return 3;//right
case 80:return 2;//down
}
}
void topblock(){
printf("┌");
for(int i=0;i=0&&ny>=0&&nx=0&&ny>=0&&nx|