Hannota classic DOS version TC source code

xiaoxiao2021-03-06  100

source:

http://blog.9cbs.net/bolm/archive/2004/04/07/16311.aspx

/ ************************************************** ********************** ???????????????????? Hanoi Tower V2.0 ?????????????????????????????????????? ??????? Turbo C 2.0 compiler ??????????????? ** ????????????? ?????????????? source program ?????????????????? ** ?????? ??????????????????????? Made by bolman ?????????????????????????? • ** ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? *********************************************************** *********** / # 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 [IJ] = B [J] '0';}

Voidinitial () ???? ** 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@tang.com ?? ");} void End () {? Char message [110] = ">>> i 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); nond ();}? Sleep (1);

Void Flash_Rec () {? int Num, x1 = 8, x2 = 10; randomize (); 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 @ esna.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 nwhetdisk) {? f (1, 8) ;? B (230, 418, 620, 428) ;? setTextStyle (default_font, horiz_dir, 1) ;? s (cyan) ;? IF (nrn == 0 && nthergetdisk == 0 ) ?? o (235, 419, "you now at the first rod") ;? Else if (nrn == 1 && nthergetdisk == 0) ?? o (235, 419, "You Now At the Second Rod"); Else IF (NRN == 2 && nwhetdisk == 0) ?? o (235, 419, "You now at the third rod") ;? Else if (nwhetdiTDisk == 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"); Break; ?????? default: Break; ?????} ?? }? Else if (nrn == 3 && nwhethergetdisk == nbasenum) ???? {s (white); O (235, 419, "you shop 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 "Ok 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);

• (348, 82, 360, 94); NTOA (NREC);? S (YELLOW) ;? o (290, 86, "Record:");? S (15) ;? o (350, 86, chmark) ;

• (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 ) ?? {??? f (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 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); 181, 211," Thank you to play ");? O (181, 231," ????? 2002.7 ???? ");? O (181, 260 "Any Key to Quit");? S (green) ;? o (180, 180, "Game ??) ;? s (15) ;? o (181, 181," Game ?? Over ") ;? Getch ( ); Mouthin () ;? closegraph () ;? end () ;? exit (0);} / * ==== end of fun quit ==== * /

INT iswin () {? INT I, NSTEP_SUB_REC;? int ndisknum = 0 ;? for (i = 0; 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;

???? f (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);

? nond ();

? 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) ............. f ?? step-record <= a basenu * 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, 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; ???? Tree [i] .ndiskname [j] = 0;

For (i = 0; i

? {

? 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

??? 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); ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????. ? BREAK;

Case 77: ???? / ** Right ** / ??????? case 'd': ??????? case 'd': ??? nrn = ((nrn == 2 )? 0: nrn 1); ??????????????????????????????????? showinfo (nrn, 0); ??? Break;

Case 72: ???? / ** Up ** / ??????? 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 ); ??? f 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 [N Rn1] .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 (); ?????? breaf; ????} ?????} ????? 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 (); breaf;? default: Sound (100); delay (10); nond (); 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) ; ????????? / * speted 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 () ;? f (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 second ** /

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; ???? Tree [i] .ndiskname [j] = 0;} for (i = 0; i

? {

? 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

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 nrmovedisk [4) {? 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 ); ?????? ing (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 = ns TAGE1-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

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 (); breaf;? case 60: clrscreen (); DRAW (); ?????? fadeout (); ?????? s (green) ?????? o (235, 419, "- press any key to start -"); ?????? getch (); ?????? INIAL_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); nond (); 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

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?"); ????? 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 ();

?}?}}

MAIN () {? initial (); start_logo ();? getch (); again:? nstep = 0;? logo (); goto again;} / ** end ** /

转载请注明原文地址:https://www.9cbs.com/read-123528.html

New Post(0)