| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 717 人关注过本帖
标题:ask for help...
只看楼主 加入收藏
zw521
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-12-27
收藏
 问题点数:0 回复次数:1 
ask for help...
在下刚刚基础C 还几乎什么都没弄清楚呢 但现在急需要作业 希望高手们帮我修改一下下面的代码使之跟简单一些 在下想要一个简单的投掷类或射击类小游戏 越简单越好 如有现成代码能提供一下当然更好 在下大恩不言谢。。。

很紧急 希望大家帮帮忙!~~




#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<conio.h>
#include<time.h>
#include<dos.h>

double hiscore=0;
int fhis=0;

int game(void);
int shownum(void);
int shoot(int,int,int);
void mydelay(void);
void instruct(void);

void main()
{
 int i=0;
 FILE *fp=fopen("score","rb+");
 if(fp==NULL)
   printf("File score open Error!\nThe high score will be reset!\n");
 else if(fread(&hiscore,sizeof(double),1,fp)!=1)
        printf("File score read Error!\nThe high score will be reset!\n");
 textbackground(BLUE);clrscr();
 textcolor(WHITE);
 gotoxy(34,2);printf("SHOOTING  GAME");
 gotoxy(37,12);printf("WELCOME!");
 gotoxy(26,22);printf("zhaowei");
 while(i++<44) mydelay();instruct();
 
 while(i=game());
 if(fhis)
   {
    rewind(fp);        /*!!!!!!*/
    if(fwrite(&hiscore,sizeof(double),1,fp)!=1)
      {
       printf("\n\n\n\t\tFile score write Error!\n\t\tThe high score will not be changed!\n\t\tPress any button to exit.");
       getch();
      }
   }
 fclose(fp);
 exit(0);
}

int game()
{
 char level;
 clrscr();window(21,3,62,23);
 textbackground(RED);clrscr();
 gotoxy(15,1);cprintf("LEVEL  SELECT");
 gotoxy(7,3);cprintf("1 Static target with column");
 gotoxy(7,5);cprintf("2 Static target without column");
 gotoxy(7,7);cprintf("3 Dynamic target with column");
 gotoxy(7,9);cprintf("4 Dynamic target without column");
 gotoxy(7,11);cprintf("5 Demo on a random level");
 gotoxy(7,13);cprintf("6 Exit");
 gotoxy(18,17);cprintf("Begin!");gotoxy(20,16);
 do{
    level=getch();
    switch(level)
    {
     case '1':if(shoot(1,0,0)) return 1;
         break;
     case '2':if(shoot(0,0,0)) return 1;
         break;
     case '3':if(shoot(1,1,0)) return 1;
         break;
     case '4':if(shoot(0,1,0)) return 1;
         break;
     case '5':
              srand((unsigned)time(0));
              if(shoot(rand()%2,rand()%2,1)) return 1;
              break;
     case '6':exit(0);
     default :cprintf("\a");
    }
   }while(level<'1'||level>'6');
 return 0;
}

int shownum()
{
 int t;
 for(t=1;t<40;t+=3)
   {gotoxy(t,21);cprintf("%d",t);}
 return 0;
}

int shoot(int fc,int fm,int fd)/*返回1,再来一次;*/
{
 int b,g,i,j,s=0;char c;time_t start,end;
 clrscr();
 
 if(!fm)
 {
  srand((unsigned)time(0)); g=rand()%40+1;}/*静态*/
  window(1,1,80,25);gotoxy(21,25);
  cprintf("Please input a number between 1~40!");
  window(21,3,62,23);

  start=time(0);
  for(i=0;i<5;i++)
  {
   if(fm) /*动态*/
   {
    srand((unsigned)time(0)); g=rand()%40+1;
   }
   gotoxy(g,1);cprintf("\1");
   if(fc) shownum();
   if(fd)     /*演示*/
   {
    do
     {
      if(g<3||g>48) b=g;
      else
       {
        srand((unsigned)time(0));
        b=rand()%40+1;
       }
     }while(b-g<-5||b-g>5);
   }
   else
   {
    do
    {
     char temp[3];int k=0;
     gotoxy(40,21);
     while(k<3)
      {
       temp[k]=getch();
       if(!isdigit(temp[k])||temp[k]=='\r')
        {
         if(temp[k]=='\r')
          {temp[k]=0;break;}
         else
          {cprintf("\a\b");continue;}
        }
       k++;
      }   
     b=atoi(temp);
     if(b<1||b>40)
     {b=0;cprintf("\a");}
    }while(b<1||b>40);
   }
   for(j=20;j>2;j--)
   {
    int t=0;
    sound(j*50);
    gotoxy(b,j);cprintf("*");   
    while(t++<5)mydelay();
    nosound();clrscr();
    gotoxy(g,1);cprintf("\1");
    if(fc) shownum();
   }
   gotoxy(b,2);cprintf("*");
   if(b==g) {cprintf("\a");s++;};
   clrscr();
  }
  end=time(0);

  window(1,1,80,25);clrscr();
  gotoxy(31,9);cprintf("Hit:%d",s);
  gotoxy(31,10);cprintf("Time elapsed:%f s",difftime(end,start));
  gotoxy(31,11);cprintf("Score:%f",500*s/difftime(end,start));
  if(500*s/difftime(end,start)>hiscore)
    {
     hiscore=500*s/difftime(end,start);
     if(!fd) fhis++;
    }
  gotoxy(31,12);cprintf("High score:%f",hiscore);
  gotoxy(31,16);cprintf("Another try?Yes or No?");
  c=getch();
  if(c=='Y'||c=='y')
  {
   clrscr();
   textbackground(BLUE);
   return 1;
  }
  return 0;
}

void mydelay()
{
 long i=0;
 while(i++<5000000);
}

void instruct()
{
 clrscr();
 gotoxy(35,2);printf("INSTRCTION");
 gotoxy(1,4);printf("  This is a simple shooting game.\n\n  When playing you just need input a number (1~40) and then press ENTER.A bullet\n('*') will go upward from the bottom at the place whose x coordinate is the num-\nber you input.If your input matches the x coordinate of the goal,you'll hear a \n\nring,and you'll get 20 score.You can only input 5 times.\n\n  There are 4 levels for you to select in the beginning.In Level 1 and Level 2,\n\nthe goal stays in one place,Level 1 with clue.In Level 3 and Level 4,the goal\n\nmoves each time after you input,Level 3 with clue.\n\n\n  Press any button to continue.");
 getch();clrscr();
}
搜索更多相关主题的帖子: int ask include help void 
2007-12-27 13:09
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
看起来,这个程序已很简单的一小游戏了.

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-12-27 13:41
快速回复:ask for help...
数据加载中...
 
   



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

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