CSDN博客

img bolm

汉诺塔经典DOS版TC源码

发表于2004/4/7 21:54:00  1173人阅读

/***********************************************************************
*                            HANOI TOWER V2.0                          *
*                          TURBO C 2.0 COMPILER                        *
*                             SOURCE PROGRAM                           *
*                             MADE BY BOLMAN                           *
*                             chencheng@vip.citiz.net*
***********************************************************************/
#include  "stdio.h"
#include  "conio.h"
#include  "stdlib.h"
#include  "dos.h"
#include  "time.h"
#include  "graphics.h"

#define S   setcolor
#define F   setfillstyle
#define R   rectangle
#define C   circle
#define B   bar
#define B3D bar3d
#define L   line
#define O   outtextxy

#define X 200
#define Y 20


int nStep=0;
int nRecord[7]={7,15,31,63,127,255,511},nRec;
int nDisk,nDisknum;
int nBaseNum;
int nSelectDelay=1; /**USE IN AUTOPLAY**/
float nDelay;
char chMark[15];

struct rod
       {
       int nDisk[10][5];
       int nDiskName[10];
       }tree[3];

/********************************************/
ntoa(int s)
{
 int b[15];
 int i,j;
 for (i=0;i<15;i++)
   chMark[i]='/0';
 for (i=0;s>=10;i++)
   {b[i]=s%10;
   s/=10;}
 b[i]=s;
 for(j=i;j>=0;j--)
   chMark[i-j]=b[j]+'0';
}


void INITIAL()     /**GAME INITIAL**/
{
 int gd=DETECT,gm=0;
 registerbgidriver(EGAVGA_driver);
 initgraph(&gd,&gm,"");
 setbkcolor(0);
}

void Start_Logo()
{
  F(1,8);
  B(200,150,439,329);
  S(7);
  R(201,151,438,328);
  S(WHITE);
  R(199,149,440,330);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  O(233,180,"HANOI TOWER");
  S(1);
  O(232,179,"HANOI TOWER");
  S(WHITE);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  O(284,204,"V 2.0");
  S(1);
  O(283,203,"V 2.0");
  settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  S(WHITE);
  O(236,240,"COPYRIGHT (C) 2002 BY");
  O(236,250,"--LING DONG  STUDIO--");
  S(7);
  O(236,280,"    BOLM@ETANG.COM   ");
}

void END()
{
 char message[110]=">>> IF YOU WANT TO GET THE SOURCE PROGRAM/n/nPLEASE SEND AN E_MAIL TO TELL ME,AND I WILL SEND TO YOU!! ^-^";
 int NUM;
 closegraph();
 sleep(1);
 gotoxy(1,10);
 for(NUM=0;NUM<110;NUM++)
  {printf("%c",message[NUM]);
   delay(500);
   sound(0);delay(50);nosound();}
  sleep(1);
}


void FLASH_REC()
{
 int NUM,x1=8,x2=10;
 randomize();
 for(NUM=0;NUM<33;NUM++)
 {
  F(1,rand()%16);
  B(x1,412,x2,414);
  x1=x1+20;
  x2=x2+20;
 }
}

void DRAW()
{
 F(1,8);
 B(6,80,633,100); /**BROWN BAR**/
 B(6,415,633,430);
 B(6,430,633,479);
 F(1,7);
 B(6,77,633,80);
 B(6,430,633,432);
 F(1,4);
 B(6,100,633,102);
 B(6,410,633,415);
 F(1,7);                 /**GAME BACKGROUND**/
 B(7,102,632,410);
 S(15);
 R(6,0,633,479);
 S(15);
 settextstyle(DEFAULT_FONT,HORIZ_DIR,4);
 O(70,30,"HANOI TOWER V2.0");
 S(9);
 O(71,31,"HANOI TOWER V2.0");

 S(7);            /**SHOW MESSAGE**/
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 O(190,440,"-MADE BY BOLMAN--LINGDONG STUDIO-");
 O(190,450,"-BOLM@ETANG.COM--BOLMAN@SINA.COM-");
 L(165,419,165,425);
 S(12);
 O(170,419,"MESSAGE:"); /**MESSAGE BOX**/
 S(7);
 O(20,419,"PRESS ESC TO QUIT");
 F(1,2);
 B(550,450,560,460);
 F(1,13);
 B(565,450,575,460);
 F(1,YELLOW);
 B(580,450,590,460);
 F(1,12);
 B(595,450,605,460);
}

