资源简介

用Vs2013 写的,用到了EasyX的只是,界面简单明了,欢迎大家借鉴学习。

资源截图

代码片段和文件信息

#include “snake.h“//graphics.h MFC WIN32 qt cocos unity UE opencv opengl directx
int tim=200;
int main()
{
srand((unsigned int)time(NULL));
initgraph(640480);//窗口
InitSnake();
while(1)
{
while(!kbhit())
{
if(Gameover==true)
{
InitSnake();
Gameover=false;
food .flag=0;
game=true;
snake.ch=kong;
tim = 200;
}
if(food.flag==0)
{
Coorfood();
}
cleardevice();
if(game==0)
{
GameOver();
MoverSnake();
DrawSnake();
DrawFood();
EatFood();
Sleep(tim);
}
else
{
DrawSnake();
DrawFood();
game=0;
break;
}
}
ChangerSnakeCh();
}

//1.
//initgraph(640480);//窗口
//cmd.exe system(“cls“);
//2.
//setbkcolor(GREEN);//设置背景颜色
//cleardevice();//背景颜色,默认黑色
//像素矩阵  坐标系
//settextstyle(1000L“微软雅黑“);
//outtextxy(100240L“fsag“);//在指定的坐标输出文本
//蛇
//rectangle(001010);
//食物
//circle(320240100);
//while(1);
return 0;
}
//初始化蛇
void InitSnake()
{
//PlaySound();//WAV 音乐
//mciSendString(L“open ./res/天使的翅膀.mp3 alias BGM“000);
//mciSendString(L“play BGM“000);

//蛇
snake.n=1;
//snake.ch=right;
snake.szb[0].x=10;
snake.szb[0].y=10;

}

void DrawSnake()
{
setlinecolor(WHITE);
setfillcolor(GREEN);
for (int i = 0; i<=48; i++)
{
fillrectangle(0 i * 10 10 10 * i + 10);
fillrectangle(630 i * 10 640 10 * i + 10);
}
for (int i = 0; i <= 64; i++)
{
fillrectangle(i*10 0 10 * i + 1010 );
fillrectangle(i * 10470 10 * i + 10480 );
}
setlinecolor(YELLOW);
setfillcolor(RED);
//bianli shuzu
for(int i=0;i {
fillrectangle(snake.szb[i].xsnake.szb[i].y
snake.szb[i].x+10snake.szb[i].y+10);
}

}

void MoverSnake()
{
for(int i=snake.n-1;i>0;i--)
{
snake.szb[i].x=snake.szb[i-1].x;
snake.szb[i].y=snake.szb[i-1].y;
}
switch (snake.ch)
{
case up:
snake.szb[0].y-=10;break;
case down:
snake.szb[0].y+=10;break;
case left:
snake.szb[0].x-=10;break;
case right:
snake.szb[0].x+=10;break;
break;
}
}

void ChangerSnakeCh()
{
int move;
move=getch();
switch(move)
{
case right:
if(snake.ch!=left)
snake.ch=right;break;
case up:
if(snake.ch!=down)
snake.ch=up;break;
case down:
if(snake.ch!=up)
snake.ch=down;break;
case left:
if(snake.ch!=right)
snake.ch=left;break;
break;
}
}
void Coorfood()
{
food.fzb.x=((rand()%62)+1)*10;
food.fzb.y=((rand()%46)+1)*10;
food.flag=1;
}

void DrawFood()
{
fillroundrect(food.fzb.xfood.fzb.yfood.fzb.x+10food.fzb.y+101010);
}

void EatFood()
{
if(snake.szb[0].x==food.fzb.x&&snake.szb[0].y==food.fzb.y)
{
snake.n++;
food.flag=0;
tim = (int)tim * 0.99  ;
}
}

void GameOver()
{
wchar_t str[100];
if(snake.szb[0].x<10||snake.szb[0].y>470||snake.szb[0].x>630||snake.szb[0].y<10)
{
Gameover=true;
for(int i=5;i>0;i--)
{
cleardevice();

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-15 11:00  snake\
     目录           0  2018-08-15 10:58  snake\Debug\
     文件      627712  2018-08-15 10:58  snake\Debug\snake.exe
     文件         406  2018-08-15 10:58  snake\Debug\snake.exe.manifest
     文件     1537724  2018-08-15 10:58  snake\Debug\snake.ilk
     文件     2797568  2018-08-15 10:58  snake\Debug\snake.pdb
     文件      642373  2018-08-13 20:55  snake\EasyX_2018春分版.exe
     目录           0  2018-08-14 22:00  snake\ipch\
     目录           0  2018-08-14 22:00  snake\ipch\snake-c3bbb363\
     文件    31064064  2018-08-14 21:36  snake\ipch\snake-c3bbb363\snake-9ca0c1e.ipch
     目录           0  2018-08-14 23:08  snake\snake\
     目录           0  2018-08-15 10:58  snake\snake\Debug\
     文件       40622  2018-08-15 10:58  snake\snake\Debug\main.obj
     文件         967  2018-08-15 10:58  snake\snake\Debug\snake.Build.CppClean.log
     文件         381  2018-08-15 10:58  snake\snake\Debug\snake.exe.intermediate.manifest
     文件          44  2018-08-14 21:36  snake\snake\Debug\snake.lastbuildstate
     文件        2153  2018-08-15 10:58  snake\snake\Debug\snake.log
     目录           0  2018-08-15 10:58  snake\snake\Debug\snake.tlog\
     文件       18682  2018-08-15 10:58  snake\snake\Debug\snake.tlog\CL.read.1.tlog
     文件         364  2018-08-15 10:58  snake\snake\Debug\snake.tlog\CL.write.1.tlog
     文件         566  2018-08-15 10:58  snake\snake\Debug\snake.tlog\cl.command.1.tlog
     文件        1110  2018-08-15 10:58  snake\snake\Debug\snake.tlog\link.command.1.tlog
     文件        2446  2018-08-15 10:58  snake\snake\Debug\snake.tlog\link.read.1.tlog
     文件         480  2018-08-15 10:58  snake\snake\Debug\snake.tlog\link.write.1.tlog
     文件         386  2018-08-15 10:58  snake\snake\Debug\snake.tlog\mt.command.1.tlog
     文件         142  2018-08-15 10:58  snake\snake\Debug\snake.tlog\mt.read.1.tlog
     文件         242  2018-08-15 10:58  snake\snake\Debug\snake.tlog\mt.write.1.tlog
     文件         157  2018-08-15 10:58  snake\snake\Debug\snake.tlog\snake.lastbuildstate
     文件      494592  2018-08-15 10:58  snake\snake\Debug\vc120.idb
     文件      143360  2018-08-15 10:58  snake\snake\Debug\vc120.pdb
     文件        3736  2018-08-14 23:08  snake\snake\main.cpp
............此处省略11个文件信息

评论

共有 条评论