利用数组实现三子棋(包含三个文件):
1.test.c //对游戏逻辑的测试
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
void menu()
{
printf("***********************\n");
printf("*****1.play 0.exit*****\n");
printf("***********************\n");
}
void game()
{
char ret = 0;
//(1)创建一个二维数组对期盼数据进行存储
char board[ROW][COL] = { 0 };
//(2)对二维数组(棋盘)进行初始化(空格)
InitBoard(board , ROW , COL);
//(3)打印棋盘(井字型)
DisplayBoard(board , ROW , COL);
while (1)
{
//(4)开始下棋(玩家)
PlayerMove(board,ROW,COL);
//(5)判断输赢
ret = IsWin(board,ROW,COL);
if (ret != 'C') //玩家赢-'* ';电脑赢-'# ';平局-'Q ';游戏继续-'C '
{
break;
}
//(6)展示棋盘
DisplayBoard(board, ROW, COL);
//(7)电脑下棋
AutoMove(board , ROW , COL);
//(8)判断输赢
ret = IsWin(board, ROW, COL);
if (ret != 'C')
{
break;
}
//(9)展示棋盘
DisplayBoard(board, ROW, COL);
}
if (ret == '*')
{
printf("玩家赢!\n");