void DrawRod()
{
 F(1,8);
 B(118,150,122,400);   /*ROD1*/
 B(318,150,322,400);   /*ROD2*/
 B(518,150,522,400);   /*ROD3*/
 F(6,LIGHTBLUE);
 B(119,151,123,401);
 B(319,151,323,401);
 B(519,151,522,401);
}
/*====END OF FUN DRAWROD====*/

void ShowInfo(int nRn,int nWhetherGetDisk)
{
 F(1,8);
 B(230,418,620,428);
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 S(CYAN);
 if(nRn==0&&nWhetherGetDisk==0)
   O(235,419,"YOU NOW AT THE FIRST ROD");
 else if(nRn==1&&nWhetherGetDisk==0)
   O(235,419,"YOU NOW AT THE SECOND ROD");
 else if(nRn==2&&nWhetherGetDisk==0)
   O(235,419,"YOU NOW AT THE THIRD ROD");
 else if(nWhetherGetDisk==1)
   {S(YELLOW);
     switch(nRn)
      {case 0 :O(235,419,"YOU GET THE TOP DISK AT THE FIRST ROD");break;
       case 1 :O(235,419,"YOU GET THE TOP DISK AT THE SECOND ROD");break;
       case 2 :O(235,419,"YOU GET THE TOP DISK AT THE THIRD ROD");break;
       default:break;
      }
   }
  else if(nRn==3&&nWhetherGetDisk==nBaseNum)
     {S(WHITE);O(235,419,"YOU SHOULD DO YOUR BEST");}
  else if(nRn==3&&nWhetherGetDisk==nBaseNum*2)
     O(235,419,"YOU SEEMS PLAY NOT VERY GOOD...^_^");
  else if(nRn==4&&nWhetherGetDisk==0)
     {S(13);O(235,419,"O.K YOU HAVE FINISHED YOUR WORK");sleep(1);}
  else O(235,419,"YOU HAVE GET DOWN THE DISK");
}
/*====END OF FUN SHOWINFO====*/


void ShowRecord()
{
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 F(1,8);
 B(78,82,90,94);
 ntoa(nDisk);
 S(YELLOW);
 O(40,86,"DISK:");
 S(15);
 O(80,86,chMark);

 B(348,82,360,94);
 ntoa(nRec);
 S(YELLOW);
 O(290,86,"RECORD:");
 S(15);
 O(350,86,chMark);

 B(560,82,610,94);
 ntoa(nStep);
 S(YELLOW);
 O(520,86,"STEP:");
 S(15);
 O(562,86,chMark);
}
/*====END OF FUN SHOWRECORD====*/

void FillDisk(int x1,int y1,int x2,int y2,int color,int color1)
{
 S(color);
 F(1,color);
 B3D(x1,y1,x2,y2,5,5);
 F(1,color1);
 B3D(x1+1,y1+1,x2+1,y2+1,5,5);
}

