一个简易的打字速度测量----C编写

#include
#include
#include
#include
#define WALL 1                      /* 边窗的ASCII码 */
#define TIMELIMIT 2              /* 字符下降的速度*/
#define BCOLOR BLACK     /* 背景的颜色*/
#define WCOLOR WHITE    /*下降的字符颜色*/
int NUM_TEST;                      /*接受你所输入的测试字符数*/
int X,Y;                                    /* 字符的位置 */    
int timeover()                        /*测试下降的时间是否到*/
{
  static long int tm1,tm2;
  tm1 = biostime(0,0l);
  if(tm1-tm2 > TIMELIMIT) { tm2=tm1; return 1; }
  else return 0;
}
void putword( int c)
{
  gotoxy(X,Y);
  putch(c);
}
void cutword(int bkground)
{
  gotoxy(X,Y);
  textcolor(bkground);
  putch('');
  textcolor(WHITE);
}
union key {           
           unsigned i;
           char ch[2];
          }bkey;
main()
{
 int i, j;
 int success,quit=0;
 int WORD,count,right;
 do{
   clrscr();
   do{printf("input your test_number that you want:/n");
      scanf("%d",&NUM_TEST);
     }while(NUM_TEST<0);
   clrscr();
   printf("if you want to quit,press esc. ");
   textbackground(BCOLOR);
   textcolor(WCOLOR);
   for(i=0;i<=20;i++)
     { gotoxy(20+i,3);putch(WALL);
       gotoxy(20+i,23);putch(WALL);
     }
   for(j=3;j<=23;j++)
     { gotoxy(20,j);putch(WALL);
       gotoxy(40,j);putch(WALL);
     }
   getch();
   count = 0;
   right = 0;
   while(count     {
       if(quit == 1) break;
       count++;
       WORD = 33;
       WORD += random(94);
       X = 30;Y = 4;
       while(1)
         { success = 0;
    putword(WORD);
           while(!timeover())
             { if(bioskey(1)!=0)
                 {
             bkey.i = bioskey(0);
             if(bkey.ch[0] == WORD) { success = 1; cutword(BCOLOR);break; }
      if(bkey.ch[0] == 27) {quit = 1;break;  }
   }
             }
           if(success == 1) { right++;break; }
    else if(quit ==1)break;
    cutword(BCOLOR);
           ++Y;
    if(Y>22)break;
         }
     }
  if(quit == 1) break;
  clrscr();
  printf("count number: %d  /nright number: %d/n",NUM_TEST,right);
  printf("error number: %d/n",NUM_TEST-right);
  printf("try angin ? y/n/n");
  do { bkey.i = bioskey(0); }while(bkey.ch[0]!='y' && bkey.ch[0]!='n');
  if(bkey.ch[0] == 'n' )break;
 }while(1);
}

 

你可能感兴趣的:(about,c)