vs2013 c语言怎么运行程序吗,用VS2013肿么运行C语言编写的游戏游戏代码?

/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo…………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*/

/*贪吃蛇*/

#include

#include

#include

#include

int head=3 ,tail=0;

int main()

{

int i,j,k=0;

int zuobiao[2][80];

long start;

int direction=77;

int gamespeed;

int timeover;

int change(char qipan[20][80],int zuobiao[2][80],char direction);

zuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;

/*处理棋盘*/

char qipan[20][80];//定义棋盘

for(i=0;i<20;i++)

for(j=0;j<80;j++)

qipan[i][j]=' ';//初始化棋盘

for(i=0;i<80;i++)

qipan[0][i]='_';

for(i=0;i<20;i++)

qipan[i][0]='|';

for(i=0;i<20;i++)

qipan[i][79]='|';

for(i=0;i<80;i++)

qipan[19][i]='_';

qipan[1][1]=qipan[1][2]=qipan[1][3]='*';//初始化蛇的位置

qipan[1][4]='#';

printf("This is a game of a SNAKE.\nGOOD LUCK TO YOU !\n");

printf("Input your game speed,please.(e.g.300)\n");

scanf("%d",&gamespeed);

while(direction!='q')

{

system("cls");

for(i=0;i<20;i++)//打印出棋盘

for(j=0;j<80;j++)

printf("%c",qipan[i][j]);

timeover=1;

start=clock();

while(!kbhit()&&(timeover=clock()-start<=gamespeed));

if(timeover)

{

getch();

direction=getch();

}

else

direction=direction;

if(!(direction==72||direction==80||direction==75||direction==77))

{

return 0;

system("cls");

printf("GAME OVER!\n");

}

if(!change(qipan,zuobiao,direction))

{

direction='q';

system("cls");

printf("GAME OVER!\n");

}

}

return 0;

}

int change(char qipan[20][80],int zuobiao[2][80],char direction)

{

int x,y;

if(direction==72)

x=zuobiao[0][head]-1;y=zuobiao[1][head];

if(direction==80)

x=zuobiao[0][head]+1;y=zuobiao[1][head];

if(direction==75)

x=zuobiao[0][head];y=zuobiao[0][head]-1;

if(direction==77)

x=zuobiao[0][head];y=zuobiao[1][head]+1;

if(x==0||x==18||y==78||y==0)

return 0;

if(qipan[x][y]!=' ')

return 0;

qipan[zuobiao[0][tail]][zuobiao[1][tail]]=' ';

tail=(tail+1)%80;

qipan[zuobiao[0][head]][zuobiao[1][head]]='*';

head=(head+1)%80;

zuobiao[0][head]=x;

zuobiao[1][head]=y;

qipan[zuobiao[0][head]][zuobiao[1][head]]='#';

return 1;

}

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值