| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 491 人关注过本帖
标题:c代码记忆猜谜游戏哪里错了
只看楼主 加入收藏
a1611025546
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-8-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
c代码记忆猜谜游戏哪里错了
#include<stdio.h>
#include<ctype.h>
#include<stdbool.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
    char another_game='Y';
    const unsigned int DELAY=1;
    bool correct=true;
    unsigned int tries=0;
    unsigned int digits=0;
    time_t seed=0;
    unsigned int number=0;
    time_t wait_start=0;
    clock_t start_time=0;
    unsigned int sorce=0;
    unsigned int total_digits=0;
    unsigned int game_time=0;
    printf("\n To play Simple Simon,");
    printf("watch the screen for a sequence of digits.");
    printf("\n The computer will remove them ,and then prompt you ");
    printf("enter the same sequence");
    printf("\nn When you dou,you must put spaces between the digits.\n");
    printf( "\n good luck, press enter to play\n");
    scanf("%c",&another_game);
    do
    {
        correct=true;
        tries=0;
        digits=2;
        start_time=clock();
        while(correct )
        {
            ++tries;
            wait_start=clock();
            srand(time(&seed));
            for(unsigned int i=1;i<=digits;++i)
                printf("%u",rand()%10);
            for(;clock()-wait_start<DELAY*CLOCKS_PER_SEC;);
            printf("\r");
            for(unsigned int i=1;i<=digits;++i)
                printf(" ");
            if(tries==1)
                printf("\n Now you enter the squence- don't forget""the space \n");
            else
                printf("\r");
             srand(seed);
            for(unsigned int i=1;i<=digits;++i)
            {
                scanf("%u",&number);
                if ( number != rand()%10)
                {
                    correct=false;
                     break;
                }
            }
            if(correct&&((tries%3)==0))
                ++digits;
            printf("%s \n",correct ? "correct!":"wrong!");
        }
        sorce=10*(digits-((tries%3)==1));
        total_digits=digits*(((tries%3)==0)?3:tries%3);
        if(digits>2)
            total_digits+=3*((digits-1)*(digits-2)/2-1);
        game_time=(clock()-start_time)/CLOCKS_PER_SEC-tries*DELAY;
        if(total_digits>game_time)
        sorce+=10*(game_time-total_digits);
        printf("\n\n Game time was %useconds.Your score is %u.",game_time,sorce);
        fflush(stdin);
        printf("\n Do you want to play again(y/n):");
        scanf("%c",&another_game);
    }while (toupper(another_game)=='Y');
    return 0;
}
搜索更多相关主题的帖子: correct 猜谜游戏 include number 
2015-08-01 17:19
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:10 
什么是记忆猜谜游戏?

一片落叶掉进了回忆的流年。
2015-08-01 18:45
冷曦。
Rank: 2
来 自:苏州
等 级:论坛游民
帖 子:20
专家分:22
注 册:2015-7-27
收藏
得分:10 
同问+1

毋伤他人、尽尔所欲~
2015-08-01 21:36
快速回复:c代码记忆猜谜游戏哪里错了
数据加载中...
 
   



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

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