Hannota's source procedure

zhaozj2021-02-16  37

This program is a game program of Hanno, written with Turbo C 2.0 and successfully, the game allows players to choose the number of plates (3 to 7). And there are three game results (you win; game over; you play BAD), and after a success, players can choose to exit or continue (if you choose to continue, the number of trays will be added). This game program is simple, friendly interface, can play, is the first Hanno tower game program under the DOS interface.

Author E_mail: bolm@etang.com

/ * --------------------------- Hanoi Tower V 1.0 ----------------- --------- * // * ----------------------------- Source Program ------ --------------------- * / # include "stdio.h" #include "cono.h" #include "stdlib.h" #include "graphics.h "#include" math.h "

#define o Outtextxy # Define s setcolor # Define f setfillstyle # define r rectangle # define c circle # define l line # define bar # define b3d bar3d

#define x 200 # Define Y 30

INT Step = 0; int RECORD [5] = {7, 15, 31, 63, 127}, REC; int Disk, disknum; char mark [15];

Struct Rod {Int Disk [8] [5]; int DiskName [8];} Tree [3];

/ **************************************************** / NTOA (Int S ) {INT B [15]; INT I, J; for (i = 0; i <15; i ) Mark [i] = '/ 0'; for (i = 0; s> = 10; i ) {b [i] = S% 10; s / = 10;} b [i] = s; for (j = i; j> = 0; j -) Mark [ij] = b [j] '0'; }

