⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dohf.cpp

📁 我学c语言时用TC写的打字程序
💻 CPP
字号:
#include<dos.h>
#include<time.h>
#include<string.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
/************************************************************************/
struct list
{char name[10];
 float score;
 int paper;
}list[10];

int i;
char ch;
char type[648];

void quit()
{window(1,1,80,25);
 textbackground(BLACK);
 textcolor(WHITE);
 clrscr();
 printf("BYE-BYE!");
 exit(0);
}

int hline(int xl,int xr,int y,int d)
{int count;
 gotoxy(xl,y);
 if(d==0)
   for(count=xl;count<=xr;count++)printf("%c",95);
 else if(d==1)
	for(count=xl;count<=xr;count++)printf("%c",196);
      else if(d==2)
	     for(count=xl;count<=xr;count++)printf("%c",205);
	   else return(-1);
 return(1);
}

int vline(int y1,int y2,int x,int d)
{int count;
 gotoxy(x,y1);
 if(d==1)
   for(count=y1;count<=y2;count++)
     {gotoxy(x,count);
      printf("%c",179);
     }
 else if(d==2)
	for(count=y1;count<=y2;count++)
	  {gotoxy(x,count);
	   printf("%c",186);
	  }
      else return(-1);
 return(1);
}

void empty()
{FILE *fp;
 int i;
 for(i=0;i<=10;i++)
   {strcpy(list[i].name,"Non");
    list[i].score=0;
    list[i].paper=0;
   }
  if((fp=fopen("stats.dat","w"))==NULL)
   {printf("Cannot open the file stats.dat");
    exit(0);
   }
 for(i=1;i<10;i++)fwrite(&list[i],sizeof(struct list),1,fp);
 fclose(fp);
 printf("sucess");
}




void listlist()
{int i,j;
 char ch;
 void menu();
 window(1,1,80,25);
 textbackground(7);
 clrscr();
 window(20,2,60,2);
 textbackground(CYAN);
 clrscr();
 window(22,2,24,2);
 textcolor(RED);
 clrscr();
 printf("Esc to back");
 window(20,3,60,23);
 textbackground(LIGHTBLUE);
 textcolor(WHITE);
 clrscr();
 printf("%c",201);
 hline(2,40,1,2);
 printf("%c",187);
 vline(2,20,1,2);
 vline(2,20,41,2);
 gotoxy(1,21);
 printf("%c",200);
 hline(2,40,21,2);
 printf("%c",188);
 for(i=3;i<=19;i=i+2)hline(3,39,i,0);
 gotoxy(3,2);
 printf(" name      score     paper   position");

 j=4;
 gotoxy(3,4);
 for(i=1;i<10;i++)
   {printf(" %-8s  %4.2f      paper(%d)    %d\n",list[i].name,list[i].score,list[i].paper,i);
    j=j+2;
    gotoxy(3,j);
   }
 ch=getch();
 while(1)
   {if(ch==27)break;
    if(ch==113)
      {empty();
       listlist();
      }
    ch=getch();
   }
 menu();

}


void stats(float correct,double dtime,int paper)
{float rats,statas,speed,score;
 char ch,name[10];
 FILE *fp;
 int i,j;
 void menu();
 paper=paper+1;
 rats=(correct*100)/648;
 speed=(correct*60)/dtime;
 score=speed*17/100+rats-60   ;
 if(score<0||rats<40)score=0;
 if(score>100)score=100;
 window(1,1,80,25);
 textbackground(CYAN);
 clrscr();
 window(20,3,60,23);
 textbackground(LIGHTBLUE);
 textcolor(WHITE);
 clrscr();
 printf("%c",201);
 hline(2,40,1,2);
 printf("%c",187);
 vline(2,20,1,2);
 vline(2,20,41,2);
 gotoxy(1,21);
 printf("%c",200);
 hline(2,40,21,2);
 printf("%c",188);
 gotoxy(5,3);
 printf("speed is:%3.0f key/minute",speed);
 gotoxy(5,6);
 printf("rats is:%2.1f%",rats);
 gotoxy(5,9);
 printf("score is:%2.2f",score);
 window(24,20,26,20);
 textbackground(CYAN);
 textcolor(RED);
 clrscr();
 printf("ESC to BACK");
 window(41,20,45,20);
 textbackground(CYAN);
 textcolor(RED);
 clrscr();
 printf("Enter to playlist");
 if((fp=fopen("stats.dat","r"))==NULL)
   {printf("Cannot open the file stats.dat");
    exit(0);
   }
 for(i=1;i<10;i++)
   fread(&list[i],sizeof(struct list),1,fp);
 fclose(fp);
 if(score>list[9].score)
   {window(20,3,60,23);
    gotoxy(2,13);
    printf("Input you name:");
    gotoxy(17,14);
    gets(name);
    for(i=9;i>=1&&score>list[i].score;i--);
    for(j=8;j>i;j--)
      {strcpy(list[j+1].name,list[j].name);
       list[j+1].score=list[j].score;
       list[j+1].paper=list[j].paper;
      }

    strcpy(list[i+1].name,name);
    list[i+1].score=score;
    list[i+1].paper=paper;
    if((fp=fopen("stats.dat","w"))==NULL)
      {printf("Write file stats.dat erroe!");
       exit(0);
      }
    for(i=1;i<10;i++)
    fwrite(&list[i],sizeof(struct list),1,fp);
    fclose(fp);
    listlist();
   }
 else
   {ch=getch();
    while(1)
      {if(ch==27)
	 {menu();
	  break;
	 }
       if(ch==13){listlist();break;}
       ch=getch();
      }
   }

}

