The previous article has problems, so now I will reissue one!
Suitable for beginners like me!
Master can not look.
BC is compiled under the BC, you can realize interpersonal battle.
The original code is as follows
#include
Void doerror; void dook; Void Dowin (int Order); Void Movecursor (int rt x, int in); void DrawMap (Void); int Judgewin (int Order , Struct Point Cursor; Int Judgewinline (int Direction); Void ShoworderMsg (int order); void endgame (void); / *************** ****************************************** ******** // *********** *********************************************************** ** // * Define global variables * / int GPlayOrder; / * Indicates the current chess party * / struct point gcursor; / * Cursor position on the board * / char gchesboard [19] [19]; / * For recording The status of each point on the chessboard * // *************************************************** **************** // **************************************** *************************** / / * main function * / void main () {INT PRESS; int boutwhile = false; / * exit Cycle sign * / init (); / * Initialization image, data * / while (1) {press = getKey (); / * Get user's button value * / switch (checkkey (press) / * judgment button category * / {/ * Is exit button * / case keyexit: clrs (); / * clear screen * / boutwhile = true; break; / * is a false bond * / case keyf Allchess: IF (ChesSGO (GPLAYORDER, GCURSOR) == false / * Watch * / doerror (); / * Falls error * / else {dook (); / * Falls correct * / * If the current chess party wins Chess * / if (gplayorder, gcursor == true) {dowin (gPlayOrder); boutwhile = true; / * Exit loop flag is true * /} / * otherwise * / else / * exchange line chess party * / ChangeORDER ();} Break; / * is a cursor mobile key * / case keymovecursor: MoveCursor (gPlayOrder, press); break; / * is invalid key * / case keyventiD: Break;} if (boutwhile == true) Break;} / *} / ********************************************** ************** * Interface initialization, data initialization * / void init (void) {INT I, J; char * msg [] = {"
Player1 Key: "," UP ---- W "," Down - S "," Left - A "," Right-D "," Do ---- Space "," "" "" "" "" "," UP ---- UP "," Down "," Left - Left "," Right-Right "," Do ---- Enter "," "EXIAME:", " Esc ", null,}; / * first, first, player * / gplayorder = chess1; / * chessboard data is clear, that is, there is no chess piece * / for (i = 0; i <19) ; i ) for (j = 0; j <19; j ) gchesboard [i] [j] = chessnull; / * cursor initial position * / gcursor.x = gcursor.y = 0; / * Cash board * / textmode C40); DrawMap (); / * Display operation key description * / i = 0; TextColor (brown); while (msg [i]! = Null) {gotoxy (25, 3 i); CPUTS (MSG [i] ); I ;} / * Show the current chess party * / showordermsg (gplayorder); / * Cream moves to the top left corner of the board * / gotoxy (gcursor.x mapxoft, gcursor.y mapyoft);} / * Chess board * / void DrawMap (void) {INT I, J; CLRSCR (); for (i = 0; i <19; i ) for (j = 0; j <19; j ) Drawcross (i, j); } / * The intersection on the chessboard * / void Drawcross (int X, int y) {gotoxy (x mapxoft, y mapyoft); / * At the intersection is a player's chess pieces * / if (gchesboard [x ] [y] == chess1) {textColor (LightBlue); PUTCH (Chess1); Return;} / * The intersection is the 2nd player's chess * / If (gchersboard [x] [y] == chess2) {textcolor (lightblue); PUTCH (Chess2); return;} textcolor (green); / * Left upper corner intersection * / if (x == 0 && y == 0) {PUTCH (Crosslu); Return;} / * Cross point * / if (x == 0 && y == 18) {PUTCH (CrossLD); Return;} / * Intersection * / if (x = = 18 && y == 0) {PUTCH (Crossru); return;} / * upper right corner crosspoint * / if (x == 18 && y == 18) {PUTCH (crossrd); return;} / * left boundary intersection * / IF (x ==
0) {PUTCH (Crossl); RTURN;} / * Right boundary intersection * / if (x == 18) {PUTCH (crossr); return;} / * upper boundary intersection * / if (y == 0) {PUTCH (Crossu);} / * lower boundary intersection * / if (y == 18) {PUTCH (CrossD);} / * The intersection of the board * / PUTCH (Cross);} / * Exchange row chess party * / int changerder (void) {if (gPlayorder == chess1) gPlayOrder = chess2; else gplayorder = chess1; return (gplayorder);} / * Get button value * / int getKey (void) {char lowbyte; INT PRESS; while (Bioskey (1) == 0); / * If the user does not button, air loop * / press = bioskey (0); lowbyte = press & 0xff; press = Press & 0xFF00 Toupper (lowbyte); Return (press); RETURN (PRESS); } / * Falling error handling * / void doerror (void) {Sound (1200); DELAY (50); noid ();} / * Winning processing * / void dowin (int order) {Sound (1500); DELAY 100); Sound (0); DELAY (50); DELAY (100); Sound (0); Delay (50); Sound (1500); DELAY (100); Sound (0); DELAY 50); Sound (800); DELAY (100); Sound (0); DELAY (50); Nosound (); TextColor (Red BLINK); gotoxy (25, 20); if (Order == Chess1) CPUTS "Player1 Win!"); Else CPUTS ("Player2 Win!"); Gotoxy (25, 21); CPUTS ("// <^ ^> /"); getCh ();} / * Watch * / int Chessgo (int Order, Struct Point Cursor) {/ * Judging the intersection with no chess pieces * / if (GCssboard [CURSOR.X] [CURSOR.Y] == CHESSNULL) {/ * If there is no chess piece, you can fall to the seed * / gotoxy (Cursor.x MapXoft, Cursor.y MAPYOFT); TextColor (LightBlue); PUTCH (Order) Gotoxy (CURSOR.X MAPXOFT, CURSOR.Y MAPYOFT); GCHESSBOARD [CURSOR.X] [CURSOR.Y] = ORDER; RETURN TRUE;} else return false;} / * Judging whether the current chess party is winning Chess * / int JudGewin (int in) {INT i; for (i = 0; i <4; i ) / * Judging whether there is a chess piece * / if of 5 row chess squares in the specified direction Judgewinline (Order, Cursor, I)) Return true; Return False;
} / * Judging whether there is 5 row chess pieces in the specified direction * / int JudGewinline (int Direction) {Int i; struct point pos, dpos; const INT TestNum = 5; int Count; switch (direction) {case 0: / * is in the horizontal direction * / post = cursor.x- (Testnum-1); POS.Y = Cursor.y; dpos.x = 1; dpos.y = 0 Break; case 1: / * in the vertical direction * / post = Cursor.x; pos.y = cursor.y- (testnum-1); dpos.x = 0; dpos.y = 1; Break; Case 2: / * In the left to top of the direction * / post, = cursor.x- (testnum-1); pos.y = cursor.y (Testnum-1); dpos.x = 1; dpos.y = -1; Break; Case 3: / * In the left to the lower right direction * / post, = cursor.x- (Testnum-1); pOS.Y = Cursor.y- (Testnum-1); DPOS. x = 1; dpos.y = 1; Break;} count = 0; for (i = 0; i