|
|
@ -1,278 +1,278 @@
|
|
|
|
#include "Chess.h"
|
|
|
|
#include "Chess.h"
|
|
|
|
#include <conio.h>
|
|
|
|
#include <conio.h>
|
|
|
|
//修正png透明背景无法显示(网上当的)
|
|
|
|
//„1¤7„1¤7„1¤7„1¤7png<EFBFBD>0È6„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1«9„1¤7„1¤7„1¤7<EFBFBD>0¶5„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>0Ð3„1¤7„1¤7<EFBFBD>0<EFBFBD>0„1¤7
|
|
|
|
void putimagePNG(int x, int y, IMAGE* picture) //x为载入图片的X坐标,y为Y坐标
|
|
|
|
void putimagePNG(int x, int y, IMAGE* picture) //x<EFBFBD>0Ë2„1¤7„1¤7„1¤7„1¤7<EFBFBD>0É0<EFBFBD>0œ2„1¤7„1¤7X„1¤7„1¤7„1¤7‚6þ7y<EFBFBD>0Ë2Y„1¤7„1¤7„1¤7„1¤7
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 变量初始化
|
|
|
|
// „1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>0¶3„1¤7„1¤7
|
|
|
|
DWORD* dst = GetImageBuffer(); // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
|
|
|
|
DWORD* dst = GetImageBuffer(); // GetImageBuffer()„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1’7„1¤7<EFBFBD>0§0„1¤7„1¤7<EFBFBD>0É0„1¤7õô„1¤7„1¤7„1¤7<EFBFBD>0é6„1¤7<EFBFBD>0ö8„1¤7ƒ0 3EASYX„1¤7<EFBFBD>0é6„1¤7
|
|
|
|
DWORD* draw = GetImageBuffer();
|
|
|
|
DWORD* draw = GetImageBuffer();
|
|
|
|
DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
|
|
|
|
DWORD* src = GetImageBuffer(picture); //„1¤7„1¤7<EFBFBD>0§0picture„1¤7„1¤7„1¤7<EFBFBD>0é6„1¤7<EFBFBD>0ö8„1¤7„1¤7
|
|
|
|
int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
|
|
|
|
int picture_width = picture->getwidth(); //„1¤7„1¤7<EFBFBD>0§0picture„1¤7<EFBFBD>0‘7„1¤7„1¤7<EFBFBD>0§2„1¤7EASYX„1¤7<EFBFBD>0é6„1¤7
|
|
|
|
int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
|
|
|
|
int picture_height = picture->getheight(); //„1¤7„1¤7<EFBFBD>0§0picture„1¤7<EFBFBD>0‘0<EFBFBD>1²2<EFBFBD>0§2„1¤7EASYX„1¤7<EFBFBD>0é6„1¤7
|
|
|
|
int graphWidth = getwidth(); //获取绘图区的宽度,EASYX自带
|
|
|
|
int graphWidth = getwidth(); //„1¤7„1¤7<EFBFBD>0§0„1¤7„1¤7<EFBFBD>0É0„1¤7„1¤7„1¤7<EFBFBD>0‘7„1¤7„1¤7<EFBFBD>0§2„1¤7EASYX„1¤7<EFBFBD>0é6„1¤7
|
|
|
|
int graphHeight = getheight(); //获取绘图区的高度,EASYX自带
|
|
|
|
int graphHeight = getheight(); //„1¤7„1¤7<EFBFBD>0§0„1¤7„1¤7<EFBFBD>0É0„1¤7„1¤7„1¤7<EFBFBD>0‘0<EFBFBD>1²2<EFBFBD>0§2„1¤7EASYX„1¤7<EFBFBD>0é6„1¤7
|
|
|
|
int dstX = 0; //在显存里像素的角标
|
|
|
|
int dstX = 0; //„1¤7„1¤7„1¤7<EFBFBD>0é6„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1…3<EFBFBD>0‘5<EFBFBD>0¢3„1¤7
|
|
|
|
|
|
|
|
|
|
|
|
// 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
|
|
|
|
// <EFBFBD>0µ6„1¤7„1¤7<EFBFBD>0È6„1¤7„1¤7„1¤7„1¤7<EFBFBD>0É0 „1¤7„1¤7<C2A4>0¶4„1¤7„1¤7 Cp=„1¤7„1¤7p*FP+(1-„1¤7„1¤7p)*BP „1¤7„1¤7 „1¤7„1¤7<C2A4>0Ý0<C39D>0»9„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7§Ö„1¤7„1¤7„1¤7<C2A4>0®2„1¤7<C2A4>0‘0„1¤7„1¤7<C2A4>0¶3„1¤7„1¤7„1¤7
|
|
|
|
for (int iy = 0; iy < picture_height; iy++)
|
|
|
|
for (int iy = 0; iy < picture_height; iy++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int ix = 0; ix < picture_width; ix++)
|
|
|
|
for (int ix = 0; ix < picture_width; ix++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int srcX = ix + iy * picture_width; //在显存里像素的角标
|
|
|
|
int srcX = ix + iy * picture_width; //„1¤7„1¤7„1¤7<EFBFBD>0é6„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1…3<EFBFBD>0‘5<EFBFBD>0¢3„1¤7
|
|
|
|
int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
|
|
|
|
int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA„1¤7„1¤7<EFBFBD>0È6„1¤7„1¤7„1¤7„1¤7
|
|
|
|
int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
|
|
|
|
int sr = ((src[srcX] & 0xff0000) >> 16); //„1¤7„1¤7<EFBFBD>0§0RGB„1¤7„1¤7„1¤7R
|
|
|
|
int sg = ((src[srcX] & 0xff00) >> 8); //G
|
|
|
|
int sg = ((src[srcX] & 0xff00) >> 8); //G
|
|
|
|
int sb = src[srcX] & 0xff; //B
|
|
|
|
int sb = src[srcX] & 0xff; //B
|
|
|
|
if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
|
|
|
|
if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
dstX = (ix + x) + (iy + y) * graphWidth; //在显存里像素的角标
|
|
|
|
dstX = (ix + x) + (iy + y) * graphWidth; //„1¤7„1¤7„1¤7<EFBFBD>0é6„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1…3<EFBFBD>0‘5<EFBFBD>0¢3„1¤7
|
|
|
|
int dr = ((dst[dstX] & 0xff0000) >> 16);
|
|
|
|
int dr = ((dst[dstX] & 0xff0000) >> 16);
|
|
|
|
int dg = ((dst[dstX] & 0xff00) >> 8);
|
|
|
|
int dg = ((dst[dstX] & 0xff00) >> 8);
|
|
|
|
int db = dst[dstX] & 0xff;
|
|
|
|
int db = dst[dstX] & 0xff;
|
|
|
|
draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) //公式: Cp=αp*FP+(1-αp)*BP ; αp=sa/255 , FP=sr , BP=dr
|
|
|
|
draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) //„1¤7„1¤7<EFBFBD>0¶4„1¤7„1¤7 Cp=„1¤7„1¤7p*FP+(1-„1¤7„1¤7p)*BP „1¤7„1¤7 „1¤7„1¤7p=sa/255 , FP=sr , BP=dr
|
|
|
|
| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) //αp=sa/255 , FP=sg , BP=dg
|
|
|
|
| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) //„1¤7„1¤7p=sa/255 , FP=sg , BP=dg
|
|
|
|
| (sb * sa / 255 + db * (255 - sa) / 255); //αp=sa/255 , FP=sb , BP=db
|
|
|
|
| (sb * sa / 255 + db * (255 - sa) / 255); //„1¤7„1¤7p=sa/255 , FP=sb , BP=db
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chess::Chess(int gradeSize, int marginX, int marginY, double chessSize)
|
|
|
|
Chess::Chess(int gradeSize, int marginX, int marginY, double chessSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this->gradeSize = gradeSize;
|
|
|
|
this->gradeSize = gradeSize;
|
|
|
|
this->margin_x = marginX;
|
|
|
|
this->margin_x = marginX;
|
|
|
|
this->margin_y = marginY;
|
|
|
|
this->margin_y = marginY;
|
|
|
|
this->chessSize = chessSize;
|
|
|
|
this->chessSize = chessSize;
|
|
|
|
playerFlag = CHESS_BLACK;
|
|
|
|
playerFlag = CHESS_BLACK;
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
vector<int>row;
|
|
|
|
vector<int>row;
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
row.push_back(0);
|
|
|
|
row.push_back(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chessMap.push_back(row);
|
|
|
|
chessMap.push_back(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Chess::init()
|
|
|
|
void Chess::init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//显示棋盘
|
|
|
|
//„1¤7„1¤7<EFBFBD>0¶5„1¤7„1¤7„1¤7„1¤7
|
|
|
|
loadimage(0, "graphics/map.png");
|
|
|
|
loadimage(0, "map.png");//¸ü¸Ä·¾¶
|
|
|
|
//显示棋子
|
|
|
|
//„1¤7„1¤7<EFBFBD>0¶5„1¤7„1¤7„1¤7„1¤7
|
|
|
|
loadimage(&chessBlackImg, "graphics/black.png", chessSize-2, chessSize-2, true);
|
|
|
|
loadimage(&chessBlackImg, "black.png", chessSize-2, chessSize-2, true);//¸ü¸Ä·¾¶
|
|
|
|
loadimage(&chessWhiteImg, "graphics/white.png", chessSize-2, chessSize-2, true);
|
|
|
|
loadimage(&chessWhiteImg, "white.png", chessSize-2, chessSize-2, true);//¸ü¸Ä·¾¶
|
|
|
|
|
|
|
|
|
|
|
|
//清零棋盘
|
|
|
|
//„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
chessMap[i][j] = 0;
|
|
|
|
chessMap[i][j] = 0;
|
|
|
|
playerFlag = true;
|
|
|
|
playerFlag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Chess::clickBoard(int x, int y, ChessPos* pos)
|
|
|
|
bool Chess::clickBoard(int x, int y, ChessPos* pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int col = (x - margin_x) / chessSize;
|
|
|
|
int col = (x - margin_x) / chessSize;
|
|
|
|
int row = (y - margin_y) / chessSize;
|
|
|
|
int row = (y - margin_y) / chessSize;
|
|
|
|
int leftTopPosX = margin_x + chessSize * col;
|
|
|
|
int leftTopPosX = margin_x + chessSize * col;
|
|
|
|
int leftTopPosY = margin_y + chessSize * row;
|
|
|
|
int leftTopPosY = margin_y + chessSize * row;
|
|
|
|
int offset = chessSize * 0.4;
|
|
|
|
int offset = chessSize * 0.4;
|
|
|
|
int len;
|
|
|
|
int len;
|
|
|
|
bool ret = false;
|
|
|
|
bool ret = false;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
//左上角
|
|
|
|
//„1¤7„1¤7„1¤7<EFBFBD>0Ñ1„1¤7
|
|
|
|
len = sqrt((x - leftTopPosX) * (x - leftTopPosX) + (y - leftTopPosY) * (y - leftTopPosY));
|
|
|
|
len = sqrt((x - leftTopPosX) * (x - leftTopPosX) + (y - leftTopPosY) * (y - leftTopPosY));
|
|
|
|
if (len < offset)
|
|
|
|
if (len < offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pos->row = row;
|
|
|
|
pos->row = row;
|
|
|
|
pos->col = col;
|
|
|
|
pos->col = col;
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//右上角
|
|
|
|
//„1¤7„1¤7„1¤7<EFBFBD>0Ñ1„1¤7
|
|
|
|
int x2 = leftTopPosX + chessSize;
|
|
|
|
int x2 = leftTopPosX + chessSize;
|
|
|
|
int y2 = leftTopPosY;
|
|
|
|
int y2 = leftTopPosY;
|
|
|
|
len = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
|
|
|
len = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
|
|
|
if (len < offset)
|
|
|
|
if (len < offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pos->row = row;
|
|
|
|
pos->row = row;
|
|
|
|
pos->col = col+1;
|
|
|
|
pos->col = col+1;
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//左下角
|
|
|
|
//„1¤7„1¤7„1¤7<EFBFBD>0†5„1¤7
|
|
|
|
int x3 = leftTopPosX;
|
|
|
|
int x3 = leftTopPosX;
|
|
|
|
int y3 = leftTopPosY + chessSize;
|
|
|
|
int y3 = leftTopPosY + chessSize;
|
|
|
|
len = sqrt((x - x3) * (x - x3) + (y - y3) * (y - y3));
|
|
|
|
len = sqrt((x - x3) * (x - x3) + (y - y3) * (y - y3));
|
|
|
|
if (len < offset)
|
|
|
|
if (len < offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pos->row = row + 1;
|
|
|
|
pos->row = row + 1;
|
|
|
|
pos->col = col;
|
|
|
|
pos->col = col;
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//右下角
|
|
|
|
//„1¤7„1¤7„1¤7<EFBFBD>0†5„1¤7
|
|
|
|
int x4 = leftTopPosX + chessSize;
|
|
|
|
int x4 = leftTopPosX + chessSize;
|
|
|
|
int y4 = leftTopPosY + chessSize;
|
|
|
|
int y4 = leftTopPosY + chessSize;
|
|
|
|
len = sqrt((x - x4) * (x - x4) + (y - y4) * (y - y4));
|
|
|
|
len = sqrt((x - x4) * (x - x4) + (y - y4) * (y - y4));
|
|
|
|
if (len < offset)
|
|
|
|
if (len < offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pos->row = row + 1;
|
|
|
|
pos->row = row + 1;
|
|
|
|
pos->col = col + 1;
|
|
|
|
pos->col = col + 1;
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Chess::ChessMove(ChessPos* pos, chess_kind_t kind)
|
|
|
|
void Chess::ChessMove(ChessPos* pos, chess_kind_t kind)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int x = margin_x + chessSize * pos->col - 0.5 * chessSize;
|
|
|
|
int x = margin_x + chessSize * pos->col - 0.5 * chessSize;
|
|
|
|
int y = margin_y + chessSize * pos->row - 0.5 * chessSize;
|
|
|
|
int y = margin_y + chessSize * pos->row - 0.5 * chessSize;
|
|
|
|
|
|
|
|
|
|
|
|
if (kind == CHESS_WHITE)
|
|
|
|
if (kind == CHESS_WHITE)
|
|
|
|
putimagePNG(x, y, &chessWhiteImg);
|
|
|
|
putimagePNG(x, y, &chessWhiteImg);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
putimagePNG(x, y, &chessBlackImg);
|
|
|
|
putimagePNG(x, y, &chessBlackImg);
|
|
|
|
|
|
|
|
|
|
|
|
updateGameMap(pos);
|
|
|
|
updateGameMap(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Chess::getGradeSize()
|
|
|
|
int Chess::getGradeSize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return gradeSize;
|
|
|
|
return gradeSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Chess::checkWin()
|
|
|
|
bool Chess::checkWin()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 横竖斜四种大情况,每种情况都根据当前落子往后遍历5个棋子,有一种符合就算赢
|
|
|
|
// „1¤7„1¤7„1¤7„1¤7§Ò„1¤7„1¤7„1¤7<EFBFBD>0ö4„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>0‹7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>1¥3„1¤7<EFBFBD>0¢2„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤75„1¤7„1¤7„1¤7„1¤7„1¤7<EFBFBD>0á5„1¤7„1¤7„1¤7<EFBFBD>0Ý5„1¤7<EFBFBD>0ö7„1¤7„1¤7<EFBFBD>0Ñ2„1¤7„1¤7„1¤7<EFBFBD>0â6
|
|
|
|
// 水平方向
|
|
|
|
// <EFBFBD>0º8<EFBFBD>0<EFBFBD>9„1¤7„1¤7„1¤7„1¤7
|
|
|
|
int row = lastPos.row;
|
|
|
|
int row = lastPos.row;
|
|
|
|
int col = lastPos.col;
|
|
|
|
int col = lastPos.col;
|
|
|
|
|
|
|
|
|
|
|
|
//落子水平方向
|
|
|
|
//„1¤7„1¤7„1¤7„1¤7<EFBFBD>0º8<EFBFBD>0<EFBFBD>9„1¤7„1¤7„1¤7„1¤7
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (col - i >= 0 &&
|
|
|
|
if (col - i >= 0 &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 1] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 1] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 2] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 2] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 3] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 3] &&
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 4])
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 4])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setlinecolor(RED);
|
|
|
|
setlinecolor(RED);
|
|
|
|
line(margin_x + (col - i) * chessSize, margin_y + (row) * chessSize, margin_x + (col - i + 4) * chessSize, margin_y + (row) * chessSize);
|
|
|
|
line(margin_x + (col - i) * chessSize, margin_y + (row) * chessSize, margin_x + (col - i + 4) * chessSize, margin_y + (row) * chessSize);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 竖直方向(上下延伸4个)
|
|
|
|
// „1¤7„1¤7<EFBFBD>0ö1„1¤7„1¤7„1¤7„1¤7(„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7„1¤74„1¤7„1¤7)
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 1][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 1][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 2][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 2][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 3][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 3][col] &&
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 4][col])
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 4][col])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setlinecolor(RED);
|
|
|
|
setlinecolor(RED);
|
|
|
|
line(margin_x + (col) * chessSize, margin_y + (row - i)*chessSize, margin_x + (col) * chessSize, margin_y + (row - i + 4)*chessSize);
|
|
|
|
line(margin_x + (col) * chessSize, margin_y + (row - i)*chessSize, margin_x + (col) * chessSize, margin_y + (row - i + 4)*chessSize);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// “/"方向
|
|
|
|
// „1¤7„1¤7/"„1¤7„1¤7„1¤7„1¤7
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (row + i < gradeSize &&
|
|
|
|
if (row + i < gradeSize &&
|
|
|
|
row + i - 4 >= 0 &&
|
|
|
|
row + i - 4 >= 0 &&
|
|
|
|
col - i >= 0 &&
|
|
|
|
col - i >= 0 &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
// 第[row+i]行,第[col-i]的棋子,与右上方连续4个棋子都相同
|
|
|
|
// „1¤7„1¤7[row+i]„1¤7§µ„1¤7„1¤7„1¤7[col-i]„1¤7„1¤7„1¤7„1¤7„1¤7<C2A4>0á5„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7<C2A4>0Ð5„1¤7„1¤7„1¤7„1¤7„1¤74„1¤7„1¤7„1¤7„1¤7„1¤7<C2A4>0ã4„1¤7„1¤7„1¤7<C2A4>0Ç4
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 1][col - i + 1] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 1][col - i + 1] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 2][col - i + 2] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 2][col - i + 2] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 3][col - i + 3] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 3][col - i + 3] &&
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 4][col - i + 4])
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 4][col - i + 4])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setlinecolor(RED);
|
|
|
|
setlinecolor(RED);
|
|
|
|
line(margin_x + (col - i)*chessSize, margin_y + (row + i) * chessSize, margin_x + (col - i + 4)*chessSize, margin_y + (row + i - 4) * chessSize);
|
|
|
|
line(margin_x + (col - i)*chessSize, margin_y + (row + i) * chessSize, margin_x + (col - i + 4)*chessSize, margin_y + (row + i - 4) * chessSize);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// “\“ 方向
|
|
|
|
// „1¤7„1¤7\„1¤7„1¤7 „1¤7„1¤7„1¤7„1¤7
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 第[row+i]行,第[col-i]的棋子,与右下方连续4个棋子都相同
|
|
|
|
// „1¤7„1¤7[row+i]„1¤7§µ„1¤7„1¤7„1¤7[col-i]„1¤7„1¤7„1¤7„1¤7„1¤7<C2A4>0á5„1¤7„1¤7„1¤7„1¤7„1¤7„1¤7¡¤„1¤7„1¤7„1¤7„1¤7„1¤74„1¤7„1¤7„1¤7„1¤7„1¤7<C2A4>0ã4„1¤7„1¤7„1¤7<C2A4>0Ç4
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
col - i >= 0 &&
|
|
|
|
col - i >= 0 &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 1][col - i + 1] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 1][col - i + 1] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 2][col - i + 2] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 2][col - i + 2] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 3][col - i + 3] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 3][col - i + 3] &&
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 4][col - i + 4])
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 4][col - i + 4])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setlinecolor(RED);
|
|
|
|
setlinecolor(RED);
|
|
|
|
line(margin_x + (col - i) * chessSize, margin_y + (row - i) * chessSize, margin_x + (col - i + 4) * chessSize, margin_y + (row - i + 4) * chessSize);
|
|
|
|
line(margin_x + (col - i) * chessSize, margin_y + (row - i) * chessSize, margin_x + (col - i + 4) * chessSize, margin_y + (row - i + 4) * chessSize);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Chess::checkOver()
|
|
|
|
bool Chess::checkOver()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (checkWin())
|
|
|
|
if (checkWin())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Sleep(3000);
|
|
|
|
Sleep(3000);
|
|
|
|
//赢棋
|
|
|
|
//<EFBFBD>0â6„1¤7„1¤7
|
|
|
|
if (!playerFlag)
|
|
|
|
if (!playerFlag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
loadimage(0, "graphics/win.jpg",400,400,true);
|
|
|
|
loadimage(0, "win.jpg",400,400,true);//¸ü¸Ä·¾¶
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//失败
|
|
|
|
//<EFBFBD>0´2„1¤7„1¤7
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
loadimage(0, "graphics/fail.png", 400, 400, true);
|
|
|
|
loadimage(0, "fail.png", 400, 400, true);//¸ü¸Ä·¾¶
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Sleep(5000);
|
|
|
|
Sleep(5000);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Chess::getChessData(ChessPos* pos)
|
|
|
|
int Chess::getChessData(ChessPos* pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return chessMap[pos->row][pos->col];
|
|
|
|
return chessMap[pos->row][pos->col];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Chess::getChessData(int row, int col)
|
|
|
|
int Chess::getChessData(int row, int col)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return chessMap[row][col];
|
|
|
|
return chessMap[row][col];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Chess::updateGameMap(ChessPos* pos)
|
|
|
|
void Chess::updateGameMap(ChessPos* pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lastPos = *pos;
|
|
|
|
lastPos = *pos;
|
|
|
|
chessMap[pos->row][pos->col] = playerFlag ? CHESS_BLACK : CHESS_WHITE;
|
|
|
|
chessMap[pos->row][pos->col] = playerFlag ? CHESS_BLACK : CHESS_WHITE;
|
|
|
|
playerFlag = !playerFlag;//换方
|
|
|
|
playerFlag = !playerFlag;//„1¤7„1¤7„1¤7„1¤7
|
|
|
|
}
|
|
|
|
}
|