打字小游戏

乖乖咙嘀咚 2018-02-04 07:48:30
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
int GeZi=0;
int Num1=0;
int Num2=0;
int Num3=0;
int Num4=0;
double V=0;        //打字速度
int Index=0;
int Key=1;        //判断第几次按下
int Score=0;        //分数
int T=0;        //正确次数
int Error=0;
int CountZiShu=0;    //正确的字数
double TimeTemp=0;   
double totaltime=0;
int NanDu=1000;        //屏幕刷新时间,







void KongGe(int num);
void Game(){
    Index=0;
    while(1){
        Index++;
        KongGe(GeZi);
        printf("%c %c %c %c ",'A'+Num1,'A'+Num2,'A'+Num3,'A'+Num4);
        Sleep(NanDu);
        totaltime+=NanDu;
        printf("\b\b\b\b\b\b\b\b         \n");
        if(Index>24){
            Score--;
            Error++;
            Index=0;
            printf("Error!!!");
            Sleep(500);
            Key=1;
            totaltime+=500;
            break;
        }

/*--------------------------------------------------*/
/*--------------------------------------------------*/
/*--------------------------------------------------*/
        if(Key==1){                    //判断第一个字母是否正确,
            if(kbhit()){
                int c=getch();
                if(c=='A'+Num1){
                    CountZiShu++;
                    Key++;
                }
                else{
                    Key=1;
                    Score--;
                    Error++;
                    printf("ERROR1!!!");
                    Sleep(500);
                    totaltime+=500;
                    break;
                }
            }
        }

        if(Key==2){                //判断第二个字母是否正确,
            if(kbhit()){
                int c=getch();
                if(c=='A'+Num2){
                    CountZiShu++;
                    Key++;   
                }
                else{
                    Key=1;
                    Score--;
                    Error++;
                    printf("ERROR2!!!");
                    Sleep(500);
                    totaltime+=500;
                    break;
                }
            }
        }

        if(Key==3){                //判断第三个字母是否正确
            if(kbhit()){
                int c=getch();
                if(c=='A'+Num3){
                    CountZiShu++;
                    Key++;
                }
                else{
                    Key=1;
                    Score--;
                    Error++;
                    printf("ERROR3!!!");
                    Sleep(500);
                    totaltime+=500;
                    break;
                }
            }
        }

        if(Key==4){                    //判断第四个字母是否正确
            if(kbhit()){
                int c=getch();
                if(c=='A'+Num4){
                    CountZiShu++;
                    Key=1;
                    T++;
                    Score++;
                    break;
                }
                else{
                    Key=1;
                    Score--;
                    Error++;
                    printf("ERROR4!!!");
                    Sleep(500);
                    totaltime+=500;
                    break;
                }
            }
        }

        TimeTemp=60/(totaltime/1000);
        V=CountZiShu*TimeTemp;
        if(totaltime>=60000){            
            totaltime=0;        //时间大于六十秒重新计算
            CountZiShu=0;
        }

/*---------------------------------------------------*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/

    }
}

void KongGe(int num){            //打印空格,用于字母下落随机位置
    int i;
    for(i=0;i<num;i++){
        printf(" ");
    }
}







void DaYin(int num){
    int i;
    for(i=0;i<num;i++){
        printf("-");
    }
    printf("\n");
}





int main(){
    printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tWelcome to Game DaZi");
    printf("\n\n\t\t\t\t\t\tAuthor:GGLDD\n");
    printf("\n\t\t\t\t\t\tPlease enter anykey to continue");
    getch();
    system("cls");   
    printf("\n\n\n\t\t\t\t\t\tPlease input a number(NanDu):");
    scanf("%d",&NanDu);
    struct tm* sysTime;
    time_t nowTime;
    while(1){
        GeZi=rand()%110;
        Num1=rand()%26;            //获取随机字母
        Num2=rand()%26;
        Num3=rand()%26;
        Num4=rand()%26;
        time(&nowTime);
        sysTime=localtime(&nowTime);
        system("cls");
        DaYin(120);
        printf("SCORE:%d\tT:%d\tERROR:%d\t\tTime:%d-%d-%d\tNanDu:%d\tSPEED:%f Word/MIN\n",Score,T,Error,sysTime->tm_hour,sysTime->tm_min,sysTime->tm_sec,NanDu,V);
        DaYin(120);
        Game();
        if(Score<=-10){               
            Score=0;
            Error=0;
        }
        if(Score==100){
            printf("\t\tYOU WIN!!!");    //分数达到100
            Sleep(3000);
            break;
        }


    }
}


大家有用c写的小游戏吗,分享下源码大家有用c写的小游戏吗,分享下源码
...全文
793 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ooolinux 2018-02-04
  • 打赏
  • 举报
回复
楼主如果想用C玩玩图形、小游戏编程,可以了解一下EasyX,EasyX是Windows平台最简单的绘图函数库(名副其实),兼容BC和TC的绘图函数,在VC下用EasyX来编程跟在TC下编程绘图差不多是完全一样的。EasyX既可以绘图,也支持图像显示和处理。 下载一个EasyX包,里面有完整的函数手册EasyX_Help.chm,有示例。EasyX官网有很多网友上传的实例,包括游戏。 仅供参考: 用绘图语句画机器猫(初学C语言的同学必看) http://blog.163.com/tab_98/blog/static/1192409720150316223680/

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