void menu()
{char ch;
 int i=1,j=1,num;
 void ui(int num);
 window(1,1,80,25);
 textbackground(8);
 textcolor(WHITE);
 clrscr();
 gotoxy(2,2);
 printf("%c",201);
 hline(3,78,2,2);
 printf("%C",187);
 vline(3,23,2,2);
 vline(3,23,79,2);
 gotoxy(2,24);
 printf("%c",200);
 hline(3,78,24,2);
 printf("%c",188);
 hline(3,55,17,1);
 vline(3,23,56,1);
 window(2,1,79,1);
 textbackground(CYAN);
 textcolor(BLUE);
 clrscr();
 gotoxy(23,1);
 printf("to exit");
 gotoxy(52,1);
 printf("Non");

 window(20,1,22,1);
 textcolor(RED);
 clrscr();
 printf("ESC");
 window(50,1,51,1);
 textcolor(RED);
 clrscr();
 printf("F1");
 window(22,4,32,4);
 textcolor(RED);
 clrscr();
 printf(" Main menu");
 window(9,7,14,7);
 textcolor(RED);
 clrscr();
 printf(" Easy");
 window(25,7,30,7);
 textcolor(RED);
 clrscr();
 printf(" Hard");
 window(39,7,49,7);
 textcolor(RED);
 clrscr();
 printf(" Very hard");
 window(61,5,74,5);
 textcolor(RED);
 clrscr();
 printf(" Construction");
 window(21,18,31,18);
 textcolor(RED);
 clrscr();
 printf(" Operation");
 window(1,1,80,25);
 gotoxy(10,10);printf("paper(1)       paper(6)       paper(11)");
 gotoxy(10,11);printf("paper(2)       paper(7)       paper(12)");
 gotoxy(10,12);printf("paper(3)       paper(8)       paper(13)");
 gotoxy(10,13);printf("paper(4)       paper(9)       paper(14)");
 gotoxy(10,14);printf("paper(5)       paper(10)      paper(15)");
 gotoxy(10,20);printf("%c %c     Change your choice",24,25);
 gotoxy(10,22);printf("Enter   Decide on your choice");
 gotoxy(58,7);printf("%c Automatically",232);
 gotoxy(58,9);printf("        chang line!");
 gotoxy(58,11);printf("%c Typing error ",232);
 gotoxy(58,12);printf("         for no use!");
 gotoxy(58,14);printf("%c Thank for use!",232);
 gotoxy(16,10);
 LABEL: ch=getch();
 switch(ch)
   {case 13:num=5*(j-1)+i-1;ui(num);break;
    case 27:quit();
    case 77:if(j<3){gotoxy(wherex()+15,wherey());j=j+1;}goto LABEL;
    case 75:if(j>1){gotoxy(wherex()-15,wherey());j=j-1;}goto LABEL;
    case 80:if(i<5){gotoxy(wherex(),wherey()+1);i=i+1;}goto LABEL;
    case 72:if(i>1){gotoxy(wherex(),wherey()-1);i=i-1;}goto LABEL;
    default :goto LABEL;
   }
}