Void Drawrod () {f (1, LightBlue); B (118, 150, 122, 400); / * ROD1 * / B (318, 150, 322, 400); / * ROD2 * / B (518, 150, 522, 400); / * ROD3 * / f (6, blue); B (119, 151, 123, 401); B (319, 151, 323, 401); B (519, 151, 522, 401);

Void Draw () {s (LightBlue); R (10, 10, 629, 40); / * Up line1 * / l (10, 26, 629, 26); L (10, 450, 629, 450); / * bottom line1 * / L (10, 446, 629, 446); S (Green); setTextStyle (default_font, horiz_dir, 2); O (200, 452, "Hanoi Tower V1.0); s (LightBlue); O (201, 453," Hanoi Tower V1.0 " }

Void showrecord () {setTextStyle (default_font, horiz_dir, 1); f (1, black); bar (58, 11, 80, 22); NTOA (Disk); s (red); o (20, 15, "Disk : "); S (Green); O (60, 15, Mark); BAR (318, 11, 350, 22); NTOA (REC); S (REC); O (260, 15," Record: "); s (Green); O (320, 15, mark);

BAR (530, 11, 600, 22); NTOA (STEP); S (RED); O (490, 15, "Step:"); s (Green); O (532, 15, Mark);

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 (6, color1); B3D (x1 1, Y1 1, X2 1, Y2 1, 5, 5);

Void Action () / ** Animation ** / {INT I; S (Black); for (i = 0; i <600; i = i 2) {R (i, 0, i 40, 479); delay 100);}}

INT ifwin () {INT I, STEP_SUB_REC; DiskNum = 0; for (i = 0; I

For (i = 0; i <3000; i = i 50) {SOUND (i); delay (300); nond ();} s (red); setTextStyle (default_font, horiz_dir, 2); o (180, 240, "Thank you to play"); s (Green); O (181, 241, "Thanou to Play"); s (red); R (168, 298, 473, 309); setTextStyle (default_font, horiz_dir, 1); o (170, 300, "Press Any Key To Continue (ESC to Quit)); S (YELLOW); O (171, 301, "Press Any Key To Continue (ESC To Quit)); if (Getch () == 27) {Closegraph (); EXIT (0);} else return (1);} return (0);

Void HelpMessage () {s (blue); R (20, 258, 619, 405); L (20, 260, 619, 260); L (20, 376, 619, 376); S (RED); O (124, 230, ">>); setTextStyle (Sans_serif_Font, Horiz_Dir, 1); O (23, 265, "Help Message:"); setTextStyle (default_font, horiz_dir, 1); s (LightBlue); O (30, 290, "1). Key: <-, ->, a, d: move the red ball to SELECT A ROD "); O (30, 315," 2). Key: Up, W: TO SELECT The Top Disk "); O (30, 340," 3). Key: Down, S: To Get Down The Disk Which SELECT ); O (30, 365, "4). Key: esc: quit the game"); s (red); O (30, 382, ​​"5). If step-record <10 Than: you win"); O (30, 393, "6). Else: Game over");

/ ********************** --- Game --- ******************* ******** / VOID GAME () {INT MOVEDISK [4], UpdiskName1, UpdiskName2, UpdiskNum1, UpdiskNum2, Havemove = 0, I, J, RN = 0; Int Stage, Stage1, Stage2, Rn1, RN2 INT X1, Y1, X2, Y2; INT A = 0, B = 0; INT Name = 1; CHAR C; REC = Record [Disk-3]; DRAW (); Drawrod (); showRecord ();

For (i = 0; i <3; i ) / ***** --- EXIST bit = 0 --- ******** / for (j = 0; j <7; j ) { Tree [i] .disk [j] = 0; Tree [i] .diskname [j] = 0;}

For (i = 0; i

For (i = 0; i

F (1, black); B (20, 100, 609, 130); F (1, RED); S (RED); C (118 (RN * 200), 115, 10); floodfill (118 (Rn * 200), 115 Red);

While (1) {if (kBhit ()) Switch (c = getch ()) {case 75: / ** left ** / case 'a': Case 'a': RN = ((RN == 0)? 2: RN-1); Break;

Case 77: / ** right ** / case 'd': Case 'D': RN = ((RN == 2)? 0: Rn 1); Break;

Case 72: / ** UP ** / CASE 'W': Case 'W': for (i = 0; Tree [RN] .disk [i] [0]! = 0; i ); if (i <1 ) Break; else {updiskname1 = Tree [RN] .diskname [i-1]; UpdiskNum1 = i-1; STAGE1 = I-1; RN1 = Rn; for (i = 0; i <4; i ) MoveDisk [i ] = Tree [RN] .disk [UpdiskNum1] [i 1]; Havemove = 0; / * Tree [RN] .diskname [UpdiskNum1] = 0; Tree [RN] .disk [UpdiskNum1] [0] = 0; * /} BREAK;

Case 80: / ** down ** / case 's': case 's': IF (MoveDisk [0] == 0) Break; for (i = 0; Tree [RN] .disk [i] [0] ! = 0; i ); if (i <1) {if (Havemove == 1) Break; STAGE2 = 0; RN2 = RN; Tree [RN] .diskname [0] = UpdiskName1; Tree [RN] .disk [ 0] [0] = 1; / ** EXIST bit -> 1 ** / tree [rn1] .diskname [UpdiskNum1] = 0; Tree [RN1] .disk [UpdiskNum1] [0] = 0; Stage = stage1 -stage2; x1 = movedisk [0] (RN2-RN1) * x; Y1 = MoveDisk [1] stage * y; x2 = MoveDisk [2] (RN2-RN1) * x; Y2 = MoveDisk [3] Stage * Y; Tree [RN] .disk [0] [1] = x1; Tree [RN] .disk [0] [2] = Y1; Tree [RN] .disk [0] [3] = x2; Tree [RN] .disk [0] [4] = Y2;} else {updiskname2 = Tree [RN] .diskname [i-1]; UPDiskNum2 = i; stage2 = i; RN2 = RN; if (UpdiskName1> UpdiskName2) {IF (Havemove == 1) Break; Tree [RN] .diskname [UpdiskNum2] = UpdiskName1; Tree [RN] .disk [UpdiskNum2] [0] = 1; / * * EXIST BIT -> 1 ** / Tree [RN1] .diskname [UpdiskNum1] = 0; Tree [RN1] .disk [Updisknum1] [0] = 0 , = Stage1-stage2; x1 = MoveDisk [0] (RN2-RN1) * x; Y1 = MoveDisk [1] Stage * Y; X2 = MoveDisk [2] (RN2-RN1) * x; Y2 = MoveDisk [3] Stage * Y;

Tree [RN] .disk [UpdiskNum2] [1] = x1; Tree [RN] .disk [UpdiskNum2] [2] = Y1; Tree [RN] .disk [UpDiskNum2] [3] = x2; Tree [RN]. Disk [UpdiskNum2] [4] = Y2;} else {Sound (1000); DELAY (300); Nosound (); Break;}} FillDisk (MoveDisk [0], MoveDisk [1], MoveDisk [2], MoveDisk [ 3], 7, 9); DELAY (2000); FillDisk (MoveDisk [0], MoveDisk [1], MoveDisk [2], MoveDisk [3], 0, 0); FillDisk (x1, y1, x2, y2, 9, 1); Step = step 1; showRecord (); Drawrod (); for (i = 0; i <4; i ) MoveDisk [i] = 0; Havemove = 1; if (ifwin () == 1 Return; / **** Check if Moves Are Finished **** / BREAK

Case 27: Closegraph (); exit (0); default: Break;} f (1, black); B (20, 100, 609, 130); f (1, red); s (red); c (118 (Rn * 200) 115, 10); Floodfill (118 (RN * 200), 115, RED);

}

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

New Post(0)