求贪吃蛇C语言代码,有一定功能要求 求一个贪吃蛇C语言源代码
\u6c42\uff0c\u8d2a\u5403\u86c7 C\u8bed\u8a00\u4ee3\u7801 \u53ca\u5176\u6bcf\u4e00\u6b65\u7684\u8bb2\u89e3/* \u8d2a\u5403\u86c7\u7a0b\u5e8f by champking */
#define N 200
#include
#include
#include
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score = 0;/*\u5f97\u5206*/
int gamespeed = 100000;/*\u6e38\u620f\u901f\u5ea6\u81ea\u5df1\u8c03\u6574*/
struct Food
{
int x;/*\u98df\u7269\u7684\u6a2a\u5750\u6807*/
int y;/*\u98df\u7269\u7684\u7eb5\u5750\u6807*/
int yes;/*\u5224\u65ad\u662f\u5426\u8981\u51fa\u73b0\u98df\u7269\u7684\u53d8\u91cf*/
}food;/*\u98df\u7269\u7684\u7ed3\u6784\u4f53*/
struct Snake
{
int x[N];
int y[N];
int node;/*\u86c7\u7684\u8282\u6570*/
int direction;/*\u86c7\u79fb\u52a8\u65b9\u5411*/
int life;/* \u86c7\u7684\u751f\u547d,0\u6d3b\u7740,1\u6b7b\u4ea1*/
}snake;
void Init(void);/*\u56fe\u5f62\u9a71\u52a8*/
void Close(void);/*\u56fe\u5f62\u7ed3\u675f*/
void DrawK(void);/*\u5f00\u59cb\u753b\u9762*/
void GameOver(void);/*\u7ed3\u675f\u6e38\u620f*/
void GamePlay(void);/*\u73a9\u6e38\u620f\u5177\u4f53\u8fc7\u7a0b*/
void PrScore(void);/*\u8f93\u51fa\u6210\u7ee9*/
/*\u4e3b\u51fd\u6570*/
void main(void)
{
Init();/*\u56fe\u5f62\u9a71\u52a8*/
DrawK();/*\u5f00\u59cb\u753b\u9762*/
GamePlay();/*\u73a9\u6e38\u620f\u5177\u4f53\u8fc7\u7a0b*/
Close();/*\u56fe\u5f62\u7ed3\u675f*/
}
/*\u56fe\u5f62\u9a71\u52a8*/
void Init(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc");
cleardevice();
}
/*\u5f00\u59cb\u753b\u9762,\u5de6\u4e0a\u89d2\u5750\u6807\u4e3a(50,40),\u53f3\u4e0b\u89d2\u5750\u6807\u4e3a(610,460)\u7684\u56f4\u5899*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);/*\u8bbe\u7f6e\u7ebf\u578b*/
for(i = 50; i <= 600; i += 10)/*\u753b\u56f4\u5899*/
{
rectangle(i, 40, i + 10, 49); /*\u4e0a\u8fb9*/
rectangle(i, 451, i + 10, 460);/*\u4e0b\u8fb9*/
}
for(i = 40; i <= 450; i += 10)
{
rectangle(50, i, 59, i + 10); /*\u5de6\u8fb9*/
rectangle(601, i, 610, i + 10);/*\u53f3\u8fb9*/
}
}
/*\u73a9\u6e38\u620f\u5177\u4f53\u8fc7\u7a0b*/
void GamePlay(void)
{
randomize();/*\u968f\u673a\u6570\u53d1\u751f\u5668*/
food.yes = 1;/*1\u8868\u793a\u9700\u8981\u51fa\u73b0\u65b0\u98df\u7269,0\u8868\u793a\u5df2\u7ecf\u5b58\u5728\u98df\u7269*/
snake.life = 0;/*\u6d3b\u7740*/
snake.direction = 1;/*\u65b9\u5411\u5f80\u53f3*/
snake.x[0] = 100; snake.y[0] = 100;/*\u86c7\u5934*/
snake.x[1] = 110; snake.y[1] = 100;
snake.node = 2;/*\u8282\u6570*/
PrScore();/*\u8f93\u51fa\u5f97\u5206*/
while(1)/*\u53ef\u4ee5\u91cd\u590d\u73a9\u6e38\u620f,\u538bESC\u952e\u7ed3\u675f*/
{
while(!kbhit())/*\u5728\u6ca1\u6709\u6309\u952e\u7684\u60c5\u51b5\u4e0b,\u86c7\u81ea\u5df1\u79fb\u52a8\u8eab\u4f53*/
{
if(food.yes == 1)/*\u9700\u8981\u51fa\u73b0\u65b0\u98df\u7269*/
{
food.x = rand() % 400 + 60;
food.y = rand() % 350 + 60;
while(food.x % 10 != 0)/*\u98df\u7269\u968f\u673a\u51fa\u73b0\u540e\u5fc5\u987b\u8ba9\u98df\u7269\u80fd\u591f\u5728\u6574\u683c\u5185,\u8fd9\u6837\u624d\u53ef\u4ee5\u8ba9\u86c7\u5403\u5230*/
food.x++;
while(food.y % 10 != 0)
food.y++;
food.yes = 0;/*\u753b\u9762\u4e0a\u6709\u98df\u7269\u4e86*/
}
if(food.yes == 0)/*\u753b\u9762\u4e0a\u6709\u98df\u7269\u4e86\u5c31\u8981\u663e\u793a*/
{
setcolor(GREEN);
rectangle(food.x, food.y, food.x + 10, food.y - 10);
}
for(i = snake.node - 1; i > 0; i--)/*\u86c7\u7684\u6bcf\u4e2a\u73af\u8282\u5f80\u524d\u79fb\u52a8,\u4e5f\u5c31\u662f\u8d2a\u5403\u86c7\u7684\u5173\u952e\u7b97\u6cd5*/
{
snake.x[i] = snake.x[i-1];
snake.y[i] = snake.y[i-1];
}
/*1,2,3,4\u8868\u793a\u53f3,\u5de6,\u4e0a,\u4e0b\u56db\u4e2a\u65b9\u5411,\u901a\u8fc7\u8fd9\u4e2a\u5224\u65ad\u6765\u79fb\u52a8\u86c7\u5934*/
switch(snake.direction)
{
case 1: snake.x[0] += 10; break;
case 2: snake.x[0] -= 10; break;
case 3: snake.y[0] -= 10; break;
case 4: snake.y[0] += 10; break;
}
for(i = 3; i < snake.node; i++)/*\u4ece\u86c7\u7684\u7b2c\u56db\u8282\u5f00\u59cb\u5224\u65ad\u662f\u5426\u649e\u5230\u81ea\u5df1\u4e86,\u56e0\u4e3a\u86c7\u5934\u4e3a\u4e24\u8282,\u7b2c\u4e09\u8282\u4e0d\u53ef\u80fd\u62d0\u8fc7\u6765*/
{
if(snake.x[i] == snake.x[0] && snake.y[i] == snake.y[0])
{
GameOver();/*\u663e\u793a\u5931\u8d25*/
snake.life = 1;
break;
}
}
if(snake.x[0]595||snake.y[0]<55||
snake.y[0]>455)/*\u86c7\u662f\u5426\u649e\u5230\u5899\u58c1*/
{
GameOver();/*\u672c\u6b21\u6e38\u620f\u7ed3\u675f*/
snake.life=1; /*\u86c7\u6b7b*/
}
if(snake.life == 1)/*\u4ee5\u4e0a\u4e24\u79cd\u5224\u65ad\u4ee5\u540e,\u5982\u679c\u86c7\u6b7b\u5c31\u8df3\u51fa\u5185\u5faa\u73af,\u91cd\u65b0\u5f00\u59cb*/
break;
if(snake.x[0] == food.x && snake.y[0] == food.y)/*\u5403\u5230\u98df\u7269\u4ee5\u540e*/
{
setcolor(0);/*\u628a\u753b\u9762\u4e0a\u7684\u98df\u7269\u4e1c\u897f\u53bb\u6389*/
rectangle(food.x, food.y, food.x + 10, food.y - 10);
snake.x[snake.node] =- 20; snake.y[snake.node] =- 20;
/*\u65b0\u7684\u4e00\u8282\u5148\u653e\u5728\u770b\u4e0d\u89c1\u7684\u4f4d\u7f6e,\u4e0b\u6b21\u5faa\u73af\u5c31\u53d6\u524d\u4e00\u8282\u7684\u4f4d\u7f6e*/
snake.node++;/*\u86c7\u7684\u8eab\u4f53\u957f\u4e00\u8282*/
food.yes = 1;/*\u753b\u9762\u4e0a\u9700\u8981\u51fa\u73b0\u65b0\u7684\u98df\u7269*/
score += 10;
PrScore();/*\u8f93\u51fa\u65b0\u5f97\u5206*/
}
setcolor(4);/*\u753b\u51fa\u86c7*/
for(i = 0; i < snake.node; i++)
rectangle(snake.x[i], snake.y[i], snake.x[i] + 10,
snake.y[i] - 10);
delay(gamespeed);
setcolor(0);/*\u7528\u9ed1\u8272\u53bb\u9664\u86c7\u7684\u7684\u6700\u540e\u4e00\u8282*/
rectangle(snake.x[snake.node-1], snake.y[snake.node-1],
snake.x[snake.node-1] + 10, snake.y[snake.node - 1] - 10);
} /*endwhile(\uff01kbhit)*/
if(snake.life == 1)/*\u5982\u679c\u86c7\u6b7b\u5c31\u8df3\u51fa\u5faa\u73af*/
break;
key = bioskey(0);/*\u63a5\u6536\u6309\u952e*/
if(key == ESC)/*\u6309ESC\u952e\u9000\u51fa*/
break;
else
if(key == UP&&snake.direction!=4)
/*\u5224\u65ad\u662f\u5426\u5f80\u76f8\u53cd\u7684\u65b9\u5411\u79fb\u52a8*/
snake.direction=3;
else
if(key == RIGHT &&snake.direction != 2)
snake.direction=1;
else
if(key == LEFT && snake.direction != 1)
snake.direction = 2;
else
if(key == DOWN && snake.direction != 3)
snake.direction = 4;
}/*endwhile(1)*/
}
/*\u6e38\u620f\u7ed3\u675f*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0, 0, 4);
outtextxy(200, 200, "GAME OVER");
getch();
}
/*\u8f93\u51fa\u6210\u7ee9*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL, YELLOW);
bar(50, 15, 220, 35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str, "score:%d", score);
outtextxy(55, 20, str);
}
/*\u56fe\u5f62\u7ed3\u675f*/
void Close(void)
{
getch();
closegraph();
}
\u6211\u5b9e\u73b0\u4e00\u4e2a\uff0c\u8bf7\u7b11\u7eb3~
\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8981\u5c06EGAVGA.BGI\u6587\u4ef6\u62f7\u5230\u548c\u8fd9\u4e2a\u6e90\u7a0b\u5e8f\u540c\u4e00\u4e2a\u76ee\u5f55\u4e0b\u624d\u80fd\u6b63\u5e38\u663e\u793a\u3002
EGAVGA.BGI\u5728C\u8bed\u8a00\u8f6f\u4ef6\u7684\u5b89\u88c5\u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5728\u8be5\u6587\u4ef6\u5939\u641c\u7d22\u627e\u5230\uff01
#include "stdio.h"
#include "graphics.h"
#include "stdlib.h"
#include "dos.h"
#define N 200
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define Esc 0x011b
int i,key;
int score=0;
int gamespeed=50000;
struct Food
{
int x;
int y;
int yes;
}food;
struct Snake
{
int x[N];
int y[N];
int node;
int direction;
int life;
}snake;
void Init();
void DrawK();
void GamePlay();
void GameOver();
void PrScore();
void Close();
void main()
{
Init();/*\u56fe\u5f62\u754c\u9762\u9a71\u52a8*/
DrawK();/*\u4f5c\u56f4\u5899*/
GamePlay();
Close();
}
/*\u56fe\u5f62\u754c\u9762\u9a71\u52a8\u6a21\u5757*/
void Init()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
}
/*\u4f5c\u77e9\u5f62\u56f4\u5899*/
void DrawK()
{
setcolor(11);
setlinestyle(0,0,3);
for(i=50;i<=600;i+=10)
{
rectangle(i,40,i+10,49);
rectangle(i,451,i+10,460);
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10);
rectangle(601,i,610,i+10);
}
getch();
}
void GamePlay()
{
randomize();
/*\u521d\u59cb\u72b6\u6001*/
food.yes=1;
snake.life=0;
snake.direction=1;
snake.x[0]=100;
snake.y[0]=100;
snake.x[1]=110;
snake.y[1]=100;
snake.node=2;
PrScore();
/*\u91cd\u590d\u73a9\u6e38\u620f\u6a21\u5757*/
while(1)
{
/*\u6ca1\u6709\u6309\u952e\u60c5\u51b5\u4e0b\u86c7\u7684\u8fd0\u52a8*/
while(!kbhit())
{
/*\u98df\u7269\u7684\u51fa\u73b0*/
if(food.yes==1)
{
food.x=rand()%400+60;
food.y=rand()%350+60;
/*\u5c06\u98df\u7269\u51fa\u73b0\u4f4d\u7f6e\u63a7\u5236\u5728\u6574\u683c*/
while(food.x%10!=0)
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*\u98df\u7269\u4f4d\u7f6e\u63a7\u5236\u597d\u4e86\u5c31\u6539\u53d8\u72b6\u6001*/
}
/*\u663e\u793a\u98df\u7269*/
if(food.yes==0)
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
/*\u86c7\u7684\u4f4d\u7f6e\u53d8\u5316*/
for(i=snake.node-1;i>0;i--)
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*\u6309\u65b9\u5411\u952e\u65f6\u86c7\u7684\u4f4d\u7f6e\u53d8\u5316*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2:snake.x[0]-=10;break;
case 3:snake.y[0]-=10;break;
case 4:snake.y[0]+=10;break;
}
/*\u86c7\u81ea\u5df1\u4e0e\u81ea\u5df1\u76f8\u649e\u65f6\u751f\u547d\u7ed3\u675f*/
for(i=3;i<snake.node;i++)
{
if(snake.x[i]==snake.x[0]&&snake.y[0]==snake.y[i])
{
GameOver();
snake.life=1;
break;
}
}
/*\u86c7\u649e\u5899\u65f6\u6b7b\u4ea1*/
if(snake.x[0]595||snake.y[0]455)
{
GameOver();
snake.life=1;
}
/*\u86c7\u7684\u751f\u547d\u72b6\u6001\u5224\u65ad*/
if(snake.life==1)
break;
/*\u86c7\u5403\u98df\u7269*/
if(snake.x[0]==food.x&&snake.y[0]==food.y)
{
setcolor(0);
rectangle(food.x,food.y,food.x+=10,food.y-=10);
snake.x[snake.node]=-20;
snake.y[snake.node]=-20;
snake.node++;
food.yes=1;
score+=10;
PrScore();
}
/*\u753b\u86c7*/
setcolor(4);
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
delay(gamespeed);
/*\u53bb\u9664\u6700\u540e\u4e00\u8282*/
setcolor(0);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
}/*end while(!kbhit())*/
if(snake.life==1)
break;
key=bioskey(0);
if(key==Esc)
break;
else if(key==UP&&snake.direction!=4)
snake.direction=3;
else if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
//\u6e38\u620f\u7ed3\u675f
void GameOver()
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*\u6253\u5370\u5206\u6570*/
void PrScore()
{
char str[10];
setfillstyle(1,14);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*\u56fe\u5f62\u7ed3\u675f*/
void Close()
{
getch();
closegraph();
}
以下是代码
/* 贪吃蛇程序 by champking */
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score = 0;/*得分*/
int gamespeed = 100000;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\c");
cleardevice();
}
/*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);/*设置线型*/
for(i = 50; i <= 600; i += 10)/*画围墙*/
{
rectangle(i, 40, i + 10, 49); /*上边*/
rectangle(i, 451, i + 10, 460);/*下边*/
}
for(i = 40; i <= 450; i += 10)
{
rectangle(50, i, 59, i + 10); /*左边*/
rectangle(601, i, 610, i + 10);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes = 1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life = 0;/*活着*/
snake.direction = 1;/*方向往右*/
snake.x[0] = 100; snake.y[0] = 100;/*蛇头*/
snake.x[1] = 110; snake.y[1] = 100;
snake.node = 2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes == 1)/*需要出现新食物*/
{
food.x = rand() % 400 + 60;
food.y = rand() % 350 + 60;
while(food.x % 10 != 0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y % 10 != 0)
food.y++;
food.yes = 0;/*画面上有食物了*/
}
if(food.yes == 0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x, food.y, food.x + 10, food.y - 10);
}
for(i = snake.node - 1; i > 0; i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i] = snake.x[i-1];
snake.y[i] = snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1: snake.x[0] += 10; break;
case 2: snake.x[0] -= 10; break;
case 3: snake.y[0] -= 10; break;
case 4: snake.y[0] += 10; break;
}
for(i = 3; i < snake.node; i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/
{
if(snake.x[i] == snake.x[0] && snake.y[i] == snake.y[0])
{
GameOver();/*显示失败*/
snake.life = 1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life == 1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0] == food.x && snake.y[0] == food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的食物东西去掉*/
rectangle(food.x, food.y, food.x + 10, food.y - 10);
snake.x[snake.node] =- 20; snake.y[snake.node] =- 20;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes = 1;/*画面上需要出现新的食物*/
score += 10;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i = 0; i < snake.node; i++)
rectangle(snake.x[i], snake.y[i], snake.x[i] + 10,
snake.y[i] - 10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1], snake.y[snake.node-1],
snake.x[snake.node-1] + 10, snake.y[snake.node - 1] - 10);
} /*endwhile(!kbhit)*/
if(snake.life == 1)/*如果蛇死就跳出循环*/
break;
key = bioskey(0);/*接收按键*/
if(key == ESC)/*按ESC键退出*/
break;
else
if(key == UP&&snake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key == RIGHT &&snake.direction != 2)
snake.direction=1;
else
if(key == LEFT && snake.direction != 1)
snake.direction = 2;
else
if(key == DOWN && snake.direction != 3)
snake.direction = 4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0, 0, 4);
outtextxy(200, 200, "GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL, YELLOW);
bar(50, 15, 220, 35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str, "score:%d", score);
outtextxy(55, 20, str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}
给你发消息了
http://hi.baidu.com/%C0%DA%CE%DE%B5%D02008/blog/item/d386a7dc5cfd07d18d102901.html
人命关天!!!!!!吓人啊!等我会了一定奉上
绛旓細include<stdio.h> include<stdlib.h> include<Windows.h> include<conio.h> include char gamemap[20][40];//娓告垙鍦板浘澶у皬 20*40 int score=0;//褰撳墠鍒嗘暟 //璁板綍铔囩殑缁撶偣 int x[800];//姣忎釜缁撶偣鐨勮缂栧彿 int y[800];//姣忎釜缁撶偣鐨勫垪缂栧彿 int len = 0;//铔囩殑闀垮害 //璁板綍姘存灉淇℃伅 int...
绛旓細include <windows.h> include <stdlib.h> include include <stdio.h> include <string.h> include <conio.h> define N 21 int apple[3],num;char score[3];char tail[3];void gotoxy(int x, int y) //杈撳嚭鍧愭爣 { COORD pos;pos.X = x;pos.Y = y;SetConsoleCursorPosition(Get...
绛旓細銆傘4555555555555
绛旓細initgraph(&gd, &gm, "c:\\tc");cleardevice();} /* 缁樺埗娓告垙鐣岄潰 */ void DrawGame(void) { setcolor(11);setlinestyle(SOLID_LINE, 0, THICK_WIDTH);for (i = 50; i <= 600; i += 10) { rectangle(i, 40, i + 10, 49); /* 鐢诲嚭涓婅竟妗 */ rectangle(i, 451, i + ...
绛旓細鎮ㄧ殑妤间富浼间箮鎻愪緵浜嗕竴娈C璇█缂栧啓鐨璐悆铔娓告垙浠g爜銆備互涓嬫槸瀵逛唬鐮佺殑涓浜涙鼎鑹插拰閿欒淇锛屼互鎻愰珮浠g爜璐ㄩ噺骞剁‘淇濆叾璇硶姝g‘锛1. 淇浜嗛儴鍒嗚娉曢敊璇紝渚嬪灏哷struct Food`鍜宍struct Snake`瀹氫箟涓殑`int`绫诲瀷鏀逛负`int x;`鍜宍int y;`浠ョ鍚圕璇█鏍囧噯銆2. 鏇存浜嗛儴鍒嗗彉閲忓懡鍚嶏紝渚嬪灏哷yes`鍜宍node`鏀...
绛旓細initgraph(&gd, &gm, "c:\\tc");cleardevice();} /*寮濮嬬敾闈,宸︿笂瑙掑潗鏍囦负(50,40),鍙充笅瑙掑潗鏍囦负(610,460)鐨勫洿澧*/ void DrawK(void){ /*setbkcolor(LIGHTGREEN);*/ setcolor(11);setlinestyle(SOLID_LINE, 0, THICK_WIDTH);/*璁剧疆绾垮瀷*/ for(i = 50; i <= 600; i += 10)/*...
绛旓細include <windows.h> include <ctime> include <iostream> include <vector> include <queue> using namespace std;ifndef SNAKE_H define SNAKE_H class Cmp { friend class Csnake;int rSign; //妯潗鏍 int lSign; //绔栧潗鏍 public:// friend bool isDead(const Cmp& cmp);Cmp(int r,int...
绛旓細include <stdio.h> include <graphics.h> include <stdlib.h> include <dos.h> /*寮曠敤鐨勫簱鍑芥暟*/ define LEFT 0x4b00 define RIGHT 0x4d00 define DOWN 0x5000 define UP 0x4800 define ESC 0x011b/*瀹忓畾涔夐敭鍚*/ define N 200 int i,key;int level;/*娓告垙绛夌骇*/ int score=0;/*寰楀垎...
绛旓細涓烘偍鎺ㄨ崘: c璇█绋嬪簭 璐悆铔嘽璇█浠g爜 璐悆铔囩紪绋嬩唬鐮侀噺300 c璇█鍏ラ棬鑷 c璇█ 璐悆铔 c璇█缂栫▼娓告垙 璐悆铔嘽璇█鑳屾櫙 c璇█鍏ラ棬璐悆铔 dos鍛戒护 鎬庝箞鐜ヾos璐悆铔 鍏朵粬绫讳技闂2015-04-26 鐢╟璇█鍐欎竴涓椽鍚冭泧娓告垙 2 2014-05-08 姹傚ぇ绁炵敤c璇█缂栦竴涓皬鍨嬭椽鍚冭泧娓告垙,鎬ユ眰!!浠婂ぉ鏅氫笂灏辫浜 2013...