void FadeIn(void)
{
 char R[256],G[256],B[256];
 int nNum,nNotFinish;

 for(nNum=0;nNum<256;nNum++)
 {
  outportb(0x3c7,nNum);
  R[nNum]=inportb(0x3c9);
  G[nNum]=inportb(0x3c9);
  B[nNum]=inportb(0x3c9);
 }
 nNotFinish=1;
 while(nNotFinish==1)
 {
  nNotFinish=0;
  for(nNum=0;nNum<256;nNum++)
  {
   if(R[nNum]!=0)
   {
    nNotFinish=1;
    R[nNum]--;
   }
   if(G[nNum]!=0)
   {
    nNotFinish=1;
    G[nNum]--;
   }
   if(B[nNum]!=0)
   {
    nNotFinish=1;
    B[nNum]--;
   }
   outportb(0x3c8,nNum);
   outportb(0x3c9,R[nNum]);
   outportb(0x3c9,G[nNum]);
   outportb(0x3c9,B[nNum]);
  }
  delay(1000);
 }
}
/*====END OF FUN FADEIN====*/

void FadeOut(void)
{
 char R[256],G[256],B[256];
 char RR[256],GG[256],BB[256];
 int nNum,nNotFinish;

 for(nNum=0;nNum<256;nNum++)
 {
  outportb(0x3c7,nNum);
  R[nNum]=RR[nNum]=inportb(0x3c9);
  G[nNum]=GG[nNum]=inportb(0x3c9);
  B[nNum]=BB[nNum]=inportb(0x3c9);
 }
 for(nNum=0;nNum<256;nNum++)
 {
  R[nNum]=0;
  G[nNum]=0;
  B[nNum]=0;
  outportb(0x3c8,nNum);
  outportb(0x3c9,0);
  outportb(0x3c9,0);
  outportb(0x3c9,0);
 }
 delay(100);
 nNotFinish=1;
 while(nNotFinish==1)
 {
  nNotFinish=0;
  for(nNum=0;nNum<256;nNum++)
  {
   if(R[nNum]!=RR[nNum])
   {
    nNotFinish=1;
    R[nNum]++;
   }
   if(G[nNum]!=GG[nNum])
   {
    nNotFinish=1;
    G[nNum]++;
   }
   if(B[nNum]!=BB[nNum])
   {
    nNotFinish=1;
    B[nNum]++;
   }
   outportb(0x3c8,nNum);
   outportb(0x3c9,R[nNum]);
   outportb(0x3c9,G[nNum]);
   outportb(0x3c9,B[nNum]);
  }
  delay(1500);
 }
}
/*====END OF FUN FADEOUT====*/

void ClrScreen(void)
{
 int NUM;
 F(11,9);
 for (NUM=84;NUM<476;NUM++)
 { B(7,NUM,632,NUM+2);
   delay(20);
 }
}

int Ball(int nRn)
{
 F(1,7);
       B(20,105,609,130);
       F(1,RED);
       S(RED);
       C(118+(nRn*200),115,10);
       floodfill(118+(nRn*200),115, RED);
}

void Quit()
{
 ClrScreen();
 settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
 S(WHITE);
 O(180,210,"THANK YOU TO PLAY");
 O(180,230,"      2002.7     ");
 S(RED);
 O(181,211,"THANK YOU TO PLAY");
 O(181,231,"      2002.7     ");
 O(181,260," ANY KEY TO QUIT ");
 S(GREEN);
 O(180,180,"G A M E   O V E R");
 S(15);
 O(181,181,"G A M E   O V E R");
 getch();
 FadeIn();
 closegraph();
 END();
 exit(0);
}
/*====END OF FUN QUIT====*/

