分析见我的博客 【C++ 程序】 井字棋游戏(人 VS Lv3电脑)(战绩统计版)(EasyX 图形界面)。
提一句,不知为什么我的电脑将其认定为病毒。自己编的中是第4次遇到这种情况了。
注意要下载 Easy-X,其中包含库graphics.h
。
程序
//This program is a simple tic-tac-toe game.
#include <iostream>
#include <string>
#include <cstddef>
#include <stdexcept>
#include <Windows.h>
#include <graphics.h>
#include <conio.h>
using namespace std;
IMAGE imageX, image0, imageXt, image0t, imageXw, image0w, imageD;
char point_now[3][3] = {
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
char player = 'X';
unsigned step_count = 0;
int win_lose(char point[3][3], int n)
{
if (point[0][0] == point[0][1] && point[0][1] == point[0][2] && point[0][0] == 'X') return 1; // X wins
if (point[1][0] == point[1][1] && point[1][1] == point[1][2] && point[1][0] == 'X') return 1; // X wins
if (point[2][0] == point[2][1] && point[2][1] == point[2][2] && point[2][0] == 'X') return 1; // X wins
if (point[0][0] == point[1][0] && point[1][0] == point[2][0] && point[0][0] == 'X') return 1; // X wins
if (point[0][1] == point[1][1] && point[1][1] == point[2][1] && point[0][1] == 'X') return 1; // X wins
if (point[0][2] == point[1][2] && point[1][2] == point[2][2] && point[0][2] == 'X') return 1; // X wins
if (point[