dazi 1.5.0
JudgmentSGF · · 休闲·娱乐
#include<iostream>
#include<iomanip>
#include<windows.h>
#include<conio.h>
#include<ctime>
typedef long long LL;
const LL kkk=12;
struct keys{
LL y;
LL x;
};
keys kb[51]={
/*letters*/
{6,11},{8,29},{8,21},{6,19},{4,18}, // A,B,C,D,E
{6,23},{6,27},{6,31},{4,38},{6,35}, // F,G,H,I,J
{6,39},{6,43},{8,37},{8,33},{4,42}, // K,L,M,N,O
{4,46},{4,10},{4,22},{6,15},{4,26}, // P,Q,R,S,T
{4,34},{8,25},{4,14},{8,17},{4,30}, // U,V,W,X,Y
{8,13}, // Z
/*numbers*/
{2,43},{2,7},{2,11},{2,15},{2,19}, // 0,1,2,3,4
{2,23},{2,27},{2,31},{2,35},{2,39}, // 5,6,7,8,9
/*characters*/
{2,3},{2,47},{2,51},{4,50},{4,54}, // `,-,=,[,]
{4,58},{6,47},{6,51},{8,41},{8,45}, // \,;,',,.
{8,49}, // /
/*others*/
{6,55},{4,4},{2,55},{10,28} // \r,\t,\b,<space>
};
LL color(LL c){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
return 0;
}
void gotoxy(HANDLE hout,LL x,LL y){
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(hout,pos);
}
void printkb(bool need_shift,LL cnt_ac,LL cnt_wa){
if(need_shift){
printf("\
-------------------------------------------------------------\n\
| ~ | ! | @ | # | $ | %% | ^ | & | * | ( | ) | _ | + | <-bks |\n\
-------------------------------------------------------------\n\
| tab | Q | W | E | R | T | Y | U | I | O | P | { | } | | |\n\
-----------------------------------------------------------\n\
| caps | A | S | D | F | G | H | J | K | L | : | \" | entr |\n\
-----------------------------------------------------------\n\
| shift | Z | X | C | V | B | N | M | < | > | ? | shift |\n\
---------------------------------------------------------\n\
| alt | fn | win | alt | space | alt | ctrl | < | ^ | > |\n\
---------------------------------------------------------\n\
\n\
AC:%lld\n\
WA:%lld\n\n",cnt_ac,cnt_wa);
}else{
printf("\
-------------------------------------------------------------\n\
| ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | <-bks |\n\
-------------------------------------------------------------\n\
| tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \\ |\n\
-----------------------------------------------------------\n\
| caps | A | S | D | F | G | H | J | K | L | ; | \' | entr |\n\
-----------------------------------------------------------\n\
| shift | Z | X | C | V | B | N | M | , | . | / | shift |\n\
---------------------------------------------------------\n\
| alt | fn | win | alt | space | alt | ctrl | < | ^ | > |\n\
---------------------------------------------------------\n\
\n\
AC:%lld\n\
WA:%lld\n\n",cnt_ac,cnt_wa);
}
}
char setchar(LL c,bool need_shift){
if(need_shift){
switch(c){
case 26: return ')';
case 27: return '!';
case 28: return '@';
case 29: return '#';
case 30: return '$';
case 31: return '%';
case 32: return '^';
case 33: return '&';
case 34: return '*';
case 35: return '(';
case 36: return '~';
case 37: return '_';
case 38: return '+';
case 39: return '{';
case 40: return '}';
case 41: return '|';
case 42: return ':';
case 43: return '\"';
case 44: return '<';
case 45: return '>';
case 46: return '?';
}
}else{
if(c>=0&&c<=25){return (char)(c+'A');}else
if(c<=35){return c-26+'0';}
switch(c){
case 36: return '`';
case 37: return '-';
case 38: return '=';
case 39: return '[';
case 40: return ']';
case 41: return '\\';
case 42: return ';';
case 43: return '\'';
case 44: return ',';
case 45: return '.';
case 46: return '/';
case 47: return '\r';
case 48: return '\t';
case 49: return '\b';
case 50: return ' ';
}
}
return ' ';
}
void printchar(char c){
if(c=='\r'){printf("entr");}else
if(c=='\t'){printf("tab");}else
if(c=='\b'){printf("<-bks");}else
if(c==' '){printf("space");}else{printf("%c",c);}
}
bool isCapsLockOn(){
return ((GetKeyState(VK_CAPITAL)&0x0001)!=0);
}
void randomTyping(HANDLE hout){
system("cls");
color(7);
printf("Article Typing Practice\n");
printf("=======================\n\n");
printf("Input how many keys you want to hit (0 for unlimited): ");
LL maxpoint;
scanf("%lld",&maxpoint);
getchar();
while(!isCapsLockOn()){
printf("\nERROR: CapsLock must be enabled!\n");
printf("Please enable CapsLock and press Enter to continue...\n\n");
while(getch() != '\r');
}
if(maxpoint>0) printf("Target: %lld keys\n",maxpoint);
else printf("Target: Unlimited\n");
printf("Press Enter to start...");
while(getch()!='\r');
system("cls");
LL cnt_ac=0, cnt_wa=0, hits=0;
DWORD startTime=GetTickCount();
while(maxpoint<=0||cnt_ac<maxpoint){
bool need_shift=rand()%2;
LL key=(need_shift?rand()%20+26:rand()%51);
gotoxy(hout,0,0);
printkb(need_shift,cnt_ac,cnt_wa);
if(need_shift){
color(9);
gotoxy(hout,52,7);
printf("shift");
gotoxy(hout,4,7);
printf("shift");
}
gotoxy(hout,kb[key].x-1,kb[key].y-1);
color(31);
char cc=setchar(key,need_shift);
printchar(cc);
char tc=getch();
color(7);
gotoxy(hout,kb[key].x-1,kb[key].y-1);
printchar(cc);
if(cc==tc){cnt_ac++;}else{cnt_wa++;}
hits++;
}
DWORD endTime=GetTickCount();
double alltime=(endTime-startTime)/1000.0;
system("cls");
printf("Typing Results:\n");
printf("===============\n");
printf("Time used: %.2f seconds\n",alltime);
printf("Accuracy: %.2f%% (%lld/%lld)\n",(cnt_ac*100.0/hits),cnt_ac,hits);
printf("Speed: %.2f chars/min\n\n",hits/alltime*60);
printf("\nPress Enter to try again or Esc to exit...");
while(true){
char c=getch();
if(c=='\r'){
randomTyping(hout);
return;
}
if(c==27) return;
}
}
void articleTyping() {
system("cls");
color(7);
printf("Article Typing Practice\n");
printf("=======================\n\n");
std::pair<const char*,const char*>articles[]={
{"default","The quick brown fox jumps over the lazy dog."}
};
const int articleCount=sizeof(articles)/sizeof(articles[0]);
printf("Select an article (1-%d) or 0 to get custom text: ",articleCount);
LL choice;
scanf("%lld",&choice);
getchar();
std::string text;
/*if(choice==0){
printf("Enter your custom text (press Enter twice to finish):\n");
std::string line;
while(true) {
std::getline(std::cin,line);
if(line.empty())break;
text+=line+"\n";
}
}else*/
if(choice>=1&&choice<=articleCount){text=articles[choice-1].second;}
else{
printf("Invalid choice! Using default article.\n");
text=articles[0].second;
}
system("cls");
printf("Type the following text:\n\n");
printf("%s\n\n",text.c_str());
printf("Press any key to start timing...");
getch();
system("cls");
printf("Type the text (press Enter to finish):\n\n");
printf("%s\n\n",text.c_str());
DWORD startTime=GetTickCount();
std::string input;
char c;
while((c=getch())!='\r'){
putchar(c);
input+=c;
}
DWORD endTime=GetTickCount();
double timeUsed=(endTime-startTime)/1000.0;
LL correct=0,total=text.length();
for(LL i=0;i<std::min(text.length(),input.length());++i) {
if(text[i]==input[i]){correct++;}
}
double accuracy=((total>0)?(correct*100.0/total):0);
double speed=((timeUsed>0)?(correct/timeUsed*60):0); // ??/??
system("cls");
printf("Typing Results:\n");
printf("===============\n");
printf("Time used: %.2f seconds\n",timeUsed);
printf("Accuracy: %.2f%% (%lld/%lld)\n",accuracy,correct,total);
printf("Speed: %.2f chars/min\n\n",speed);
printf("Press Enter to continue...");
while(getch()!='\r');
}
void mainMenu(HANDLE hout) {
while(true) {
system("cls");
color(7);
printf("Type - Version 1.5.0\n");
printf("AUTHOR & COPYRIGHT: JSGF_PhigrosMC\n");
printf("======================\n");
printf("0. Exit\n");
printf("1. Random Keyboard Practice\n");
printf("2. Article Typing Practice\n\n");
printf("Select an option: ");
char choice;
scanf("%c",&choice);
switch(choice) {
case '0': return;
case '1':
randomTyping(hout);
break;
case '2':
articleTyping();
break;
default:
printf("\nInvalid choice! Please try again.");
Sleep(1000);
}
}
}
int main(){
srand(time(0));
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize=1;
cursorInfo.bVisible=FALSE;
SetConsoleCursorInfo(hout,&cursorInfo);
mainMenu(hout);
return 0;
}