分类:
2008-10-15 16:40:31
想编个贪吃蛇游戏,但是在编写这个游戏之前想先练练兵,所以就编了这个按键游戏,没有用多少色彩,而且很菜,都挤在一起了,请大家多多指教.
#include "conio.h"
#include "stdlib.h"
#include "graphics.h"
main()
{char a[36];
int i,j,x,key,t,score=0;
int gd=DETECT,gr;
initgraph(&gd,&gr,"");
cleardevice();
for(i=0;i<10;i++)
a[i]=48+i;
for(i=10;i<36;i++)
a[i]=55+i;
a[i]=0;
for(i=1;i<81;i++) /*游戏初始化*/
gotoxy(5,1);
printf("score:");
settextstyle(1,0,8);
outtextxy(100,350,"TYPE GAME"); /*初始化结束*/
sleep(2);
randomize();
for(;;)
{
gotoxy(12,1);
printf(" ");
gotoxy(12,1);
printf("%d",score);
i=rand()%80; /*随机赋值*/
if(i==0)
i=1;
x=rand()%36;
t=0;
for(j=4;!kbhit()&&j!=18;j++) /*自动移动*/
{
gotoxy(i,j);
printf("%c",a[x]);
gotoxy(i,j);
if(score<10) /*难度设定*/
delay(10000);
else if(score<20)
delay(7000);
else if(score<30)
delay(5000);
else if(score<40)
delay(4000);
if(score==40) /*游戏胜利*/
{
clrscr();
textmode(C40);
delay(100000);
gotoxy(18,12);
printf("YOU WIN!");
delay(100000);
exit(1);
}
gotoxy(i,j);
printf(" ");
gotoxy(i,j);
} /*自动移动结束一个循环*/
if(j==18)
{
t=1;
score--;
}
if(t==1)
continue;
key=bioskey(0);
if(key==0x011b)
break;
[1]