|
|
|
@ -0,0 +1,45 @@
|
|
|
|
|
#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;//最近落子点位置
|
|
|
|
|
};
|
|
|
|
|
|