程序代码:
#include <stdio.h>
#include <conio.h>
int score;
void play(void);
int main(void)
{
printf("w a s d\n");
printf("press any key to start except 'q'.\n");
do
{
score=0;
getch();
play();
}
while( getch()!='q' );
getch();
}
void play(void)
{
char a;
char input;
int ctrl;
for(ctrl=0; ctrl<10; ctrl++)
{
a=rand()%4+24;
printf("%c",a);
input=getch();
switch (a)
{
case 24:
if(input=='w')
{
score++;
printf(" ");
}
else
printf("X ");
break;
case 25:
if(input=='s')
{
score++;
printf(" ");
}
else
printf("X ");
break;
case 26:
if(input=='d')
{
score++;
printf(" ");
}
else
printf("X ");
break;
case 27:
if(input=='a')
{
score++;
printf(" ");
}
else
printf("X ");
break;
default:
score--;
printf("X ");
}
}
printf("\nYou score is %d.\n",score);
printf("press any key to start except 'q'.\n");
}
练练你的左手吧
[
本帖最后由 dsl975708035 于 2012-8-14 21:25 编辑 ]