您的位置:首页 > 编程语言 > PHP开发

概论2--简单打字游戏

2010-01-30 20:54 288 查看
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
 
int count=0;                  //打字个数              
char Date[128],Time[128];     //设定的日期和时间
char OSDate[128],OSTime[128]; //系统当前日期和时间
void CurrentTime();           //获取当前系统时间
void SetTime();               //用户设置练习时间
void TimeOut();               //时间到
void setCursorPos(int x,int y);//设置光标位置
void Start();
void End();
 
int main()
{
         char CharLib;
         int line,row; //光标位置
         char ch;  //接收用户输入
 
         Start();
         CurrentTime();
         SetTime();
 
         do
         {
                   system("cls");
                   _strtime( OSTime );
                   _strdate( OSDate );
                   if ((strcmp(Date,OSDate)==0)&&(strcmp(Time,OSTime)==0))
                   {
                            TimeOut();
                            break;
                   }
 
                   else
                   {
 
                            //随机产生的字符
                            srand(time(NULL));
                            CharLib = rand()%26+97;
                           
                            //随机的位置
                            line=0;
                            row = rand()%80;
                           
                            do
                            {       
                                     if(line>0)
                                     {
                                               setCursorPos(row,line - 1);
                                               putchar(' ');
                                     }
                                    
                                     setCursorPos(row,line);          
                                     printf("%c",CharLib);          
                                     Sleep(300); //移动速度
                                     line++;
                                     while(_kbhit())
                                     {
                                               ch = _getch();
                                     }
                                    
                                     if (ch == CharLib)
                                     {
                                               count++;
                                               break;
                                     }      
                            }while(ch != VK_ESCAPE);        
                   }//else
                  
         } while (1);
 
         End();
         putchar('/n');
         system("pause");
 
         return 0;
}
 
void Start()
{
         printf("欢迎使用打字练习程序!");
}
void End()
{
         printf("感谢您的使用!/n");
}
void CurrentTime()
{
         _strtime( OSTime );
         _strdate( OSDate );
         printf("现在时间:");
         puts(OSDate);
         puts(OSTime);
}
void SetTime()
{
         printf("请输入您想结束的日期(MM/DD//YY):");
         gets(Date);
         printf("请输入您想结束的时间(HH:MM:SS):");
         gets(Time);
}
void TimeOut()
{
         Beep(500,500);
         printf("时间到!/n");
         printf("您打字的个数为:%d/n",count);
}
void setCursorPos(int x,int y)
{
         COORD pos;
         pos.X = x;
         pos.Y = y;
         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息