From d0ccca886c1ee0d6c90f8efe19e0e25392096f56 Mon Sep 17 00:00:00 2001 From: peauxh9ov <1757486528@qq.com> Date: Tue, 18 Jun 2024 00:00:11 +0800 Subject: [PATCH] ADD file via upload --- Chess.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Chess.h diff --git a/Chess.h b/Chess.h new file mode 100644 index 0000000..07c47bb --- /dev/null +++ b/Chess.h @@ -0,0 +1,64 @@ +#pragma once +#include "graphics.h" +#include +using namespace std; + +//棋子位置 +struct ChessPos +{ + int row; + int col; + + ChessPos(int r = 0, int c = 0):row{ r }, col{ c } {} +}; + +typedef enum { + CHESS_WHITE = -1,//白 + CHESS_BLACK = 1//黑 +}chess_kind_t; +class Chess +{ + //添加数据成员 +private: + IMAGE chessBlackImg;//黑棋子 + IMAGE chessWhiteImg;//白棋子 + + int gradeSize;//棋盘大小 + int margin_x;//棋盘左侧边界 + int margin_y;//棋盘顶部边界 + double chessSize;//棋子大小(棋盘格大小) + ChessPos lastPos;//最后落子 + + //棋盘中棋子分布情况chessMap[行][列] + vector>chessMap{}; + + //落子方确定 + bool playerFlag;//true黑false白 + + //更新 + void updateGameMap(ChessPos* pos); + + //胜负判断 + bool checkWin(); +public: + Chess(int gradeSize, int marginX, int marginY, double chessSize); + //棋盘初始化 + void init(); + + //判断有效点击,并保存有效位置 + bool clickBoard(int x, int y, ChessPos *pos); + + //落子 + void ChessMove(ChessPos *pos, chess_kind_t kind); + + //获取棋盘大小 + int getGradeSize(); + + //是否获胜 + bool checkOver(); + + //获取指定位置棋子状态 + int getChessData(ChessPos* pos); + int getChessData(int row, int col); +}; +