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

#include<stdio.h>
#include<bios.h>
#include<conio.h>
#include<stdlib.h>
#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<NUM_TEST)
     {
       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);
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值