int getsource(int num)
{int col,i,row,dohf;
 FILE *fp;
 if((fp=fopen("type.dat","r"))==NULL)
   {printf("Can not open the source file type.dat!\n");
    exit(0);
   }
 fseek(fp,648*num,0);
 for(i=0;i<648;i++)type[i]=fgetc(fp);
 row=1;
 i=0;
 while(i<648)
   {gotoxy(1,row);
    for(col=0;col<72;col++)
      {delay(1);
       printf("%c",type[i]);
       i++;
      }
    row=row+2;
   }
 window(20,22,60,22);
 textbackground(GREEN);
 textcolor(WHITE);
 clrscr();
 printf("   Enter to begin   Esc  to back");
 for(dohf=5;dohf<=21;dohf=dohf+2)
   {window(5,dohf,76,dohf);
    textbackground(CYAN);
    clrscr();
   }
 return(1);
}


void check(int num)
{int ttt,wx,wy,hang,lie;
 int y=5,col,i=0;
 float correct=0;
 double minute=0,dtime,sec;
 time_t first,second;
 window(6,25,20,25);
 printf("00:00");
 window(65,25,80,25);
 printf("0/648");
 window(5,y,76,y);
 ch=getch();
 while(1)
 {if(ch==13)break;
  else if(ch==27)menu();
       else ch=getch();
 }
 first=time(NULL);
 while(i<647)
   {
    window(5,y,76,y);
    for(col=0;col<72;col++)
      {ch=getch();
       if(ch==27)menu();
       if(ch==type[i])
	 {printf("%c",ch);
	  correct++;
	 }
       else
	 {hang=(i/72+1)*2+3;
	 lie=i%72+5;
	  window(lie,hang,lie,hang);
	  textbackground(BLACK);
	  textcolor(RED);
	  clrscr();
	  printf("%c",ch);
	  printf("\a");
	 }

       i++;
       /*hang=(i/72+1)*2+3;
       lie=i%72+5;*/
       wx=i%72+1;wy=1;
       window(65,25,80,25);
       printf("%5d/648",i);
       window(6,25,20,25);
       second=time(NULL);
       sec=difftime(second,first+minute*60);
       if(sec>60)
	 {minute=minute+1;
	  sec=sec-60;
	 }
       if(sec<10)printf("0%1.0f:0%1.0f",minute,sec);
       else printf("0%1.0f:%2.0f",minute,sec);
       window(5,y,76,y);
       gotoxy(wx,wy);

      }
    y=y+2;
   }
 dtime=difftime(second,first);
 stats(correct,dtime,num);
}


/************************************************************************/
void ui(int num)
{char _char;
 int  count;
 window(1,1,80,25);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 gotoxy(1,2);
 printf("%c",201);
 hline(2,79,2,2);
 printf("%c",187);
 vline(3,24,1,2);
 vline(3,24,80,2);
 gotoxy(1,25);
 printf("%c",200);
 hline(2,79,25,2);
 printf("%c",188);

 gotoxy(2,2);

 _char=3;
 for(count=1;count<24;count++)printf("%c",_char);
 printf("  Produced by Du Hongfei!  ");
 for(count=52;count<80;count++)printf("%c",_char);
 gotoxy(20,25);
 _char=1;
 for(count=1;count<12;count++)printf("%c",_char);
 printf(" Produced by dohf ");
 for(count=47;count<60;count++)printf("%c",_char);

 window(3,11,3,11);
 textcolor(141);
 clrscr();
 printf("%c",6);
 window(78,11,78,11);
 textcolor(141);
 clrscr();
 printf("%c",6);
 window(3,12,3,12);
 textcolor(141);
 clrscr();
 printf("%c",3);
 window(78,12,78,12);
 textcolor(141);
 clrscr();
 printf("%c",3);
 window(3,13,3,13);
 textcolor(141);
 clrscr();
 printf("%c",5);
 window(78,13,78,18);
 textcolor(141);
 clrscr();
 printf("%c",5);
 window(3,14,3,14);
 textcolor(141);
 clrscr();
 printf("%c",4);
 window(78,14,78,14);
 textcolor(141);
 clrscr();
 printf("%c",6);

 window(1,25,20,25);
 textbackground(GREEN);
 textcolor(WHITE);
 clrscr();

 window(60,25,80,25);
 textbackground(GREEN);
 clrscr();

 window(5,4,76,22);
 textbackground(7);
 textcolor(BLUE);
 clrscr();
 getsource(num);
 check(num);
}

 /**************************************************************************/

void main()
{menu();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -