| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 925 人关注过本帖
标题:神呐!救救我吧!!!明天就答辩了,谁能帮帮我啊。
只看楼主 加入收藏
lhysun
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-1-10
收藏
 问题点数:0 回复次数:0 
神呐!救救我吧!!!明天就答辩了,谁能帮帮我啊。
我的雪花程序运行后有个子菜单,第一项是汉诺塔但是是假的,不能运行。
于是我又找了一个真的汉诺塔程序,可是我不会把它们合并成一个程序,各位大哥谁能帮我一下啊,使第一个雪花程序的子菜单汉诺塔程序变成真的----既第2个程序
谢谢啦,我真的好急,明天就交了,怎么办。拜托!!!!!!!!!!
祝新年快乐!!!!!!!!

雪花程序:
/*3. ?′3ìDò*/
/***dsdemo.c?Yê??μí3***/
#include<stdlib.h>
#include<graphics.h>
#define ESC 0x011b
#define ENTER 0x1c0d
#define DOWN 0x5000
#define UP 0x4800
struct Snow/*??μ?ò"D?2?êy*/
{
   int x;
   int y;
   int speed;/*??"¨μ??ùè*/
}snow[100];
struct Star/*D?D?μ?ò"D?2?êy*/
{
   int x;
   int y;
   int color;
}star[200];
int key;/*°′?ü±?á?*/
int keyx,keyy;/*?????üμ?×?±ê*/
int snownum=0;/*??μ???êy*/
int size;/*±£′???óòμ?′óD?*/
int change=10;/*±???é"óD1?*/
void *save1,*save2;/*±£′?????*/
void Copy(void);/*±£′???óò*/
void DrawSnow(void);/*??ì?êμ??*/
void Pr(void);/*ê?3?×?ì?*/
void Choose(void);/*?????Yê??úèY*/
void DrawStar(void);/*×?oóμ?D?D?D§1?*/
void DrawBall(int x,int y,int color);/*"-????μ??òì?*/
void Init(void);/*í?D??yˉ*/
void Close(void);/*í?D?1?±?*/
void main(void)
{
   Init();
   Copy();
   DrawSnow();/*??"¨??ˉ*/
   Choose();/*?????Yê??úèY*/
   DrawStar();/*?áê?"-??*/
   Close();
   exit(0);
}
void Init(void)
{
   int gd=DETECT,gm;
   initgraph(&gd,&gm,"c:\\tc");
   cleardevice();
}
void Close(void)/*í?D?1?±?*/
{
   getch();
   closegraph();
}
void Copy(void)/*±£′???óò*/
{
   setcolor(0);
   setfillstyle(SOLID_FILL,15);
   fillellipse(200,200,4,4);
   size=imagesize(196,196,204,204);/*¨ò?±£′?í??ó??óò′óD?*/
   save1=malloc(size);/*éê??????*/
   save2=malloc(size);
   getimage(196,196,204,204,save1);/*±£′???"¨*/
   getimage(96,96,104,104,save2); /*±£′?±3?°oúé"*/
}
void Pr(void)/*?ú???Dê?3???×?*/
{
   settextstyle(0,0,1);
   if(change>=20&&change<=30||change>=50&&change<=60||
     change>=100&&change<=110)/*éá??D§1?*/
      setcolor(YELLOW);
   else
      setcolor(BLACK);
   outtextxy(250,250,"anykey to continue");
   setcolor(change/10);/*±?""??é"??ê?±êìa*/
   settextstyle(0,0,3);
   outtextxy(100,200,"Data Structure Demo");/*±êìa*/
}
/*??ê???"¨μ???ì?1y3ì*/
void DrawSnow(void)
{
   int i;
   int sx[62];
   randomize();
   for(i=0;i<62;i++) /*¨ò???"¨μ?x×?±ê*/
      sx[i]=(i+2)*10;
   cleardevice();
   while(!kbhit())
   {
      Pr();
      if(snownum!=100)/*éú3éD?μ???"¨*/
      {
     snow[snownum].speed=2+random(5);/*?ùè??"ú¨£μ"2"D?óú2*/
     i=random(62);
     snow[snownum].x=sx[i];/*??"úè?x×?±ê*/
     snow[snownum].y=10-random(100);
      }
      for(i=0;i<snownum;i++)/*è¥??*/
     putimage(snow[i].x,snow[i].y,save2,COPY_PUT);
      Pr(); /*??ê?±êìa*/
      if(snownum!=100)
     snownum++;
      setfillstyle(SOLID_FILL,15);/*"-??*/
      for(i=0;i<snownum;i++)
      {
     snow[i].y+=snow[i].speed;
     putimage(snow[i].x,snow[i].y,save1,COPY_PUT);
     if(snow[i].y>500)
        snow[i].y=10-random(200);
      }
      change++;
      if(change==140)/*??é"±?"ˉ*/
     change=10;
   }
}
/*"-????μ??òì?xoíy?a×?±ê£color?a?òμ???é"*/
void DrawBall(int x,int y,int color)
{
   setcolor(0);
   setfillstyle(SOLID_FILL,color);
   fillellipse(x,y+10,10,10);
}
/*?????Yê?oˉêy*/
void Choose(void)
{
   int yes;/*?D?ê?·?í?3?????£12"í?3?0í?3?*/
   int oyes=1;
   while(oyes)
   {
      Init();
      cleardevice();
      yes=1;
      keyx=140;
      keyy=150;
      setcolor(11);
      rectangle(40,40,600,440);/*"-±??ò??/
      setcolor(13);
      settextstyle(0,0,3);/*±êìa′óò"D?*/
      outtextxy(100,70,"Data Structure Demo");
      settextstyle(0,0,2);/*???ü????D?ò"D?*/
      setcolor(RED);
      outtextxy(200,150,"hanoi tower");/*oo?μ?t*/
      setcolor(BLUE);
      outtextxy(200,190,"double link");/*?"á′±í*/
      setcolor(GREEN);
      outtextxy(200,230,"bubble sorting"); /*?e?Y??Dò*/
      setcolor(YELLOW);
      outtextxy(200,270,"radix sorting"); /*"ùêy??Dò*/
      setcolor(10);
      outtextxy(200,310,"binary serach");    /*t·?2é?ò*/
      setcolor(MAGENTA);
      outtextxy(200,350,"binary tree");  /* t2?ê÷±éàú*/
      setcolor(WHITE);
      outtextxy(200,390,"exit");/*?áê?3ìDò*/
      DrawBall(keyx,keyy,11);
      while(yes)
      /*????μ??-"·ì??t*/
      {
     key=bioskey(0);
     if(key==ESC)/*í?3??μí3*/
        break;
     if(key==UP)/*é??ü?ì2ù×÷*/
     {
        DrawBall(keyx,keyy,BLACK);/*?èó?oúé"?ú?-à′?"??è¥3y?ò*/
        if(keyy!=150)
           keyy-=40;
        else
           keyy=390;
        DrawBall(keyx,keyy,11);/*D??"??ê?3??ò*/
     }
     if(key==DOWN)/*???ü?ì2ù×÷*/
     {
        DrawBall(keyx,keyy,BLACK);/*?èó?oúé"?ú?-à′?"??è¥3y?ò*/
        if(keyy!=390)
           keyy+=40;
        else
           keyy=150;
        DrawBall(keyx,keyy,11);/*D??"??ê?3??ò*/
     }
     if(key==ENTER)/*è·¨?ü*/
     {
        switch(keyy)/*?D??úèY*/
        {
           case 150:system("hanoi");yes=0;break;/*μ÷ó?oo?μ?t*/
           case 190:system("dblink");yes=0;break;/*μ÷ó??"á′±í*/
           case 230:system("bubble");yes=0;break;/*μ÷ó??e?Y??Dò*/
           case 270:system("radix");yes=0;break;/*μ÷ó?"ùêy??Dò*/
           case 310:system("binary");yes=0;break;/*μ÷ó?t·?2é?ò*/
           case 350:system("tree2");yes=0;break; /*μ÷ó?t2?ê÷*/
           case 390: yes=0;oyes=0;/*exit????*/
        }/*endswitch*/
     } /*endenter*/
      } /*endwhile*/
   } /*endwhile*/
}
/*?áê?"-??*/
void DrawStar(void)
{
   int i;
   cleardevice();
   setcolor(GREEN);
   settextstyle(0,0,2);
   while(!kbhit())
   {
      for(i=0;i<200;i++)/*??"úéú3éD?D?*/
      {
     star[i].x=random(640);
     star[i].y=random(480);
     star[i].color=random(13)+1;
      }
      for(i=0;i<200;i++)/*ê?3?D?D?*/
      {
     putpixel(star[i].x,star[i].y,star[i].color);
     delay(100);
      }
      outtextxy(100,200,"Thank you for use this system");
      sleep(1);
      for(i=0;i<200;i++)/*è¥3yD?D?*/
      {
     putpixel(star[i].x,star[i].y,0);
     delay(50);
      }
   }
}







