游戏说明:计算机会在屏幕上将一串数字显示很短的时间。玩家必须在数字消失之前记住他们,然后输入这串数字。每次过关后,计算机会显示更长的一串数字,让玩家继续玩下去。玩家应尽可能使这个过程重复更多的次数。

#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
int main(void){char another_game = 'Y';        //Records if another game is to be playedconst unsigned int DELAY = 1;  //Display period in secondsbool 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 score = 0;unsigned int total_digits = 0;unsigned int game_time = 0;//how to play the gameprintf("To play Simple Simon,""watch the screen for a sequence of digits.");printf("\nWatch carefully,as the digits are only displayed""for %u second%s ",DELAY,DELAY>1?"s!":"!");printf("\nThe computer will remove them,and then prompt you""to enter the same sequence.");printf("\nWhen you do,you must put spaces between the digits.\n");printf("\nGood Luck!\nPress Enter to play\n");scanf("%c",&another_game);do{//Initialize gamecorrect = true; tries = 0;digits = 2;start_time = clock();//Inner loop continues as long as sequences are entered correctlywhile(correct){++tries;wait_start = clock();//Generate a sequence of digits and display themsrand(time(&seed));for(unsigned int i=1;i<=digits;++i){printf("%u ",rand() % 10);}/*Code to wait one second*/for(;clock() - wait_start < DELAY*CLOCKS_PER_SEC;);/*Code to overwrite the digit sequence*/printf("\r");       //Go to beginning of the linefor(unsigned int i=1;i<=digits;++i)printf("  ");   //Output spaces to cover the number that already printfif(tries == 1)printf("\nNow you enter the sequence - don't forget""the spaces\n");elseprintf("\r");/*Code to prompt for the input sequence*/srand(seed);for(unsigned int i=1;i<=digits;++i){//Read the input sequence & check against the originalscanf("%u",&number);//read a digitif(number != rand()%10){//compare with generater digitcorrect = false;break;}} /*on every third successful try,increase the sequence length*/if(correct && ((tries%3)==0))++digits;printf("%s\n",correct?"Correct!" : "Wrong!");}/*output the score when the game is finished*/score = 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)score += 10*(game_time - total_digits);printf("\n\nGame time was %u seconds.your score is %u",game_time,score);fflush(stdin);printf("\nDo you want play again ?");scanf("%c",&another_game); }while(toupper(another_game)=='Y');return 0;
} 

C语言-简单的Simon游戏相关推荐

  1. C语言简单实现打字游戏,小霸王其乐无穷!

    很多刚开始学习编程的同学都希望自己可以去开发一些游戏,当学习了c语言的时候却发现总是用c语言去解决一些数学问题,今天我就分享给大家一个我学习c语言时候学到的一些好玩的东西,希望可以帮助大家保持对编程的 ...

  2. C语言---简单五子棋小游戏

    效果图如下: 设计思路: 棋盘设计为15×15格,初始状态光标在棋盘的中央,白棋先走,轮流落子,当一方连成五子或下满棋盘时,游戏结束(连成五子的一方获胜,下满棋盘为和棋).当游戏一方胜利后显示胜利信息 ...

  3. c语言简单射击小游戏源程序,简单的迷宫小游戏 C语言程序源代码

    #include #include #include #include #define Height 31 //迷宫的高度,必须为奇数 #define Width 25 //迷宫的宽度,必须为奇数 # ...

  4. 简单五子棋游戏c语言简单,C语言制作简单的五子棋游戏

    原标题:C语言制作简单的五子棋游戏 C语言制作简单的五子棋游戏 学习C语言的人很多,但是用C语言很少,而用来为自己所用,来做游戏的人就更少了,很多人都是跟着学校学习,学校讲到哪就坐到哪,但是以后却还是 ...

  5. C语言设计的简单2048小游戏

    //***************************************************************************// //****************** ...

  6. c语言写一个简单的小游戏-推箱子

    在学习C语言之后,写了一个简单的小游戏来锻炼自己的代码以及C语言知识的掌握能力. 推箱子作为手机上最常见的简单游戏,其代码也相对简单,想法也比较简单,下面为其代码和运行图. /************ ...

  7. C语言简单的键盘玩扫雷小游戏(完结)

    1:这次我们会将前面的代码进行整合,和整理,最终使我们的程序可以有效的运行起来. [1]初始化函数. void GameInit() {     //随机数种子     srand((unsigned ...

  8. C语言——简单的飞机小游戏

    目录 前言 一.先看代码 二.代码解析 1.飞机图案的打印 2.控制飞机移动 getch() 函数 kbhit() 函数 3.发射激光 4.打击靶子 总结 前言 代码参考了<C语言课程设计与游戏 ...

  9. 超级详细的注释C语言简单实现童年小游戏:贪吃蛇

    引言: 记得小时候还没有现在超级高端的智能手机,当时的诺基亚类型的老人机是我的最爱,而里面的贪吃蛇小游戏我总是能玩很久,所以今天就用C语言简单实现一下贪吃蛇这一个小游戏吧. 一. 准备工作: 1.VS ...

  10. 用python做C语言的猜数字游戏,[Python3 练习] 007 简单的猜数字小游戏

    题目:简单的猜数字小游戏 (1) 描述 程序随机生成一个数字,玩家用键盘输入所猜数字,在规定次数内猜对为胜. (2) 要求 程序随机生成一个 1 到 100 的自然数 有 7 次机会去猜 机会用尽之前 ...

最新文章

  1. iOS私有Api检测
  2. 一生中需要的10种人脉
  3. qt同时两个动画执行_Qt实现数字滚动动画效果
  4. FPGA之道(46)数字电路中的隐患
  5. 【Oracle】表空间相关集合
  6. 软件开发管理的十大工作任务(FROM 栾跃)
  7. 设计模式--装饰者模式
  8. Common Attention Points
  9. 【前端】.easyUI.c#
  10. 添加功能---jsp,servlet
  11. rtt面向对象oopc——4.IO设备管理之父类调用子类方法
  12. MusicXML文档翻译(持续更新)
  13. 大学生数学竞赛资料目录20190403更新
  14. C语言中文网教程导航
  15. var foo = function(){} 和 function foo(){}
  16. 国庆 -- 2. 拍婚纱照
  17. tlc5620输出三角波流程图_单片机实践A/D和D/A转换的程序
  18. XCon 2022 | 赛宁主动防御体系惊喜登场
  19. android和java 通过UDP搜索同一局域网内指定网络设备
  20. VS Code 这么牛,再次印证了一句名言

热门文章

  1. cistern java,basin是什么意思_basin怎么读_basin翻译_用法_发音_词组_同反义词_盆-新东方在线英语词典...
  2. OTA分类 OTA升级方式(乒乓、压缩、差分)
  3. PETA 数据集下载
  4. Learning Center Probability Map for Detecting Objects in Aerial Images 论文学习笔记
  5. Simultaneous accesses to 0x1c5a674c8, but modification requires exclusive access.
  6. 谈谈对springboot的理解
  7. 腾讯视频没有了html分享代码,腾讯视频代码在哪里 腾讯视频嵌入网页的方法-电脑教程...
  8. c语言中min函数的作用,min函数到底在哪个头文件里?
  9. npm install 提示 path .../node_modules/node-sass command failed
  10. be [prove] a great boon to [for]