int IsWin()
{
  int i,nStep_Sub_Rec;
  int nDiskNum=0;
  for (i=0;i<nDisk;i++)
   { if(tree[2].nDisk[i][0]==1) nDiskNum++;}
  nStep_Sub_Rec=nStep-nRec;
  if (nDiskNum==nDisk)
    { ShowInfo(4,0);             /**IT CAN BE SET AS YOUR WAY**/
     nBaseNum=nRec/9;
     if (nStep_Sub_Rec<=nBaseNum) /**WIN**/
       { ClrScreen();
  S(GREEN);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
  O(230,200,"YOU WIN");
  S(RED);
  O(231,201,"YOU WIN"); }
      else if (nStep_Sub_Rec<=nBaseNum*2)
       { ClrScreen();
  S(RED);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
  O(220,200,"JUST SOSO");
  S(LIGHTBLUE);
  O(221,201,"JUST SOSO"); }
       else
       { ClrScreen();
  S(LIGHTBLUE);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
  O(175,200,"YOU PLAY BAD");
  S(CYAN);
  O(176,201,"YOU PLAY BAD"); }
  sound(1000);
  delay(1000);
  sound(1500);
  delay(300);
  sound(400);
  delay(2020);
  nosound();
  S(BLUE);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  O(170,230,"PRESS ANY KEY TO CONTINUE(ESC TO QUIT)");
  S(WHITE);
  O(171,231,"PRESS ANY KEY TO CONTINUE(ESC TO QUIT)");

  if(getch()==27) {Quit();}
  else
  {ClrScreen();return(1);}
    }
    else ShowInfo(3,nStep_Sub_Rec);
    return(0);
}
/*====END OF FUN ISWIN====*/

void HelpMessage()
{
 S(15);
 L(7,314,632,314);
 L(7,432,632,432);
 S(12);
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 O(23,320,"HELP MESSAGE:");
 S(7);
 O(50,340,"1).............KEY: <-,->,A,D :MOVE THE RED BALL TO SELECT A ROD");
 O(50,365,"2).............KEY: UP,W      :TO SELECT THE TOP DISK");
 O(50,390,"3).............KEY: DOWN,S    :TO GET DOWN THE DISK WHICH SELECT");
 O(50,415,"4).............KEY: ESC       :QUIT THE GAME");
 S(12);
 O(50,442,"5).............IF   STEP-RECORD<=A BASENUM   THAN  :YOU WIN");
 O(50,453,"6).............IF   STEP-RECORD<=A BASENUM*2 THAN  :JUST SOSO");
 O(50,464,"7).............ELSE                                :YOU BAD BAD^_^");
}
/*====END OF FUN HELPMESSAGE====*/


