C语言-打字系统源码

//C语言-打字系统源码https://wy.guahao.com/expert/38505d5c-f809-4609-91ac-b787229b7bc4000

#include

#include

#include

 

int life=100;//失败的次数

int sleep=150;//字符掉下来的速度

char* arr[]={"Q W E R T Y U I O P [ ] ",

                              "A S D F G H J K L ; ' ",

                               "Z X C V B N M , . / "};

void GamePosition(int x,int y)//定坐标

{

         COORD pos={x,y};//直接赋值给点成员变量

         HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//拿到一张可擦可画的纸

         SetConsoleCursorPosition(hout,pos);

         //设置控制平台光标位置

}

int Play()//开始玩

{

         int x,y,i,j;//x,y是坐标,i,j是数组的行和列

         char ch,cur;//ch是来清空,cur是用来接收输入的按钮字符

         srand((unsigned)time(0));//随机种子 配合rand函数来使用,每次执行结果不一致

         y=7;//因为y轴初始化是6,显示时要从7开始

         i=rand()%3;//从0-2的随机数

         j=rand()%(9-i);//每一行的字母都不一样多

         ch=arr[i][j*4];//???

         x=18+i*2+j*4;//???

         while(y<=24)

         {

                   if(y==24&&ch!=' ')

                            life--;

                   if(life==0)

                            return 0;

                   if(kbhit())//按下键盘

                   {

                            cur=getch();//接收字符

                            if(cur==ch||cur==ch+32)//按下正确

                                     ch=' ';

                            else

                                     life--;

                   }                          

                   if(y>7)

                   {

                            GamePosition(x,y-1);

                            printf(" ");//清除字母的尾巴

                   }

                   GamePosition(x,y);

                   printf("%c",ch);

                   Sleep(sleep);

                   y++;

         }

         return 0;

}

int main()

{

         int i;

         system("cls");//DOS窗口下的清空指令

         GamePosition(18,2);//拿到坐标

         printf("%s\n",arr[0]);

         GamePosition(20,4);

         printf("%s\n",arr[1]);

         GamePosition(22,6);

         printf("%s\n",arr[2]);

         GamePosition(11,25);

         for(i=0;i<60;i++)

                   printf("=");

         while(1)

                   Play();

         return 0;

}

http://www.jiakang021.com

你可能感兴趣的:(C语言-打字系统源码)