**:
#include
#include
#include
using
namespace std;
const
int h=
50,w=
50,maxlen=
400;
void
gotoxy
(short y,
short x)
//游標移動函式
;setconsolecursorposition
(getstdhandle
(std_output_handle)
,pos);}
struct node
;node s[maxlen]
;node food;
int dir,len;
int map[h+5]
[w+5];
int time[7]
=,level;
//building。。。
void
foodcreate()
gotoxy
(food.x,food.y)
,printf
("@");
gotoxy
(h+1,0
);}void
init()
printf
("\n");
} len=2;
//初始化蛇
dir=0;
s[1].x=
12,s[1]
.y=4
; s[len]
.x=12
,s[len]
.y=3
; map[s[1]
.x][s[1]
.y]=map[s[len]
.x][s[len]
.y]=1;
gotoxy
(s[1
].x,s[1]
.y),
printf
("*");
gotoxy
(s[len]
.x,s[len]
.y),
printf
("*");
gotoxy
(h+1,0
);foodcreate()
;}intmove()
if(map[next.x]
[next.y]
)return0;
//下一步gg
if(next.x==food.x&&next.y==food.y)
//下一步遇到食物
else
//下一步是空白就將尾部覆蓋
gotoxy
(next.x,next.y)
,printf
("*");
gotoxy
(h+1,0
); map[next.x]
[next.y]=1
;for
(int i=len;i>
1;i--
)s[i]
=s[i-1]
; s[1]
=next;
sleep
(100);
//sleep放在最後比較順滑//速度在這兒調
return1;
}void
gameover()
gotoxy
(h+1,0
);printf
("gameover\n");
printf
("press any key to continue...");
}void
welcome()
intmain()
if((temp+dir)%2
)dir=temp;
//如果方向不衝突 }if
(move()
==0)}
}
執行效果:
C 結構體陣列實現貪吃蛇
include程式設計客棧c h include include using namespace std const int h 50,w 50,maxlen 400 void gotoxy short y,short x 游標移動函式 setconsolecursorposition getstd...
c 實現貪吃蛇
include include include include include include include include include word square color 7 義方向 define key up 72 define key down 80 define key left 75...
貪吃蛇 c 實現
週末無聊,嘗試寫了下貪吃蛇。先上 include include include include include includeusing namespace std define up 72 define down 80 define left 75 define right 77 struct ...