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.

46 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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
{
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<vector<int>> chessMap;
//表示现在该谁下棋
bool playerFlag;//true:该黑子走false:该白字走
void updateGameMap(ChessPos* pos);
bool checkWin();//如果胜负已分返回ture否则返回false
ChessPos lastPos;//最近落子点位置
};