| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1926 人关注过本帖
标题:打字小游戏
只看楼主 加入收藏
niuniul
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:60
注 册:2018-1-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
打字小游戏
熬夜写的小游戏,本来想加个计算每分钟打字速度
的功能,奈何没思路,就这样吧!

#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
char levels='D';        //output level分数
int score=0;            //your score等级
int num=0;
int GeZi=0;            //GeZi代表要打印多少个空格
int index=0;






void KongGe(int num);        //打印空格的函数







void Game(){
   
    index=0;
   
            
            
    while(1){
        
   
   
            
        KongGe(GeZi);
        printf("%c",'a'+num);
        Sleep(80);            //间隔时间,越小越快
        printf("\b \n");
        index++;
   
        if(index>23){            //字母掉到底部
            score-=1;
            break;
        }


        if(kbhit()){
            int c=getch();
            if(c!='a'+num){
                score--;
               
                printf("t\t\t\t\t\tError!!!");//敲错字幕
                Sleep(150);
                break;
            }
            if(c='a'+num){
                score+=1;
               
                break;
            }
            
        }





    }
}





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














void KongGe(int num){
    int i;
    for(i=1;i<num;i++){
        printf(" ");
    }
}






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

int main(){
    printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\tPlease enter anykey to continue");
    printf("\n\t\t\t\t\tAuthor:GGLDD");
    getch();


/*-----------------------------------------------------------------------*/
        system("cls");


        struct tm *sysTime;
        time_t nowTime;
        while(1){
            time(&nowTime);
            sysTime=localtime(&nowTime);
            num=rand()%26;
            GeZi=rand()%110;        
            printf("\t\tlevels:%c\t\tTime%d-%d-%d\t\t\t",levels,sysTime->tm_hour,sysTime->tm_min,sysTime->tm_sec);
            printf("Score:%d\n",score);
            printf("\t\t \t\t\t\t\n");
            Daying(110);
            Game();                                
            system("cls");
            if(score>60&&score<80)
                levels='C';
            if(score>80&&score<90)
                levels='B';
            if(score>90&&score<100)
                levels='A';
            if(score>100)
                levels='S';
            if(score<60&&score>0)
                levels='D';
            if(score<0)
                levels='F';
            
            

        

            

        }

   
        
    return 0;
}

text.c.zip (1.26 KB)
搜索更多相关主题的帖子: 打字 int score num printf 
2018-02-02 13:37
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
收藏
得分:20 
已加上每分钟打字速度

程序代码:
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
char levels = 'D';        //output level分数
int score = 0;            //your score等级
int num = 0;
int GeZi = 0;            //GeZi代表要打印多少个空格
int index = 0;
float totaltime = 0.0001;   //总时间
float totalcount = 0;  //总打正确个数
float V = 0;            //速度

void KongGe(int num);        //打印空格的函数

void Game() {

    index = 0;

    while (1) {

        KongGe(GeZi);
        printf("%c", 'a' + num);
        Sleep(80);            //间隔时间,越小越快
        printf("\b \n");
        index++;
        totaltime += 80;
        if (index>23) {            //字母掉到底部
            score -= 1;
            break;
        }

        if (kbhit()) {
            int c = getch();
            if (c != 'a' + num) {
                score--;

                printf("t\t\t\t\t\tError!!!");//敲错字幕
                Sleep(150);
                totaltime += 150;
            
                break;
            }
            if (c == 'a' + num) {
                score += 1;
                totalcount = totalcount + 1;

                break;
            }

        }
        
        V = ((totalcount) / (totaltime / 1000)) * 60;
    }
}

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


void KongGe(int num) {
    int i;
    for (i = 1; i<num; i++) {
        printf(" ");
    }
}


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

int main() {
    printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\tPlease enter anykey to continue");
    printf("\n\t\t\t\t\tAuthor:GGLDD");
    getch();

    /*-----------------------------------------------------------------------*/
    system("cls");

    struct tm *sysTime;
    time_t nowTime;
    while (1) {
        time(&nowTime);
        sysTime = localtime(&nowTime);
        num = rand() % 26;
        GeZi = rand() % 110;
        printf("\t\tlevels:%c\t\tTime%d-%d-%d\t\t\t", levels, sysTime->tm_hour, sysTime->tm_min, sysTime->tm_sec);
        printf("Score:%d", score);
        printf("\t\tV:%f", V);
        printf(" \t\t\t\t\n");
        Daying(110);
        Game();
        system("cls");
        
        if (score>60 && score<80)
            levels = 'C';
        if (score>80 && score<90)
            levels = 'B';
        if (score>90 && score<100)
            levels = 'A';
        if (score>100)
            levels = 'S';
        if (score<60 && score>0)
            levels = 'D';
        if (score<0)
            levels = 'F';

    }

    return 0;
}

早知做人那么辛苦!  当初不应该下凡
2018-02-02 14:48
niuniul
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:60
注 册:2018-1-13
收藏
得分:0 
重新写了一遍,换成4个字母的
程序代码:
#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;
        }


    }
}

不见满街漂亮妹,哪个归得程序员?
2018-02-04 15:26
浮笔
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-2-9
收藏
得分:0 
请问为什么有些字掉的快有些字掉得慢啊~~是哪个地方完成这个功能的
2018-02-09 12:24
快速回复:打字小游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024833 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved