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<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
DWORD* dst = GetImageBuffer(); // GetImageBuffer()<29>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>0<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>0<EFBFBD>1<EFBFBD>7<EFBFBD><37><EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>8<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>3EASYX<59>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7
|
|
|
|
|
DWORD* draw = GetImageBuffer();
|
|
|
|
|
DWORD* src = GetImageBuffer(picture); //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>0picture<72>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>8<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int picture_width = picture->getwidth(); //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>0picture<72>1<EFBFBD>7<EFBFBD>0<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>2<EFBFBD>1<EFBFBD>7EASYX<59>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<E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|
|
|
int srcX = ix + iy * picture_width; //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>3<EFBFBD>0<EFBFBD>5<EFBFBD>0<EFBFBD>3<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA<41>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int sr = ((src[srcX] & 0xff0000) >> 16); //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>0RGB<47>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7R
|
|
|
|
|
int sg = ((src[srcX] & 0xff00) >> 8); //G
|
|
|
|
|
int sb = src[srcX] & 0xff; //B
|
|
|
|
|
if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
|
|
|
|
|
{
|
|
|
|
|
dstX = (ix + x) + (iy + y) * graphWidth; //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>3<EFBFBD>0<EFBFBD>5<EFBFBD>0<EFBFBD>3<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int dr = ((dst[dstX] & 0xff0000) >> 16);
|
|
|
|
|
int dg = ((dst[dstX] & 0xff00) >> 8);
|
|
|
|
|
int db = dst[dstX] & 0xff;
|
|
|
|
|
draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7 Cp=<3D>1<EFBFBD>7<EFBFBD>1<EFBFBD>7p*FP+(1-<2D>1<EFBFBD>7<EFBFBD>1<EFBFBD>7p)*BP <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7 <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7p=sa/255 , FP=sr , BP=dr
|
|
|
|
|
| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7p=sa/255 , FP=sg , BP=dg
|
|
|
|
|
| (sb * sa / 255 + db * (255 - sa) / 255); //<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7p=sa/255 , FP=sb , BP=db
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chess::Chess(int gradeSize, int marginX, int marginY, double chessSize)
|
|
|
|
|
{
|
|
|
|
|
this->gradeSize = gradeSize;
|
|
|
|
|
this->margin_x = marginX;
|
|
|
|
|
this->margin_y = marginY;
|
|
|
|
|
this->chessSize = chessSize;
|
|
|
|
|
playerFlag = CHESS_BLACK;
|
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
|
{
|
|
|
|
|
vector<int>row;
|
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
|
{
|
|
|
|
|
row.push_back(0);
|
|
|
|
|
}
|
|
|
|
|
chessMap.push_back(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Chess::init()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
loadimage(0, "map.png");//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
loadimage(&chessBlackImg, "black.png", chessSize-2, chessSize-2, true);//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
loadimage(&chessWhiteImg, "white.png", chessSize-2, chessSize-2, true);//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
for (int i = 0; i < gradeSize; ++i)
|
|
|
|
|
for (int j = 0; j < gradeSize; ++j)
|
|
|
|
|
chessMap[i][j] = 0;
|
|
|
|
|
playerFlag = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Chess::clickBoard(int x, int y, ChessPos* pos)
|
|
|
|
|
{
|
|
|
|
|
int col = (x - margin_x) / chessSize;
|
|
|
|
|
int row = (y - margin_y) / chessSize;
|
|
|
|
|
int leftTopPosX = margin_x + chessSize * col;
|
|
|
|
|
int leftTopPosY = margin_y + chessSize * row;
|
|
|
|
|
int offset = chessSize * 0.4;
|
|
|
|
|
int len;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
do {
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>1<EFBFBD>1<EFBFBD>7
|
|
|
|
|
len = sqrt((x - leftTopPosX) * (x - leftTopPosX) + (y - leftTopPosY) * (y - leftTopPosY));
|
|
|
|
|
if (len < offset)
|
|
|
|
|
{
|
|
|
|
|
pos->row = row;
|
|
|
|
|
pos->col = col;
|
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>1<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int x2 = leftTopPosX + chessSize;
|
|
|
|
|
int y2 = leftTopPosY;
|
|
|
|
|
len = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
|
|
|
|
if (len < offset)
|
|
|
|
|
{
|
|
|
|
|
pos->row = row;
|
|
|
|
|
pos->col = col+1;
|
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int x3 = leftTopPosX;
|
|
|
|
|
int y3 = leftTopPosY + chessSize;
|
|
|
|
|
len = sqrt((x - x3) * (x - x3) + (y - y3) * (y - y3));
|
|
|
|
|
if (len < offset)
|
|
|
|
|
{
|
|
|
|
|
pos->row = row + 1;
|
|
|
|
|
pos->col = col;
|
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7
|
|
|
|
|
int x4 = leftTopPosX + chessSize;
|
|
|
|
|
int y4 = leftTopPosY + chessSize;
|
|
|
|
|
len = sqrt((x - x4) * (x - x4) + (y - y4) * (y - y4));
|
|
|
|
|
if (len < offset)
|
|
|
|
|
{
|
|
|
|
|
pos->row = row + 1;
|
|
|
|
|
pos->col = col + 1;
|
|
|
|
|
if (chessMap[pos->row][pos->col] == 0)
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Chess::ChessMove(ChessPos* pos, chess_kind_t kind)
|
|
|
|
|
{
|
|
|
|
|
int x = margin_x + chessSize * pos->col - 0.5 * chessSize;
|
|
|
|
|
int y = margin_y + chessSize * pos->row - 0.5 * chessSize;
|
|
|
|
|
|
|
|
|
|
if (kind == CHESS_WHITE)
|
|
|
|
|
putimagePNG(x, y, &chessWhiteImg);
|
|
|
|
|
else
|
|
|
|
|
putimagePNG(x, y, &chessBlackImg);
|
|
|
|
|
|
|
|
|
|
updateGameMap(pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Chess::getGradeSize()
|
|
|
|
|
{
|
|
|
|
|
return gradeSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Chess::checkWin()
|
|
|
|
|
{
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>҄1<D284>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<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|
|
|
|
|
|
//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>8<EFBFBD>0<EFBFBD>9<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
if (col - i >= 0 &&
|
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
|
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 + 3] &&
|
|
|
|
|
chessMap[row][col - i] == chessMap[row][col - i + 4])
|
|
|
|
|
{
|
|
|
|
|
setlinecolor(RED);
|
|
|
|
|
line(margin_x + (col - i) * chessSize, margin_y + (row) * chessSize, margin_x + (col - i + 4) * chessSize, margin_y + (row) * chessSize);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>1<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7(<28>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>74<37>1<EFBFBD>7<EFBFBD>1<EFBFBD>7)
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
|
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 + 3][col] &&
|
|
|
|
|
chessMap[row - i][col] == chessMap[row - i + 4][col])
|
|
|
|
|
{
|
|
|
|
|
setlinecolor(RED);
|
|
|
|
|
line(margin_x + (col) * chessSize, margin_y + (row - i)*chessSize, margin_x + (col) * chessSize, margin_y + (row - i + 4)*chessSize);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7/"<22>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
if (row + i < gradeSize &&
|
|
|
|
|
row + i - 4 >= 0 &&
|
|
|
|
|
col - i >= 0 &&
|
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7[row+i]<5D>1<EFBFBD>7<EFBFBD><37><EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7[col-i]<5D>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>74<37>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4
|
|
|
|
|
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 - 3][col - i + 3] &&
|
|
|
|
|
chessMap[row + i][col - i] == chessMap[row + i - 4][col - i + 4])
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7\<5C>1<EFBFBD>7<EFBFBD>1<EFBFBD>7 <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
// <20>1<EFBFBD>7<EFBFBD>1<EFBFBD>7[row+i]<5D>1<EFBFBD>7<EFBFBD><37><EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7[col-i]<5D>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>5<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD><37><EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>74<37>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>4
|
|
|
|
|
if (row - i >= 0 &&
|
|
|
|
|
row - i + 4 < gradeSize &&
|
|
|
|
|
col - i >= 0 &&
|
|
|
|
|
col - i + 4 < gradeSize &&
|
|
|
|
|
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 + 3][col - i + 3] &&
|
|
|
|
|
chessMap[row - i][col - i] == chessMap[row - i + 4][col - i + 4])
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Chess::checkOver()
|
|
|
|
|
{
|
|
|
|
|
if (checkWin())
|
|
|
|
|
{
|
|
|
|
|
Sleep(3000);
|
|
|
|
|
//<2F>0<EFBFBD>6<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
if (!playerFlag)
|
|
|
|
|
{
|
|
|
|
|
loadimage(0, "win.jpg",400,400,true);//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
}
|
|
|
|
|
//<2F>0<EFBFBD>2<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
loadimage(0, "fail.png", 400, 400, true);//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
}
|
|
|
|
|
Sleep(5000);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Chess::getChessData(ChessPos* pos)
|
|
|
|
|
{
|
|
|
|
|
return chessMap[pos->row][pos->col];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Chess::getChessData(int row, int col)
|
|
|
|
|
{
|
|
|
|
|
return chessMap[row][col];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Chess::updateGameMap(ChessPos* pos)
|
|
|
|
|
{
|
|
|
|
|
lastPos = *pos;
|
|
|
|
|
chessMap[pos->row][pos->col] = playerFlag ? CHESS_BLACK : CHESS_WHITE;
|
|
|
|
|
playerFlag = !playerFlag;//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
|
|
|
|
}
|