【c++】打字练习
【代码】【c++】打字练习。
·
代码:
#include<iostream>
#include<windows.h>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
string J1=" QWERTYUIOP",J2=" ASDFGHJKL",J3=" ZXCVBNM",J0="0123456789";
string chall="#includeiostream\nUsinGNAmEspaCeSTd\nINtMAIN()",small="\n1 2 3 4 5 6 7 8 9 0\nq w e r t y u i o p\n a s d f g h j k l\n z x c v b n m\n";
string big="\n! @ # $ % ^ & * ( )\nQ W E R T Y U I O P\n A S D F G H J K L\n Z X C V B N M\n";
int cnt1,cnt2;int hh[3]{0,17,35};
int l1,l2,l3,l0;
bool flag;
void gotoxy(int x, int y){
HANDLE hout;COORD coord={x,y};
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
}
void color(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
char library(char c){
switch(c){
case '1':return '!';
case '2':return '@';
case '3':return '#';
case '4':return '$';
case '5':return '%';
case '6':return '^';
case '7':return '&';
case '8':return '*';
case '9':return '(';
case '0':return ')';
default :break;
}
}
void solve(string J,int start,int l,int h,int left){
int cb,cz;
for(int i=start;i<=l;i++){
if(KEY_DOWN(J[i])){
char cc;cc=J[i];
int to=(J[i]=='0')?18:i*2-left;
if(!flag&&cc>'9')cc=cc-'A'+'a';
if(flag&&cc<='9')cc=library(cc);
if(chall[cnt1+hh[cnt2]]==cc)cb=2;
else cb=4;
color(cb,0);printf("%c",cc),cnt1++,
gotoxy(to,h),color(0,cb),
printf("%c",cc),gotoxy(cnt1,0),
gotoxy(cnt1-1,5+cnt2),color(7,cb),printf("%c",chall[cnt1+hh[cnt2]-1]),
Sleep(100),gotoxy(to,h),color(7,0),
printf("%c",cc),gotoxy(cnt1,0);
gotoxy(cnt1,0);while(KEY_DOWN(J[i]));
if(chall[cnt1+hh[cnt2]]=='\n')cnt1=0,gotoxy(0,0),printf(" "),gotoxy(0,0),cnt2++;
}
}
}
int main(){
l1=J1.length()-1,l2=J2.length()-1,l3=J3.length()-1,l0=J0.length()-1;
cout<<small;cout<<chall;gotoxy(0,0);
while(true){
solve(J0,0,l0,1,2);solve(J1,1,l1,2,2);
solve(J2,1,l2,3,1);solve(J3,1,l3,4,0);
if(KEY_DOWN(0x10))
if(!flag)gotoxy(0,0),cout<<big,gotoxy(cnt1,0),flag=true;
if(!KEY_DOWN(0x10))
if(flag)gotoxy(0,0),cout<<small,gotoxy(cnt1,0),flag=false;
}
return 0;
}
更多推荐
已为社区贡献2条内容
所有评论(0)