You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.2 KiB
65 lines
1.2 KiB
#pragma once
|
|
#include "graphics.h"
|
|
#include <vector>
|
|
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<vector<int>>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);
|
|
};
|
|
|