/*汉诺塔源程序*/
/********hanoi.c*********/
#include <graphics.h>
struct H
{
   int data[15];/*存放每个盘的代号*/
   int top;/*每个塔的具体高度*/
}num[3];/*三个塔*/
void move(char x,char y,struct H num[3]);/*移动的具体过程*/
void hanoi(char x,char y,char z,int n,struct H num[3]);/*递归*/
void Init(void);/*初始化*/
void Close(void);/*图形关闭*/
int computer=1;/*自动控制与手动控制的标志*/
int speed=0;/*全局变量speed主要是演示过程的速度*/
void main(void)
{
   Init();/*初始状态*/
   Close();/*图形关闭*/
   exit(0);
}
void Init(void)/*初始化*/
{
   int gd=DETECT,gm;
   int i,n,color;
   clrscr();
   printf("please input n(n<=10): ");/*输入要演示的盘子数*/
   scanf("%d",&n);
   printf("Please input 1 or 2:\ 2.people\n");
   scanf("%d",&i);
   if(i==2)/*选择手动控制标志为0*/
      computer=0;
   if(n<1||n>10)
      n=10;/*越界的话n当10处理*/
   if(computer)/*如果是自动控制的话输入速度*/
   {
      printf("please input speed: ");/*输入速度*/
      scanf("%d",&speed);
   }
   initgraph(&gd,&gm,"c:\\tc");
   cleardevice();
   for(i=0;i<3;i++)
      num[i].top=-1;/*三个地方的高度开始都为-1*/
   for(i=0;i<n;i++)/*画一开始的塔座A上的盘子*/
   {
      num[0].top++;/*栈的高度加1*/
      num[0].data[num[0].top]=i; /*最大的盘子代号为0,依次为1,2,…n-1*/
      color=num[0].data[num[0].top]+1;/*盘子的颜色代码为栈顶盘子代号加1*/
      setfillstyle(SOLID_FILL,color);
      bar(100-(33-3*num[0].data[num[0].top]),400-20*i-8,100+
(33-3*num[0].data[num[0].top]),400-20*i+8); /*画矩形*/
   }
   setcolor(YELLOW);
   outtextxy(180,450,"any key to continue");
   settextstyle(0,0,2);
   outtextxy(90,420,"A"); /*塔座标志*/
   outtextxy(240,420,"B");
   outtextxy(390,420,"C");
   getch();/*接收字符后就执行递归操作*/
   hanoi('a','b','c',n,num);
}
void move(char x,char y,struct H num[3])/*移动的具体过程*/
{
   int i;
   char num1[3],num2[3];
   sprintf(num1,"%c",x-32);/*将小写变成大写,并转换成字符串输出*/
   sprintf(num2,"%c",y-32);
   setfillstyle(SOLID_FILL,BLACK);/*把原来的地方移去涂黑*/
   bar(0,0,640,60);
   setcolor(RED);
   outtextxy(150,30,num1);/*输出移动过程*/
   outtextxy(200,30,"--->");
   outtextxy(310,30,num2);
   settextstyle(0,0,2);
   setfillstyle(SOLID_FILL,BLACK);/*把原来的地方移去涂黑*/
   bar(100+150*(x-97)-(33-3*num[x-97].data[num[x-97].top]),
400-20*num[x-97].top-8,100+150*(x-97)+(33-3*
num[x-97].data[num[x-97].top]),400-20*num[x-97].top+8);
   num[y-97].top++;/*入栈,目标点的top加1*/
   num[y-97].data[num[y-97].top]=num[x-97].data[num[x-97].top];/*在目标点盘子的代号与源点盘子的代号相同*/
   num[x-97].top--;/*出栈,原来地方的top减1*/
   setfillstyle(SOLID_FILL,num[y-97].data[num[y-97].top]+1);/*盘子颜色代码是栈顶盘子代号加1*/
   bar(100+150*(y-97)-(33-3*num[y-97].data[num[y-97].top]),
400-20*num[y-97].top-8,100+150*(y-97)+
(33-3*num[y-97].data[num[y-97].top]),400-20*num[y-97].top+8);
   if(computer)/*自动控制就用delay*/
      delay(speed);/*延时函数*/
   else
      getch();/*手动控制的话就自己按键盘来控制*/
}
void hanoi(char one,char two,char three,int n,struct H num[3])/*递归n为盘子数,num为堆栈*/
{
   if(n==1)
      move(one,three,num);/*如果盘子为1,将这个盘子从塔座A移动到塔座C*/
   else
   {
      hanoi(one,three,two,n-1,num);/*将塔座A的前n-1个盘子移到塔座B*/
      move(one,three,num);/*将塔座A的第n个盘子移到塔座C*/
      hanoi(two,one,three,n-1,num); /*将塔座B的n-1个盘子移到塔座C*/
   }
}
void Close(void)/*图形关闭*/
{
   getch();
   closegraph();
}
搜索更多相关主题的帖子: 汉诺塔 新年 define 雪花 
2005-01-10 20:13
快速回复:神呐!救救我吧!!!明天就答辩了,谁能帮帮我啊。
数据加载中...
 
   



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

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