From 8979fa154238e56d790fd9d78ee2022c4f1aa8b9 Mon Sep 17 00:00:00 2001 From: pwhjurltz <2624989522@qq.com> Date: Tue, 9 Jan 2024 20:39:20 +0800 Subject: [PATCH] ADD file via upload --- Chess.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Chess.h diff --git a/Chess.h b/Chess.h new file mode 100644 index 0000000..838ad34 --- /dev/null +++ b/Chess.h @@ -0,0 +1,45 @@ +#pragma once +#include +#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 +{ +public: + Chess(int gradeSize, int marginX, int marginY, float chessSize); + void init();//棋盘初始化 + bool clickBoard(int x, int y, ChessPos* pos);//判断是否有效点击,如果是有效点击。把有效点击的位置保存在参数pos中 + void chessDown(ChessPos* pos, chess_kind_t kind);//在棋盘的指定位置(pos),落子(kind) + int getGradeSize();//获取棋盘大小 + int getChessData(ChessPos* pos);//获取指定位置的是黑棋还是白棋 + int getChessData(int row,int col); + bool checkOver(); +private: + IMAGE chessBlackImg; + + IMAGE chessWhiteImg; + + int gradeSize;//棋盘大小 + int margin_x;//棋盘的左侧边界 + int margin_y;//期盼的顶部边界 + float chessSize;//棋子的大小 + + //存储当前棋局数据 + vector> chessMap; + //表示现在该谁下棋 + bool playerFlag;//true:该黑子走,false:该白字走 + void updateGameMap(ChessPos* pos); + bool checkWin();//如果胜负已分,返回ture,否则返回false + ChessPos lastPos;//最近落子点位置 +}; +