The renderings are as follows :

Design ideas :

The chessboard is designed as 15×15 grid , The initial state cursor is in the center of the chessboard , White chess goes first , Take turns , When one side is connected into five pieces or the chessboard is full , game over ( The party with five sons in a row wins , A full chessboard is a draw ). When one side of the game wins, the victory information is displayed , Prompt information is output by Chinese character dot matrix .

The program game is a two-dimensional plan , It can be realized by two-dimensional array , The two subscripts of the array can represent the position on the chessboard , The value of the array element represents the state on the chess grid , There are three situations , namely 0 Represents a space ,1 Represents white chess ,2 Black chess . The main work of the program is to receive the key operation of the chess player , chess player 1 Use the four keys to control the cursor movement , The Enter key indicates the drop . chess player 2 Use the other four keys to control the cursor movement , The space bar represents the space bar . Enter or spacebar received , Explain the chess player's position , First judge whether it is a valid position , That is, the positions of chess pieces cannot overlap . After success , Immediately determine the eight directions centered on this position : upper , lower , Left , right , Upper left , Lower left , Upper right , Are there pieces of the same color at the bottom right connected into five pieces , If you are connected into five children , The game is over .

#include<stdio.h> #include<stdlib.h> #include<iostream> #include<graphics.h> #
include<windows.h> #include <mmsystem.h> #pragma comment(lib, "WINMM.LIB") #
include<conio.h> #include<time.h> #include<string.h> #define width 32 // Total width of chessboard #
define high 31 // Total height of chessboard #define MAX_X 15 // Number of checkerboard horizontal grids #define MAX_Y 15 // Number of checkerboard vertical grids #
define WIDTH (width+16) // Total game width #define HIGH (high+4) // Total height of the game #define player1 1
// Player one #define player2 2 // Player 2 #define emptyPlayer 0// No child or player #define Unplayer -2
// Quit the game halfway , No player wins #define MODEL_1 1// Mode I #define MODEL_2 2// Mode 2 typedef int
position; typedef int stackpointing; typedef struct Stack { // Record the coordinates of each drop
position x[MAX_X * MAX_Y]; position y[MAX_X * MAX_Y]; // Equivalent to stack top pointer stackpointing
top; }Stack; position pos[MAX_X][MAX_Y];// Store the status of each position on the chessboard For example, there are white children 1, There are sunspots for 2, No child is 0
position px, py; // Cursor position int player = 1;// Record current player The default player starts from the white side int flag1 = 0;// Mark the beginning of the game
int gameOver_player = -1;// Flag for judging the end int pre_px = -1, pre_py = -1;// Record the last coordinate position
void gotoxy(int x, int y);// set up CMD Window cursor position void hide_cursor(); // hide CMD Window cursor void map
();// Print map void game_Description();// Print Dynamic Game Description void initMapState();// Initialize game location data
void mapState(int qizi);// The array records the status of the corresponding position int isGoPlay();// Judge whether it can fall int hasGoPlay(
int Player);// Take the falling place as the center , Judge whether the five pieces of the chessboard are connected void goPlay(int Player, Stack* p);// Falling seed
Player 1 2 0 void yiDongKuang();// Move box void player1_move();// game player 1_ move void
player2_move();// game player 2_ move int gameOver();// Determine whether the game is over Stack* createStack();// Create empty stack
void zhuJieMian();// main interface void exit_WeiMu();// Exit the curtain void fengMian();// cover void
shuoming();// Game help description int zhongJianJieMian();// Intermediate interface , Select menu void fuXianQiZi(Stack* p)
;// Reproducing chess pieces void guangBiao_Limit();// Cursor limit void touXiang();// surrender void push(Stack* p,
int x, int y);// Push void color(const unsigned short textColor);// The custom function changes the color according to the parameters
// Move Cursor void gotoxy(int x, int y)// set up CMD Window cursor position { COORD coord; coord.X = x; coord.
Y= y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } // hide cursor
void hide_cursor() // hide CMD Window cursor { CONSOLE_CURSOR_INFO cci; cci.bVisible = FALSE;
cci.dwSize = sizeof(cci); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cci); } // colour void color(const unsigned short
textColor) // The custom function changes the color according to the parameters { if (textColor > 0 && textColor <= 15) // Parameter in 0-15 Range color
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textColor);
// Use one parameter , Change font color else // The default font color is white SetConsoleTextAttribute(GetStdHandle(
STD_OUTPUT_HANDLE), 7); } // Play music void playMusic() { //music.wav Is placed in the code file
PlaySound(TEXT("music.wav"), 0, SND_FILENAME | SND_ASYNC | SND_LOOP); } // Print map
void map() { int x, y; color(02); /* Start printing checkerboard grid */ // Print landscape grid for (y = 2; y < high - 1
; y += 2) { for (x = 1; x < width - 2; x += 2) { gotoxy(x, y); printf("-+"); } }
// Print vertical grid for (y = 1; y < high; y += 2) { for (x = 2; x < width - 2; x += 2) {
gotoxy(x, y); printf("|"); } } /* End of printing checkerboard grid */ /* Start printing borders */ // Print checkerboard frame for (y = 0; y <
high; y++) { for (x = 0; x < width; x += 2) { if (x == 0 || x == width - 2) {
gotoxy(x, y); printf("|"); } if (y == 0 || y == high - 1) { gotoxy(x, y); printf
("--"); } } } // Print right border for (y = 0; y < high; y++) { for (x = width; x < WIDTH; x
+= 2) { if (x == WIDTH - 2) { gotoxy(x, y); printf("|"); } if (y == 0 || y ==
high- 1) { gotoxy(x, y); printf("--"); } } } // Print the lower frame y->high ~ HiGH-1 x->0 ~
WIDTH-2 for (y = high; y < HIGH; y++) { for (x = 0; x < WIDTH; x += 2) { if (x
== 0 || x == WIDTH - 2) { gotoxy(x, y); printf("|"); } if (y == high || y ==
HIGH- 1) { gotoxy(x, y); printf("--"); } } } // Print the contents of the box below gotoxy(1, high + 1);
printf(" Welcome to Gobang !"); // Print the contents of the right frame gotoxy(width - 1, 1); printf(" Game Description :"); gotoxy(
width- 1, 3); printf("1)X Indicates that the player plays a chess game "); gotoxy(width - 1, 4); printf(" son , and O Represents the player ");
gotoxy(width - 1, 5); printf(" Two pieces "); gotoxy(width - 1, 7); printf("2)X before ,O after , alternate ");
gotoxy(width - 1, 8); printf(" skillful or capable , Only one at a time "); gotoxy(width - 1, 9); printf(" One son ");
gotoxy(width - 1, 11); printf("3) Under the chessboard "); gotoxy(width - 1, 12); printf(
" In the grid , Under the chess piece "); gotoxy(width - 1, 13); printf(" After fixing , Do not report to others "); gotoxy(width - 1, 14);
printf(" Point movement "); gotoxy(width - 1, 16); printf("4) First connected into five sons "); gotoxy(width - 1, 17);
printf(" The winner is the one who wins "); gotoxy(width - 1, 19); printf(" Player one Move key :"); gotoxy(width - 1,
20); printf("w upper s lower a Left d right "); gotoxy(width - 1, 21); printf(" skillful or capable : Space bar "); gotoxy(
width- 1, 23); printf(" Player 2 Move key :"); gotoxy(width - 1, 24); printf("i upper k lower j Left l right ");
gotoxy(width - 1, 25); printf(" skillful or capable : enter key "); gotoxy(width + 1, 27); color(4); printf
(" Game Description : P"); gotoxy(width + 1, 29); color(6); printf(" Repentance key : G"); /* End of print frame */ color
(02); /* Print four marked points on the chessboard */ gotoxy(3 * 2 + 2, 3 * 2 + 2); printf("*"); gotoxy((MAX_X -
4) * 2, 3 * 2 + 2); printf("*"); gotoxy(3 * 2 + 2, (MAX_Y - 4) * 2); printf("*")
; gotoxy((MAX_X - 4) * 2, (MAX_Y - 4) * 2); printf("*"); /* End of printing */ /* Start trimming */
/*gotoxy(width - 1, 0); printf(" "); gotoxy(width - 1, high - 1); printf(" ");*/
/* Trimming end */ /* Print map complete */ } // Print Dynamic Game Description void game_Description() { // Print the contents of the box below gotoxy(1,
high+ 1); printf(" "); if (player == player1) { gotoxy(1, high + 1); color(2);
printf(" The player is playing chess ..."); } else if (player == player2) { gotoxy(1, high + 1); color
(2); printf(" Player 2 plays chess ..."); } } // Initialize game location data void initMapState() { for (int i = 0;
i< MAX_Y; i++) { for (int j = 0; j < MAX_X; j++) { pos[i][j] = 0;// The initial state is all empty } }
// be careful The position of the cursor is different from the position stored in the array px = 7; py = 7; gotoxy(py * 2 + 1, px * 2 + 1);// initial position }
// The array records the status of the corresponding position void mapState(int qizi) { //2*px+1 = x //2*py+1 = y //px->0~14
//py->0~14 if (px >= MAX_X || px < 0 || py >= MAX_Y || py < 0) return;
// The status cannot be recorded under other circumstances pos[px][py] = qizi; } // Judge whether it can fall int isGoPlay() { if (px >= MAX_X
|| px < 0 || py >= MAX_Y || py < 0) return 0;// The status cannot be recorded under other circumstances if (pos[px][py] ==
emptyPlayer) {// Description no child return 1; } else {// It means there are children return 0; } }
// Take the falling place as the center , Judge whether the five pieces of the chessboard are connected int hasGoPlay(int Player) {
// It is divided into two parts , Record the same part first Player Number of // Then record the number of other parts , Add to the total number of connected pieces int port1 = 0, port2 = 0;
int x, y, count; // Find up and down x = px, y = py - 1; while (y >= 0 && pos[x][y] == Player
) { ++port1;// Number of upper parts --y;// Move up } y = py + 1; while (y < MAX_Y && pos[x][y] ==
Player) { ++port2;// Number of lower parts ++y;// Move down } // Calculate total count = port1 + port2 + 1; if (
count>= 5) return 1; // Left and right search port1 = 0, port2 = 0; x = px - 1, y = py; while ( x
>= 0 && pos[x][y] == Player ) { ++port1;// Number of upper parts --x;// Shift left } x = px + 1; while (x
< MAX_X && pos[x][y] == Player) { ++port2;// Number of lower parts ++x;// Shift right } // Calculate total count =
port1+ port2 + 1; if (count >= 5) return 1; // Top left and bottom right search port1 = 0, port2 = 0; x =
px- 1, y = py - 1; while ( x >= 0 && y >= 0 && pos[x][y] == Player) { ++port1;
// Number of upper parts --x;// Shift left --y;// Move up } x = px + 1, y = py + 1; while ( x < MAX_X && y <
MAX_Y&& pos[x][y] == Player ) { ++port2;// Number of lower parts ++x;// Shift right ++y;// Move down } // Calculate total
count= port1 + port2 + 1; if (count >= 5) return 1; // Top right and bottom left search port1 = 0, port2 =
0; x = px + 1, y = py - 1; while ( x < MAX_X && y >= 0 && pos[x][y] == Player )
{ ++port1;// Number of upper parts ++x;// Shift left --y;// Move up } x = px - 1, y = py + 1; while ( x >= 0 &&
y< MAX_Y && pos[x][y] == Player ) { ++port2;// Number of lower parts --x;// Shift right ++y;// Move down } // Calculate total
count= port1 + port2 + 1; if (count >= 5) return 1; return 0; } // Falling seed Player 1 2
0 void goPlay(int Player, Stack* p) { if (isGoPlay()) {// It means you can drop the seeds mapState(Player)
;// Record the corresponding position in the array if (hasGoPlay(Player)) {// If the five are connected , be gameover gameOver_player =
Player; // Record the winning player at the moment , End the game } /* Push */ push(p, px, py); /* Role switching */ if (Player == player1
) { player = player2;// Switch to player 1 gotoxy(px * 2 + 1, py * 2 + 1);// Move the cursor to the corresponding position color(
07); printf("X");// Print player 1 game_Description();// Dynamic description } else if (Player == player2
) { player = player1;// Switch to another player 2 gotoxy(px * 2 + 1, py * 2 + 1);// Move the cursor to the corresponding position
color(07); printf("O");// Print player 2 game_Description();// Dynamic description } } } // Push void push(
Stack* p, int x, int y) { // Stack the coordinates of the moment int top = p->top; ++p->top;// Moving stack needle p->x[top
] = x; p->y[top] = y; return; } // Out of stack void pop(Stack* p) { int x, y; // Out of stack , Move stack top pointer
// If the stack is empty , Will not pop up if (p->top <= 0) return; --p->top; int top = p->top; // Record the pop-up position x
= p->x[top]; y = p->y[top]; // Print spaces in the pop-up position gotoxy(x * 2 + 1, y * 2 + 1); printf(" "
); // Erase record pos[x][y] = 0; } // Move box void yiDongKuang() { // Limit cursor range if (py < 0) py =
0; else if (py > MAX_Y - 1) py = MAX_Y - 1; else if (px < 0) px = 0; else if (px
> MAX_X - 1) px = MAX_X - 1; // Print move box gotoxy(px * 2, py * 2 + 1); color(11);
printf("["); gotoxy(px * 2 + 2, py * 2 + 1); printf("]"); // End of print move box if (pre_px
!= -1 && pre_py != -1) { if (pre_px > px && pre_py == py) {// When moving to the left
// Leave the right side of the previous position as it is gotoxy(pre_px * 2 + 2, pre_py * 2 + 1); color(2); printf("|"); }
else if (pre_px < px && pre_py == py) {// When moving to the right // Leave the left side of the previous position as it is gotoxy(pre_px *
2, pre_py * 2 + 1); color(2); printf("|"); } else {// When moving up and down // Leave the left and right edges of the previous position as they are
gotoxy(pre_px * 2 + 2, pre_py * 2 + 1); color(2); printf("|"); gotoxy(pre_px * 2
, pre_py * 2 + 1); color(2); printf("|"); } } pre_px = px; pre_py = py; }
// Reproduce all player pieces void fuXianQiZi(Stack* p) { if (p->top <= 0) return; int top = p->top
- 1;// Note that the pointer at the top of the stack does not move , It's just recorded int x, y, flag; if (player == player1) flag = 1; else
if (player == player2) flag = 2; else return; while (top>=0) { // Record the pop-up position x = p
->x[top]; y = p->y[top]; // Print spaces in the pop-up position if (flag == 1) { gotoxy(x * 2 + 1, y * 2 +
1); color(7); printf("O"); flag = 2; } else { gotoxy(x * 2 + 1, y * 2 + 1);
color(7); printf("X"); flag = 1; } --top;// The recording position moves backward } } // game player 1 move void
player1_move(Stack* p) { char key; if (_kbhit())// Check whether the key is pressed { fflush(stdin); key =
_getch();// Save key switch (key) { case 'w': py--; yiDongKuang(); break;// upper case 'a'
: px--; yiDongKuang(); break;// Left case 'd': px++; yiDongKuang(); break;// right case
's': py++; yiDongKuang(); break;// lower case ' ': goPlay(player1, p);
game_Description();break;// Falling seed // Dynamic description case 'y': gameOver_player = -2; gameOver();
// Exit the game case 'Y': gameOver_player = -2; gameOver();// Exit the game case 'g': pop(p); pop(p
); break;// Repentance chess case 'G': pop(p); pop(p); break;// Repentance chess case 'p': shuoming(); system(
"cls"); map(); fuXianQiZi(p); break;// Check the instructions case 'P': shuoming(); system("cls");
map(); fuXianQiZi(p); break;// Check the instructions case 'f': touXiang(); break;// surrender case 'F':
touXiang(); break;// surrender default: break; } } } // game player 2 move void player2_move(Stack* p
) { char key; if (_kbhit())// Check whether the key is pressed , Used to force the contents of the buffer to be written to a file . { fflush(stdin);
// Clear a stream , That is, clear the file buffer key = _getch();// Save key switch (key) { case 'i': py--;
yiDongKuang(); break;// upper case 'j': px--; yiDongKuang(); break;// Left case 'l': px++
; yiDongKuang(); break;// right case 'k': py++; yiDongKuang(); break;// lower case '\r':
goPlay(player2, p); game_Description(); break;// Falling seed // Dynamic description case 'y':
gameOver_player= -2; gameOver();// Exit the game case 'Y': gameOver_player = -2; gameOver(
);// Exit the game case 'g': pop(p); pop(p); break;// Repentance chess case 'G': pop(p); pop(p); break;
// Repentance chess case 'p': shuoming(); system("cls"); map(); fuXianQiZi(p); break;// Check the instructions
case 'P': shuoming(); system("cls"); map(); fuXianQiZi(p); break;// Check the instructions case
'f': touXiang(); break;// surrender case 'F': touXiang(); break;// surrender default: break; } }
} // Create empty stack Stack* createStack() { // Application space Stack* p = (Stack*)malloc(sizeof(Stack)
); // If no space is requested if (p == NULL) return NULL; p->top = 0;// Initialize stack top return p; }
// Determine whether the game is over int gameOver() { //gamerOver_player -1 Indicates to continue the game 1 It means that Belarus wins 2 It means the black side wins 0
It means a draw // Five connected Winning side y->high ~ HiGH-1 x->0 ~ WIDTH-2 if (gameOver_player == -1) {
return 1; } else if (gameOver_player == player1) {// White victory gotoxy(1, high + 1);
color(04); printf(" game player 1 victory !!! "); color(02); return 0; } else if (gameOver_player
== player2) {// Black victory gotoxy(1, high + 1); color(04); printf(" game player 2 victory !!! "); color(
02); return 0; } else if (gameOver_player == emptyPlayer) {// The chessboard is full of chess it ends in a draw gotoxy(1,
high+ 1); color(06); printf(" it ends in a draw !!! "); color(02); return 0; } else if (
gameOver_player== Unplayer) {// Midway exit color(02); exit_WeiMu();// Exit the curtain of the game system(
"cls"); gotoxy(WIDTH / 2 - 10, HIGH / 2); printf(" Exit the game successfully !!!"); gotoxy(WIDTH / 2
- 10, HIGH / 2 - 2); printf(" Thank you again for your support !"); gotoxy(0, 0); exit(1); exit(1); }
return 1; } // Game help description void shuoming() { int x, y; system("cls"); color(02);
// Print border for (y = 0; y < HIGH; y++){ for (x = 0; x < WIDTH; x += 2){ if (x == 0 ||
x== WIDTH - 2) { gotoxy(x, y); printf("*"); } if (y == 0 || y == HIGH - 1) {
gotoxy(x, y); printf("* "); } } } // printing complete // print contents while (1) { gotoxy(4, 3); printf
(" The rules of the game are as follows :\n"); gotoxy(6, 5); printf(" Both sides of the game take turns ,o Represents player one "); gotoxy(6, 7); printf(
",x Indicates player 2 , The player is on the side first "); gotoxy(6, 9); printf(" Sub frame , Player 2 will then enter the box "); gotoxy(6, 11);
printf(" son , The player who gets five sons first wins !("); gotoxy(6, 13); printf(" The game only supports hands free )o( ̄┰ ̄*)ゞ"); gotoxy(4,
15); printf(" Key related description :"); gotoxy(6, 17); printf("< Y key : retreat Out swim play >"); gotoxy(6, 18)
; printf("< G key : Regret Chess >"); gotoxy(6, 19); printf("< P key : check see swim play say bright >"); gotoxy(
6, 20); printf("< F key : throw drop >"); gotoxy(WIDTH / 2 - 10, HIGH - 4); printf("< U key
: return return >"); if (_kbhit())// Check whether the key is pressed { fflush(stdin); if (_getch() == 'u' || _getch()
== 'U') { // If you press the spacebar , Then exit the description interface return; } } } // printing complete } // Exit the curtain of the game interface void exit_WeiMu()
{ int x, y; color(2); for ( y = 0; y < HIGH; y++) { for ( x = 0; x < WIDTH; x +=
2) { gotoxy(x, y); printf("■"); } Sleep(100); } for ( y = HIGH - 1; y >= 0; y--)
{ for ( x = WIDTH; x >= 0; x -= 2) { gotoxy(x, y); printf(" "); } Sleep(100); }
} // Print main interface cover void fengMian() { int x, y, z, add = 0; // Dot matrix printing Gobang color(06); gotoxy(
6, 3); printf("******"); gotoxy(8, 4); printf("* "); gotoxy(6, 5); printf(
"*****"); gotoxy(8, 6); printf("* *"); gotoxy(5, 7); printf("********"); color(
04); gotoxy(17, 3); printf("*****"); gotoxy(20, 4); printf("* "); gotoxy(16, 5);
printf("*********"); gotoxy(20, 6); printf("* "); gotoxy(19, 7); printf("** ");
color(3); gotoxy(30, 3); printf("* * * "); gotoxy(28, 4); printf("***** *******"
); gotoxy(29, 5); printf("*** * * "); gotoxy(28, 6); printf("* * * * *** *");
gotoxy(28, 7); printf("* * * * * "); color(10); gotoxy(1, 10); printf(" * * * *
* * * * * * * * * * * * * * * * * * "); // printing complete // Print cover // Build a house for (z = 0; z < 14
; z++, add++) { color(3); gotoxy(WIDTH / 2 - 6, HIGH - 2 - add); printf("┌");
color(4); gotoxy(WIDTH / 2 - 4, HIGH - 2 - add); printf("╀"); color(6); gotoxy(
WIDTH/ 2 - 2, HIGH - 2 - add); printf("┣"); } color(1); gotoxy(WIDTH / 2 - 4,
HIGH- 2 - add); printf("┬╂┬"); color(2); gotoxy(WIDTH / 2 - 4, HIGH - 3 - add);
printf(" ╳"); // Build another house add = 0; for (z = 0; z < 8; z++, add++) { color(3);
gotoxy(WIDTH / 2 + 4, HIGH - 2 - add); printf("┌"); color(4); gotoxy(WIDTH / 2 +
6, HIGH - 2 - add); printf("╀"); color(6); gotoxy(WIDTH / 2 + 8, HIGH - 2 - add)
; printf("┣"); } color(1); gotoxy(WIDTH / 2 + 6, HIGH - 2 - add); printf("┬╂┬");
color(2); gotoxy(WIDTH / 2 + 6, HIGH - 3 - add); printf(" ╳"); // The house is finished // Build some trees
color(3); gotoxy(WIDTH / 2 + 16, HIGH - 3); printf("○"); gotoxy(WIDTH / 2 + 16,
HIGH- 2); printf("|"); gotoxy(WIDTH / 2 + 18, HIGH - 3); printf("○"); gotoxy(
WIDTH/ 2 + 18, HIGH - 2); printf("|"); for (int i = 0; i < 10; i += 2) { gotoxy(
WIDTH/ 2 - 10 - i, HIGH - 3); printf("○"); gotoxy(WIDTH / 2 - 10 - i, HIGH - 2);
printf("|"); } gotoxy(WIDTH / 2 - 22, HIGH - 3); printf("○"); gotoxy(WIDTH / 2 -
22, HIGH - 2); printf("|"); hide_cursor();// hide cursor // Completion of construction // Print border color(2); for (y
= 0; y < HIGH; y++) { for (x = 0; x < WIDTH; x += 2) { if (x == 0 || x == WIDTH
- 2) { gotoxy(x, y); printf("*"); } if (y == 0 || y == HIGH - 1) { gotoxy(x, y);
printf("* "); } } } // Print border complete // Print cover completed } // Intermediate interface int zhongJianJieMian() { system(
"cls"); int x, y, a = 0, choice = 0; // Print border for (y = 0; y < HIGH; y++) { for (x
= 0; x < WIDTH; x += 2) { if (x == 0 || x == WIDTH - 2) { gotoxy(x, y); printf(
"*"); } if (y == 0 || y == HIGH - 1) { gotoxy(x, y); printf("* "); } } } // printing complete
while (1) { // Continuously detect whether there is key operation , If it exists , According to different key operations , Indicates different states if (GetAsyncKeyState(VK_UP) ||
GetAsyncKeyState(87) || GetAsyncKeyState(119)) // Press on { if (a == 0) a = 2; else if
(a == 1) a = 0; else if (a == 2) a = 1; } if (GetAsyncKeyState(VK_DOWN) ||
GetAsyncKeyState(83) || GetAsyncKeyState(115)) // Press { if (a == 0) a = 1; else if
(a == 1) a = 2; else if (a == 2) a = 0; } if (GetAsyncKeyState('\r')) { if (a ==
0) { return MODEL_1;// Return to mode 1 } else if (a == 1) { return MODEL_2;// Return to mode 2 } else{
system("cls");// Return to the main interface return 0; } } if (a == 0) { gotoxy(WIDTH / 2 - 8, 12);
printf("△ Mode I : Double mode "); } else { gotoxy(WIDTH / 2 - 8, 12); printf(" Mode I : Double mode "); }
if (a == 1) { gotoxy(WIDTH / 2 - 8, 14); printf("△ Mode 2 : standalone mode "); } else { gotoxy(
WIDTH/ 2 - 8, 14); printf(" Mode 2 : standalone mode "); } if (a == 2) { gotoxy(WIDTH / 2 - 8, 16
); printf("△ Return to the main interface "); } else { gotoxy(WIDTH / 2 - 8, 16); printf(" Return to the main interface "); }
// Prompt flashing text if (choice == 2) { gotoxy(WIDTH / 2 - 10, HIGH - 4); printf(" < Enter to confirm > "
); Sleep(200);// Prevent flashing screen choice = 0; } else { gotoxy(WIDTH / 2 - 10, HIGH - 4);
printf(" "); Sleep(200); choice++; } } } // main interface void zhuJieMian() { int a = 0;
int choice = 1; fengMian();// Print main interface cover while (1) {
// Continuously detect whether there is key operation , If it exists , According to different key operations , Indicates different states if (GetAsyncKeyState(VK_UP) ||
GetAsyncKeyState(87) || GetAsyncKeyState(119)) // Press on { if (a == 0) a = 2; else if
(a == 1) a = 0; else if (a == 2) a = 1; } if (GetAsyncKeyState(VK_DOWN) ||
GetAsyncKeyState(83) || GetAsyncKeyState(115)) // Press { if (a == 0) a = 1; else if
(a == 1) a = 2; else if (a == 2) a = 0; } if (GetAsyncKeyState('\r')) { if (a ==
0) {// Enter the game system("cls");// Clear screen return ; } else if (a == 1) { shuoming();// Game help description
system("cls");// Clear screen fengMian();// Reprint cover } else if (a == 2) { exit_WeiMu();
// Exit the curtain of the game system("cls"); gotoxy(WIDTH / 2 - 10, HIGH / 2); printf(" Exit the game successfully !!!");
gotoxy(WIDTH / 2 - 10, HIGH / 2 - 2); printf(" Thank you again for your support !"); gotoxy(6, 22); printf
(" of course , New models will be developed later , than "); gotoxy(6, 24); printf(" standalone mode , Hands off mode, etc . Here feeling "); gotoxy(6, 26);
printf(" Thank you for your support , Coming soon !!!"); gotoxy(0, 0); exit(1); } } if (a == 0) { gotoxy(WIDTH
/ 2 - 8, 12); color(4); printf("△ Start the game "); } else { gotoxy(WIDTH / 2 - 8, 12);
color(2); printf(" Start the game "); } if (a == 1) { gotoxy(WIDTH / 2 - 8, 14); color(4);
printf("△ Game help "); } else { gotoxy(WIDTH / 2 - 8, 14); color(2); printf(" Game help "
); } if (a == 2) { gotoxy(WIDTH / 2 - 8, 16); color(4); printf("△ Exit the game "); }
else { gotoxy(WIDTH / 2 - 8, 16); color(2); printf(" Exit the game "); } // Flashing prompt text if (
choice== 2) { gotoxy(WIDTH / 2 + 4, 12); color(7); printf(" < Enter to confirm > "); Sleep(
200);// Prevent flashing screen choice = 0; } else { gotoxy(WIDTH / 2 + 4, 12); printf(" "); Sleep(
200); choice++; } } } // surrender void touXiang() { if (player == player1) {// game player 1 surrender
gameOver_player= 2;// game player 2 victory } else {// game player 2 surrender gameOver_player = 1;// game player 1 victory } } int
main() { // Set title system("title Next gobang "); // Adjust game box system("mode con cols=48
lines=35"); // Start background music // This requires a corresponding .wav file playMusic(); // main interface zhuJieMian();
// Intermediate interface -- Select mode while (!zhongJianJieMian()) { Sleep(100); // main interface zhuJieMian(); }
// Print map map(); // Initialize game location data initMapState(); // Create empty stack Stack* p = createStack();
// hide cursor hide_cursor(); // Game cycle Control movement while (gameOver()) { // Constantly changing characters if (player ==
player1) player1_move(p);// Switch players 1 else if (player == player2) player2_move(p);
// Switch players 2 } free(p); }

Technology
Daily Recommendation