/*========GAME:PLAYER PLAY========*/
void Game()
{
 int nMoveDisk[4],nUpdiskName1,nUpdiskName2,nUpdiskNum1,nUpdiskNum2,nHaveMove=0,i,j,nRn=0;
 int nStage,nStage1,nStage2,nRn1,nRn2;
 int x1,y1,x2,y2;
 int a=0,b=0;
 int nName=1;
 nRec=nRecord[nDisk-3];
 DrawRod();
 ShowRecord();
 FLASH_REC();

for (i=0;i<3;i++)         /*---EXIST BIT=0---*/
  for (j=0;j<9;j++)
    {tree[i].nDisk[j][0]=0;
     tree[i].nDiskName[j]=0;}


for (i=0;i<nDisk;i++)     /*DRAW THE DISKS OF THE FIRST ROD*/
 {
  tree[nRn].nDiskName[i]=nName;
  tree[nRn].nDisk[i][0]=1;      /*DISK i-----exist bit*/
  tree[nRn].nDisk[i][1]=40+a;   /*--X1--*/
  tree[nRn].nDisk[i][2]=390-b;  /*--Y1--*/
  tree[nRn].nDisk[i][3]=200-a;  /*--X2--*/
  tree[nRn].nDisk[i][4]=400-b;  /*--Y2--*/

  nName=nName+1;
  a=a+8;
  b=b+20;
 }

for (i=0;i<nDisk;i++)     /*********DRAW THE DISKS***********/
    FillDisk(tree[nRn].nDisk[i][1],tree[nRn].nDisk[i][2],tree[nRn].nDisk[i][3],tree[nRn].nDisk[i][4],8,BLUE);
for (i=0;i<4;i++)
    nMoveDisk[i]=0;
 DrawRod();
/*-----------------------------------------------------------------*/
Ball(nRn);

S(13);
O(239,419,"GAME START,PLEASE GO!!");
while(1)
    {if(kbhit())
      switch(getch())
       {case 75:     /**left**/
        case 'A':
        case 'a':
    nRn=((nRn==0)?2:nRn-1);
                 Ball(nRn);
    ShowInfo(nRn,0);
    FLASH_REC();
    break;

 case 77:     /**right**/
        case 'D':
        case 'd':
    nRn=((nRn==2)?0:nRn+1);
                 Ball(nRn);
    ShowInfo(nRn,0);
    FLASH_REC();
    break;

 case 72:     /**up**/
        case 'W':
 case 'w':
    for (i=0;tree[nRn].nDisk[i][0]!=0;i++);
    if (i<1) break;
    else
      {
        nUpdiskName1=tree[nRn].nDiskName[i-1];
        nUpdiskNum1=i-1;
        nStage1=i-1;
        nRn1=nRn;
    for (i=0;i<4;i++)
        nMoveDisk[i]=tree[nRn].nDisk[nUpdiskNum1][i+1];
        nHaveMove=0;
    /*    tree[nRn].diskname[nUpdiskNum1]=0;
   tree[nRn].disk[nUpdiskNum1][0]=0;   */
       }
    ShowInfo(nRn,1);
    break;

 case 80:     /**down**/
        case 'S':
 case 's':
    if (nMoveDisk[0]==0) break;
    for (i=0;tree[nRn].nDisk[i][0]!=0;i++);
    if (i<1)
      {  if (nHaveMove==1) break;
        nStage2=0;nRn2=nRn;
        tree[nRn].nDiskName[0]=nUpdiskName1;
        tree[nRn].nDisk[0][0]=1;      /**exist bit-->1**/
  tree[nRn1].nDiskName[nUpdiskNum1]=0;
  tree[nRn1].nDisk[nUpdiskNum1][0]=0;
        nStage=nStage1-nStage2;
        x1=nMoveDisk[0]+(nRn2-nRn1)*X;
        y1=nMoveDisk[1]+nStage*Y;
        x2=nMoveDisk[2]+(nRn2-nRn1)*X;
        y2=nMoveDisk[3]+nStage*Y;

        tree[nRn].nDisk[0][1]=x1;
        tree[nRn].nDisk[0][2]=y1;
        tree[nRn].nDisk[0][3]=x2;
        tree[nRn].nDisk[0][4]=y2;
      }
     else
      {
        nUpdiskName2=tree[nRn].nDiskName[i-1];
        nUpdiskNum2=i;
        nStage2=i;
        nRn2=nRn;
        if (nUpdiskName1>nUpdiskName2)
    {
    if (nHaveMove==1) break;
      tree[nRn].nDiskName[nUpdiskNum2]=nUpdiskName1;
      tree[nRn].nDisk[nUpdiskNum2][0]=1; /**exist bit-->1**/
       tree[nRn1].nDiskName[nUpdiskNum1]=0;
       tree[nRn1].nDisk[nUpdiskNum1][0]=0;
      nStage=nStage1-nStage2;
      x1=nMoveDisk[0]+(nRn2-nRn1)*X;
      y1=nMoveDisk[1]+nStage*Y;
      x2=nMoveDisk[2]+(nRn2-nRn1)*X;
      y2=nMoveDisk[3]+nStage*Y;

      tree[nRn].nDisk[nUpdiskNum2][1]=x1;
      tree[nRn].nDisk[nUpdiskNum2][2]=y1;
      tree[nRn].nDisk[nUpdiskNum2][3]=x2;
      tree[nRn].nDisk[nUpdiskNum2][4]=y2;
    }
    else
      {sound(1000);
       delay(300);
       nosound();
       break;     }
      }
      FillDisk(nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3],WHITE,WHITE);
      delay(2000);
      FillDisk(nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3],7,7);
      FillDisk(x1,y1,x2,y2,8,BLUE);
      nStep=nStep+1;
      ShowRecord();
      DrawRod();

      for(i=0;i<4;i++)
         nMoveDisk[i]=0;
         nHaveMove=1;
     if (IsWin()==1) return;       /****check if moves are finished****/
    break;

 case 27:Quit();break;
 default:sound(100);delay(10);nosound();break;
       }
}
}
/*====END OF FUNCTION GAME====*/

