学C 3个月编的一段小程序
字符下落游戏,大家指教下#include <conio.h>
#include <stdlib.h>
void a()
{
textbackground(RED);
clrscr();
textcolor(1);
gotoxy(22,15);
cprintf("Hello!\b");
delay(1000);
}
void b()
{
textbackground(YELLOW);
clrscr();
textcolor(2);
gotoxy(30,15);
delay(300);
cprintf("H");
delay(300);
cprintf("e");
delay(300);
cprintf("l");
delay(300);
cprintf("l");
delay(300);
cprintf("o");
delay(300);
cprintf("!\b");
delay(1000);
}
void c()
{
exit(1);
}
int menu()
{
int i, key, presskey;
textbackground(BLUE);
clrscr();
textcolor(2);
for(i=25;i<=50;i++)
{gotoxy(i,8);
cprintf("%c",205);}
for(i=25;i<=50;i++)
{gotoxy(i,20);
cprintf("%c",205);}
for(i=9;i<=19;i++)
{gotoxy(24,i);
cprintf("%c",186);}
for(i=9;i<=19;i++)
{gotoxy(51,i);
cprintf("%c",186);}
{gotoxy(24,8);
cprintf("%c",201);}
{gotoxy(51,8);
cprintf("%c",187);}
{gotoxy(24,20);
cprintf("%c",200);}
{gotoxy(51,20);
cprintf("%c",188);} /*text*/
textcolor(14);
{gotoxy(32,11);
cprintf("1.singal");}
{gotoxy(32,13);
cprintf("2.multiletter");}
{gotoxy(32,15);
cprintf("3.quit");}
{gotoxy(25,17);
cprintf("please choose number:(1~3)");} /*text*/
{gotoxy(35,19);
cprintf(" ");}
presskey=key=bioskey(0)&0xff;
do
{
key=presskey;
switch(key)
{
case 49:cprintf("1\b");break;
case 50:cprintf("2\b");break;
case 51:cprintf("3\b");break;
default:cprintf(" \b");
}
presskey=bioskey(0)&0xff;
}while(presskey!=13);
switch(key)
{
case 49:return(1);
case 50:return(2);
case 51:return(3);
default:return(0);
}
}
main()
{
do{
switch(menu())
{
case 1:s();break;
case 2:u();break;
case 3:c();break;
case 0:break;
default:return(0);
}
}while(1); /*kz*/
}
s()
{int i;
int k;
int t;
int z;
int right=0;
int wrong=0;
int total=0;
int key,low;
int a=0+random(61);
int c1=97+random(26);
textbackground(BLUE);
clrscr();
textcolor(RED);
textcolor(5);
{gotoxy(65,12);
cprintf("total=0");}
{gotoxy(65,14);
cprintf("right=0");}
{gotoxy(65,16);
cprintf("wrong=0");}
textcolor(15);
for(t=2;t<=78;t++)
{gotoxy(t,1);
cprintf("%c",205);}
for(t=2;t<=78;t++)
{gotoxy(t,25);
cprintf("%c",205);}
for(t=2;t<=25;t++)
{gotoxy(1,t);
cprintf("%c",186);}
for(t=2;t<=25;t++)
{gotoxy(78,t);
cprintf("%c",186);}
{gotoxy(1,1);
cprintf("%c",201);}
{gotoxy(78,1);
cprintf("%c",187);}
{gotoxy(1,25);
cprintf("%c",200);}
{gotoxy(78,25);
cprintf("%c",188);}
for(k=61;k<=75;k++)
{gotoxy(k,8);
cprintf("%c",205);}
for(k=61;k<=75;k++)
{gotoxy(k,20);
cprintf("%c",205);}
for(k=9;k<=20;k++)
{gotoxy(60,k);
cprintf("%c",186);}
for(k=9;k<=20;k++)
{gotoxy(75,k);
cprintf("%c",186);}
{gotoxy(60,8);
cprintf("%c",201);}
{gotoxy(75,8);
cprintf("%c",187);}
{gotoxy(60,20);
cprintf("%c",200);}
{gotoxy(75,20);
cprintf("%c",188);} /*text*/
{gotoxy(35,19);
cprintf(" ");}
for(z=7;z<=30;z++)
{gotoxy(z,21);cprintf("%c",196);}
{gotoxy(7,22);cprintf("Plese press 'Esc' to return the menu!");}
{gotoxy(5,22);cprintf("%c",219);}
while(1)
while(1)
{
for(i=3;i<=17;i++)
{
gotoxy(a,i);
cprintf("%c\b",c1);
if(kbhit())
{
key=bioskey(0)&0xff;
if(key==27){return;}
low=key&0xff;
if(low==c1)
{ cprintf(" ");
right=right+1;
break;
}
else wrong=wrong+1;
cprintf(" ");
break;
}
delay(65535);
cprintf(" ");
if(i==17)
{wrong=wrong+1;}
}
c1=97+random(26);
a=0+random(61);
total=total+1;
textcolor(14);
{gotoxy(65,12);
cprintf("total=%d",total);}
{gotoxy(65,14);
cprintf("right=%d",right);}
{gotoxy(65,16);
cprintf("wrong=%d",wrong);}
}
getch();
}
u()
{
int x[9999],y=2,n[9999],x1=0,n1=0,m,t,RIGHT=0,WRONG=0,TOTAL=0,i;
window(1,1,80,25);
randomize();
textbackground(0);
clrscr();
textcolor(15);
for(i=2;i<=79;i++)
{gotoxy(i,2);
cprintf("%c",205);}
for(i=2;i<=79;i++)
{gotoxy(i,25);
cprintf("%c",205);}
for(i=3;i<=24;i++)
{gotoxy(1,i);
cprintf("%c",186);}
for(i=3;i<=24;i++)
{gotoxy(80,i);
cprintf("%c",186);}
{gotoxy(1,2);
cprintf("%c",201);}
{gotoxy(80,2);
cprintf("%c",187);}
{gotoxy(1,25);
cprintf("%c",200);}
{gotoxy(80,25);
cprintf("%c",188);}
for(i=62;i<=78;i++)
{gotoxy(i,9);
cprintf("%c",205);}
for(i=62;i<=78;i++)
{gotoxy(i,19);
cprintf("%c",205);}
for(i=10;i<=18;i++)
{gotoxy(61,i);
cprintf("%c",186);}
for(i=10;i<=18;i++)
{gotoxy(79,i);
cprintf("%c",186);}
for(i=2;i<=60;i++)
{gotoxy(i,22);
cprintf("%c",220);}
{gotoxy(61,9);
cprintf("%c",201);}
{gotoxy(79,9);
cprintf("%c",187);}
{gotoxy(61,19);
cprintf("%c",200);}
{gotoxy(79,19);
cprintf("%c",188);}
textcolor(12); /*字体颜色*/
gotoxy(67,11);cprintf("RIGHT:%d",RIGHT);
gotoxy(67,14);cprintf("WRONG:%d",WRONG);
gotoxy(67,17);cprintf("TOTAL:%d",TOTAL);
gotoxy(65,8);cprintf("inputscore");
gotoxy(5,23);cprintf("Plese press 'Esc' to return the menu!");
while(1)
{
t=0;
x1=x1+1;n1=n1+1;
x[x1]=random(57)+3;n[n1]=97+random(26);
gotoxy(x[x1],y);cprintf("%c",n[n1]);
if(x1-1>=1) {gotoxy(x[x1-1],y+1);cprintf("%c",n[n1-1]);}
if(x1-2>=1) {gotoxy(x[x1-2],y+3);cprintf("%c",n[n1-2]);}
if(x1-3>=1) {gotoxy(x[x1-3],y+5);cprintf("%c",n[n1-3]);}
if(x1-4>=1) {gotoxy(x[x1-4],y+7);cprintf("%c",n[n1-4]);}
if(x1-5>=1) {gotoxy(x[x1-5],y+9);cprintf("%c",n[n1-5]);}
if(x1-6>=1) {gotoxy(x[x1-6],y+11);cprintf("%c",n[n1-6]);}
if(x1-7>=1) {gotoxy(x[x1-7],y+13);cprintf("%c",n[n1-7]);}
if(x1-8>=1) {gotoxy(x[x1-8],y+15);cprintf("%c",n[n1-8]);}
if(x1-9>=1) {gotoxy(x[x1-9],y+17);cprintf("%c",n[n1-9]);}
if(x1-10>=1) {gotoxy(x[x1-10],y+19);cprintf("%c",n[n1-10]);}
textcolor(1);cprintf(" \b");textcolor(14);
sleep(1); /*延时*/
gotoxy(x[x1],y);cprintf(" ");
if(x1-1>=1) {gotoxy(x[x1-1],y+1);cprintf(" ");}
if(x1-2>=1) {gotoxy(x[x1-2],y+3);cprintf(" ");}
if(x1-3>=1) {gotoxy(x[x1-3],y+5);cprintf(" ");}
if(x1-4>=1) {gotoxy(x[x1-4],y+7);cprintf(" ");}
if(x1-5>=1) {gotoxy(x[x1-5],y+9);cprintf(" ");}
if(x1-6>=1) {gotoxy(x[x1-6],y+11);cprintf(" ");}
if(x1-7>=1) {gotoxy(x[x1-7],y+13);cprintf(" ");}
if(x1-8>=1) {gotoxy(x[x1-8],y+15);cprintf(" ");}
if(x1-9>=1) {gotoxy(x[x1-9],y+17);cprintf(" ");}
if(x1-10>=1) {gotoxy(x[x1-10],y+19);cprintf(" ");}
if(kbhit())
{
m=bioskey(0)&0xff;
if(m==27)
{return;}
if(m==n[n1-10])
{n[n1-10]=32;t=1;}
else if(m==n[n1-9])
{n[n1-9]=32;t=1;}
else if(m==n[n1-8])
{n[n1-8]=32;t=1;}
else if(m==n[n1-7])
{n[n1-7]=32;t=1;}
else if(m==n[n1-6])
{n[n1-6]=32;t=1;}
else if(m==n[n1-5])
{n[n1-5]=32;t=1;}
else if(m==n[n1-4])
{n[n1-4]=32;t=1;}
else if(m==n[n1-3])
{n[n1-3]=32;t=1;}
else if(m==n[n1-2])
{n[n1-2]=32;t=1;}
else if(m==n[n1-1])
{n[n1-1]=32;t=1;}
else if(m==n[n1])
{n[n1]=32;t=1;}
}
if(t==1)
RIGHT=RIGHT+1;
else
WRONG=WRONG+1;
TOTAL=TOTAL+1;
gotoxy(73,11);cprintf("%d",RIGHT);
if(WRONG>=10) {gotoxy(73,14);cprintf("%d",WRONG-9);}
if(TOTAL>=10) {gotoxy(73,17);cprintf("%d",TOTAL-9);}
}
getch();
}