| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:来帮帮我呗!谢谢
只看楼主 加入收藏
linxiaomu
Rank: 1
等 级:新手上路
帖 子:14
专家分:6
注 册:2011-7-26
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
来帮帮我呗!谢谢
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void play();
void getguess_num(int);
int getinitlevel();
int getrnd_num(int);

main(){
    char ch;
    clrscr();
    printf("do you want to play this game?(y or n)");
    scanf("%c",&ch);
    switch(ch){
        case 'y':
        case 'Y':
          play();
        break;
    }
    getchar();
    printf("please any key to exit game!");
    getchar();
}

void play(){
  int now_level, rnd_num;
  char play_continue;
  clrscr();
  printf("*****************************************************\n");
  printf("**************wellcome to play this game*************\n");
  printf("**please input choose level you want to play!(1-10)**\n");
  printf("*****************************************************\n");
  now_level = getinitlevel();
  do{
    rnd_num = getrnd_num(now_level);
    printf("\n");
    printf("the level is:%d,you guess_num is between:0 - %d\n",now_level,now_level *10);
    printf("the guess_num is:%d\n",rnd_num);
    getguess_num(rnd_num);
    now_level ++;
    printf("Do you want to continue?(y or n)");
    getchar();
    scanf("%c",&play_continue);
   }while((play_continue == 'y' || play_continue == 'Y') && now_level <= 10);
   printf("------------------------------------------------------------\n");
   printf("-------- Bye-bye  wellcome you next visit ------------------\n");
   printf("------------------------------------------------------------\n");
}

int getinitlevel(){
  int level;
  printf("please input you choose level!(1-10)\n");
  do{
    printf("Init level:");
    scanf("%d",&level);
    if(level < 1 || level > 10){
      printf("the Init levle is error! please choose again!(1-10)\n");
      getchar();
    }
   }while(level < 1 || level > 10);
   return level;
}

int getrnd_num(int now_level){
  int num, rnd_num;
  num = 10 * now_level;
  rnd_num = rand()%num;
  return rnd_num;
}

void getguess_num(int rnd_num){
    int guess_num;
    long begin_time, end_time;
    printf("please input your guess_num:\n");
    begin_time = time(NULL);
    scanf("%d",&guess_num);
    while(guess_num != rnd_num){
        if (guess_num > rnd_num){
          printf("please input a num little than %d\n", guess_num);
        }
        else{
          printf("please input a num bigger than %d\n", guess_num);
        }
        scanf("%d",&guess_num);
    }

     end_time = time(NULL);
     if((end_time - begin_time) <= 120s){
       printf("you use %ds to guess\n",end_time -begin_time);
     }
 }

这是一个猜数游戏 顺利猜对能自己增加难度可以运行,现在我想在这里面加一个功能:比如突然有事关掉了这个界面怎样做才能使下次玩得时候接着玩下去 ?
搜索更多相关主题的帖子: game include please 
2011-08-02 18:02
Magic_Q
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:23
专家分:102
注 册:2011-7-27
收藏
得分:10 
百度一下, ini文件操作.
剩下的,看lz慧根啦...
2011-08-02 19:41
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:10 
把需要用到的数据写在磁盘文件中就行了,下次启动时读回来。

授人以渔,不授人以鱼。
2011-08-02 22:13
快速回复:来帮帮我呗!谢谢
数据加载中...
 
   



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

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