void Select()
{
 int nInput,i;
 DRAW();
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 S(15);
for (i=1;i<75;i++)
  {delay(500);          /*SPEED OF THE SENTENCE*/
  setviewport(0,0,50+i*8,479,1);
  O(155,230,"PLEASE INPUT THE NUMBER OF DISKS(3..9):");
  }
while((nInput=getch())<'3'||nInput>'9');
  nInput=nInput-48;
  nDisk=nInput;
  delay (1000);
}

void Mode_1()   /**PLAYER PLAY**/
{
again:
 DRAW();
 FadeOut();
 Game();   /**GAME**/
 cleardevice();
 if(nDisk<9) nDisk++;
 nStep=0;
 goto again;
}


void Initial_AutoPlay()
{
 int i,j,a=0,b=0;
 int nName=1;

 if (nSelectDelay==1) nDelay=0.5;      /** 0.5 SEC**/
 else if (nSelectDelay==2) nDelay=1.0; /** 1.0 SEC**/
 else nDelay=2.0;                      /** 2.0 SEC**/

nRec=nRecord[nDisk-3];
 DrawRod();
 ShowRecord();

for (i=0;i<3;i++)         /*---EXIST BIT=0---*/
  for (j=0;j<9;j++)
    {tree[i].nDisk[j][0]=0;
     tree[i].nDiskName[j]=0;}


for (i=0;i<nDisk;i++)     /*DRAW THE DISKS OF THE FIRST ROD*/
 {
  tree[0].nDiskName[i]=nName;
  tree[0].nDisk[i][0]=1;      /*DISK i-----exist bit*/
  tree[0].nDisk[i][1]=40+a;   /*--X1--*/
  tree[0].nDisk[i][2]=390-b;  /*--Y1--*/
  tree[0].nDisk[i][3]=200-a;  /*--X2--*/
  tree[0].nDisk[i][4]=400-b;  /*--Y2--*/

  nName=nName+1;
  a=a+8;
  b=b+20;
 }

for (i=0;i<nDisk;i++)     /*DRAW THE DISKS OF THE FIRST ROD*/
FillDisk(tree[0].nDisk[i][1],tree[0].nDisk[i][2],tree[0].nDisk[i][3],tree[0].nDisk[i][4],8,BLUE);
 DrawRod();
}

