簡單三子棋

2021-09-19 10:14:55 字數 1394 閱讀 1225

c8

簡單三子棋**

/*使用二維陣列 建立乙個棋盤,

每乙個元素都是乙個char

'x'表示玩家落子

'o'表示電腦落子

' '表示未落子*/

#define _crt_secure_no_warnings

#include

#include

#include

int menu()

#define max_row 3

#define max_col 3

char chess_board[max_row][max_col];//建立乙個全域性變數

void init()}}

void print()}}

void playermove()

if (chess_board[row][col] != ' ')

chess_board[row][col] = 'x';

break;}}

void computermove()

chess_board[row][col] = 'o';

break;}}

//棋盤滿了,返回1,否則返回0

int isfull()}}

return 1;//只要找到乙個位置『 』就認為沒滿

}//返回x表示玩家勝

//返回o表示電腦勝

//返回q表示和棋

//返回' '表示未分出勝負,也不是和棋,繼續進行遊戲

char checkgameover()

}for (int col = 0; col < max_col; ++col)

}if (chess_board[0][0] == chess_board[1][1] &&

chess_board[0][0] == chess_board[2][2])

if (chess_board[0][2] == chess_board[1][1] &&

chess_board[0][2] == chess_board[2][0])

if (isfull())

return ' ';

}void game()

//5.電腦落子

computermove();

//6.檢測遊戲結束

winner=checkgameover();

if (winner != ' ')

}if (winner == 'x')

else if (winner == 'o')

else if (winner == 'o')

else

}int main()

else if (choice == 0)

else

}system ("pause");

return 0;

簡單三子棋遊戲

通過二維陣列實現簡單的三子棋。玩家通過輸入棋盤座標進行下棋,電腦隨機生成自己的棋子。通過do while迴圈和switch case實現遊戲選單。int main while input return 0 將二維陣列全部致為空格,玩家下的棋子用x表示,電腦的棋子用o表示,即將二維陣列中的值改變為相應...

簡單的三子棋實現

game.h pragma warning disable 4996 ifndef game h define game h include include include define row 3 define col 3 void initboard char board row col int...

簡單的三子棋程式

一.題目分析 簡單三子棋是指棋盤為3 3,玩家與電腦之間對決的遊戲。其中 0 代表電腦落子,x 玩家落子。基本思路 1.列印地圖 列印乙個 字狀的棋盤 2.電腦落子 隨機落子 3.玩家落子 通過輸入座標的方式 4判斷遊戲結果 二.程式 game.件 ifndef game h define game...