c++编写手机小游戏代码_求一C++小游戏源代码简单点的?!!谢谢

这是一个使用C++编写的简单手机小游戏代码示例,包括结构体定义、游戏控制函数、速度调节、游戏菜单选择等功能。玩家可以调整游戏速度并进行游戏交互。
摘要由CSDN通过智能技术生成

#include

#include

#include

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define DOWN 0x5000

#define UP 0x4800

#define ESC 0x011b

int i,key;

int score=0;

int gamespeed=32000;

struct Food /*食物的结构体*/

{

int x; /*食物的横坐标*/

int y; /*食物的纵坐标*/

int yes; /*食物是否出现的变量*/

}food;

struct Snack /*蛇的结构体*/

{

int x;

int y;

int node; /*蛇的节数*/

int direction; /*蛇的方向*/

int life; /*蛇的生命,0活着,1死亡*/

}snake;

void Init(void); /*图形驱动*/

void Close(void); /*关闭游戏函数*/

void DrawK(void); /*画图函数*/

void GameOver(void);/*输出失败函数*/

void GamePlay(); /*游戏控制函数 主要程序*/

void PrScore(void); /*分数输出函数*/

DELAY(char ch)/*调节游戏速度*/

{

if(ch=='3')

{

delay(gamespeed); /*delay是延迟函数*/

delay(gamespeed);

}

else if(ch=='2')

{

delay(gamespeed);

}

}

Menu()/*游戏开始菜单*/

{

char ch;

printf("Please choose the gamespeed:\n");

printf("1-Fast 2-Normal 3-Slow\n");

printf("\nPlease Press The numbers..\n");

do

{ch=getch();}

while(ch!='1'&&ch!='2'&&ch!='3');

clrscr();

return(ch);

}

/*主函数*/

void main(void)

{

int ch;

ch=Menu();

Init();

DrawK();

GamePlay(ch);

Close();

}

void Init(void)

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc");

cleardevice();

}

void DrawK(void)

{

setcolor(11);

setlinestyle(SOLID_LINE,0,THICK_WIDTH);

for(i=50;i

匿名用户   2009-05-24 21:36

宝宝知道提示您:回答为网友贡献,仅供参考。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值