/*============GAME:AUTO PLAY (MOVEDISK)============*/
void MoveDisk(int nRn1,int nRn2)
{
 int nMoveDisk[4],nUpdiskName1,nUpdiskName2,nUpdiskNum1,nUpdiskNum2,i;
 int nStage,nStage1,nStage2;
 int x1,y1,x2,y2;
 nRn1=nRn1-1;
 nRn2=nRn2-1;
/*--------------------------------------------------------------------*/
for (i=0;tree[nRn1].nDisk[i][0]!=0;i++);
  nUpdiskName1=tree[nRn1].nDiskName[i-1];
  nUpdiskNum1=i-1;
  nStage1=i-1;
  for (i=0;i<4;i++)
     nMoveDisk[i]=tree[nRn1].nDisk[nUpdiskNum1][i+1];
   /*printf("%d %d %d %d/n",nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3]);*/
/*--------------------------------------------------------------------*/
sleep(nDelay);
/*--------------------------------------------------------------------*/
for (i=0;tree[nRn2].nDisk[i][0]!=0;i++);
       if (i<1)
      {
        nStage2=0;
        tree[nRn2].nDiskName[0]=nUpdiskName1;
        tree[nRn2].nDisk[0][0]=1;      /**exist bit-->1**/
  tree[nRn1].nDiskName[nUpdiskNum1]=0;
  tree[nRn1].nDisk[nUpdiskNum1][0]=0;
        nStage=nStage1-nStage2;
        x1=nMoveDisk[0]+(nRn2-nRn1)*X;
        y1=nMoveDisk[1]+nStage*Y;
        x2=nMoveDisk[2]+(nRn2-nRn1)*X;
        y2=nMoveDisk[3]+nStage*Y;

        tree[nRn2].nDisk[0][1]=x1;
        tree[nRn2].nDisk[0][2]=y1;
        tree[nRn2].nDisk[0][3]=x2;
        tree[nRn2].nDisk[0][4]=y2;
      }
     else
      {
        nUpdiskName2=tree[nRn2].nDiskName[i-1];
        nUpdiskNum2=i;
        nStage2=i;
        if (nUpdiskName1>nUpdiskName2)
    {
      tree[nRn2].nDiskName[nUpdiskNum2]=nUpdiskName1;
      tree[nRn2].nDisk[nUpdiskNum2][0]=1; /**exist bit-->1**/
       tree[nRn1].nDiskName[nUpdiskNum1]=0;
       tree[nRn1].nDisk[nUpdiskNum1][0]=0;
      nStage=nStage1-nStage2;
      x1=nMoveDisk[0]+(nRn2-nRn1)*X;
      y1=nMoveDisk[1]+nStage*Y;
      x2=nMoveDisk[2]+(nRn2-nRn1)*X;
      y2=nMoveDisk[3]+nStage*Y;

      tree[nRn2].nDisk[nUpdiskNum2][1]=x1;
      tree[nRn2].nDisk[nUpdiskNum2][2]=y1;
      tree[nRn2].nDisk[nUpdiskNum2][3]=x2;
      tree[nRn2].nDisk[nUpdiskNum2][4]=y2;
    }

      }
    /*  printf("%d %d %d %d/n",nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3]);*/
      FillDisk(nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3],WHITE,WHITE);
      delay(2000);
      FillDisk(nMoveDisk[0],nMoveDisk[1],nMoveDisk[2],nMoveDisk[3],7,7);
      FillDisk(x1,y1,x2,y2,8,BLUE);
      nStep=nStep+1;
      ShowRecord();
      DrawRod();

}
/*END OF FUNC AUTO PLAY:MOVEDISK*/


void AutoPlay(int nDisk,int one,int two,int three)
{
  if(nDisk==1) MoveDisk(one,three);
    else
     {
      AutoPlay(nDisk-1,one,three,two);
      MoveDisk(one,three);
      AutoPlay(nDisk-1,two,one,three);
     }
}

int SelectDelay()
{
 ClrScreen();
 S(7);
 R(98,278,200,295);
 R(268,278,370,295);
 R(437,278,539,295);
 L(149,278,149,200);
 L(319,278,319,200);
 L(486,278,486,200);
 L(149,200,590,200); /**UP LINE**/
 L(590,200,590,390);
 L(590,390,500,390);
 O(130,387,"PLEASE SELECT THE AUTO PLAY SPEED (DELAY TIME)");

 F(1,8);
 B(99,279,199,294);
 B(269,279,369,294);
 B(438,279,538,294);

 S(15);
 O(109,284,"0.5 SECOND");
 O(279,284,"1.0 SECOND");
 O(448,284,"2.0 SECOND");

 S(12);
 R(98,278,200,295);
 O(350,192,"_PRESS <F2> TO ENTER >>>");
while(1)
  {if(kbhit())
    switch(getch())
     {case 75:
      case 'a':
      case 'A': nSelectDelay=((nSelectDelay==1)?3:nSelectDelay-1);
  if (nSelectDelay==1)
     {S(12);R(98,278,200,295);
      S(7); R(268,278,370,295);R(437,278,539,295);}
  else if (nSelectDelay==2)
     {S(12);R(268,278,370,295);
      S(7); R(98,278,200,295);R(437,278,539,295);}
  else
     {S(12);R(437,278,539,295);
      S(7); R(98,278,200,295);R(268,278,370,295);}
  break;
       case 77:
       case 'd':
       case 'D': nSelectDelay=((nSelectDelay==3)?1:nSelectDelay+1);
   if (nSelectDelay==1)
     {S(12);R(98,278,200,295);
      S(7); R(268,278,370,295);R(437,278,539,295);}
  else if (nSelectDelay==2)
     {S(12);R(268,278,370,295);
      S(7); R(98,278,200,295);R(437,278,539,295);}
  else
     {S(12);R(437,278,539,295);
      S(7); R(98,278,200,295);R(268,278,370,295);}
  break;

 case 27:ClrScreen();Quit();END();break;
 case 60:ClrScreen();DRAW();
       FadeOut();
       S(GREEN);
       O(235,419,"--PRESS ANY KEY TO START--");
       getch();
       Initial_AutoPlay();
       AutoPlay(nDisk,1,2,3); /**AUTO PLAY**/
       F(1,8);
       B(230,418,620,428);
       S(15);
       O(235,419,"--AUTO PLAY OVER--");
       sleep(1);
       ClrScreen();
       return;
       break;
 default:sound(100);delay(10);nosound();break;
 }

    }

}

void Mode_2()
{
 SelectDelay();
 return;
}

void GameMode(int mode)
{
 if(mode==1)
 {ClrScreen();Select();Mode_1();}
 if(mode==2)
 {ClrScreen();Select();Mode_2();return;}
}

void Logo()
{
 int nPlay_Mode=1;
 DRAW();
 ClrScreen();
 HelpMessage();       /**HELP MESSAGE**/
 F(1,15);
 B(150,200,529,300);
 F(1,8);
 B(151,201,530,300);

 F(1,12);             /**DRAW BUTTON**/
 B(200,275,280,290);
 B(400,275,480,290);
 F(1,RED);
 B(201,276,281,291);
 F(1,9);
 B(401,276,481,291);

 S(12);
 O(265,255,"PRESS <F2> TO ENTER");

 S(15);
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 O(230,240,"PLEASE SELECT THE PLAY MODE:");
 O(205,280,"YOU  PLAY");
 O(405,280,"AUTO PLAY");

 while(1)
  {if(kbhit())
     switch(getch())
      {case 75:
       case 'a':
       case 'A':nPlay_Mode=((nPlay_Mode==1)?2:1);
  F(1,RED);
  if(nPlay_Mode==1)
     {B(201,276,281,291);
      O(205,280,"YOU  PLAY");
      F(1,9);
      B(401,276,481,291);
      O(405,280,"AUTO PLAY");}
  else
     {B(401,276,481,291);
      O(405,280,"AUTO PLAY");
      F(1,9);
      B(201,276,281,291);
      O(205,280,"YOU  PLAY");}break;
       case 77:
       case 'd':
       case 'D':nPlay_Mode=((nPlay_Mode==2)?1:2);
  F(1,RED);
  if(nPlay_Mode==1)
     {B(201,276,281,291);
      O(205,280,"YOU  PLAY");
      F(1,9);
      B(401,276,481,291);
      O(405,280,"AUTO PLAY");}
  else
     {B(401,276,481,291);
      O(405,280,"AUTO PLAY");
      F(1,9);
      B(201,276,281,291);
      O(205,280,"YOU  PLAY");}break;

       case 60:GameMode(nPlay_Mode);return;break;
       case 27:Quit();END();exit(0);break;
       default:sound(100);delay(10);nosound();break;

 }
  }
}

main()
{
 INITIAL();
 Start_Logo();
 getch();
again:
 nStep=0;
 Logo();
 goto again;
}
/**END**/

0 0

相关博文

我的热门文章

img
取 消
img