📄 globalfun.cpp
字号:
LineTo(hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE );
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y+ SQUARE_SIZE /2, NULL );
LineTo(hDC, p.x +SQUARE_SIZE , p.y +SQUARE_SIZE);
}
if ((rank==9)&&(line==5))
{
MoveToEx( hDC, p.x + SQUARE_SIZE , p.y + SQUARE_SIZE /2, NULL );
LineTo(hDC, p.x ,p.y+SQUARE_SIZE/2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE );
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2 , NULL);
LineTo(hDC, p.x , p.y +SQUARE_SIZE);
}
if ((rank==9)&&(line==0))
{
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y +SQUARE_SIZE/2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE );
}
if ((rank==9)&&(line==8))
{
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2 , p.y +SQUARE_SIZE);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x , p.y + SQUARE_SIZE/2 );
}
if ((rank==0)&&(line==8))
{
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2 , p.y );
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x , p.y + SQUARE_SIZE/2 );
}
if (rank==5)
if ((line==1)||(line==2)||(line==3)||(line==4)||(line==5)||(line==6)||(line==7))
{
MoveToEx( hDC, p.x , p.y+ SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y +SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE /2, p.y );
}
if (rank==4) //第五行
if ((line==1)||(line==2)||(line==3)||(line==4)||(line==5)||(line==6)||(line==7))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2 , NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y +SQUARE_SIZE/2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x + SQUARE_SIZE /2 , p.y + SQUARE_SIZE );
}
if ((rank==1)|| (rank==8))
if ((line==1)||(line==2)||(line==3)||(line==5)||(line==6)||(line==7))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y , NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
}
if ((rank==1)||(rank==8))
if (line==4)
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x , p.y, NULL );
LineTo(hDC, p.x+SQUARE_SIZE , p.y + SQUARE_SIZE );
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE, NULL);
LineTo(hDC, p.x +SQUARE_SIZE, p.y );
}
if ((rank==2) || (rank==7))
if ((line==1) ||(line==7))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y , NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*3/8 , p.y + SQUARE_SIZE/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/8 , p.y + SQUARE_SIZE*3/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*5/8 , p.y + SQUARE_SIZE/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*7/8 , p.y + SQUARE_SIZE*3/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/8 , p.y + SQUARE_SIZE*5/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*3/8 , p.y + SQUARE_SIZE*7/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*7/8 , p.y + SQUARE_SIZE*5/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*5/8 , p.y + SQUARE_SIZE*7/8 );
}
if ((rank==3) || (rank==6))
if ((line==2) ||(line==4)||(line==6))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL );
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*3/8 , p.y + SQUARE_SIZE/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/8 , p.y + SQUARE_SIZE*3/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*5/8 , p.y + SQUARE_SIZE/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*3/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*7/8 , p.y + SQUARE_SIZE*3/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/8 , p.y + SQUARE_SIZE*5/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*3/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*3/8 , p.y + SQUARE_SIZE*7/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*7/8 , p.y + SQUARE_SIZE*5/8 );
MoveToEx( hDC, p.x +SQUARE_SIZE*5/8, p.y +SQUARE_SIZE*5/8, NULL);
LineTo(hDC, p.x +SQUARE_SIZE*5/8 , p.y + SQUARE_SIZE*7/8 );
}
if (rank==7) //第八行
if ((line==2)||(line==4)||(line==6))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y , NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
}
if ((rank==7)&&(line==3))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y , NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y +SQUARE_SIZE/2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE, p.y );
}
if ((rank==7)&&(line==5))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL );
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y +SQUARE_SIZE/2, NULL);
LineTo(hDC, p.x , p.y );
}
if (rank==2) //第三行
if ((line==2)||(line==4)||(line==6))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL );
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
}
if ((rank==2)&&(line==3))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y +SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE, p.y + SQUARE_SIZE);
}
if ((rank==2)&&(line==5))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL );
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y +SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x , p.y + SQUARE_SIZE);
}
if (rank==6) //第七行
if ((line==1)||(line==3)||(line==5)||(line==7))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y , NULL);
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
}
if (rank==3) //第四行
if ((line==1)||(line==3)||(line==5)||(line==7))
{
MoveToEx( hDC, p.x , p.y + SQUARE_SIZE /2, NULL);
LineTo(hDC, p.x +SQUARE_SIZE , p.y + SQUARE_SIZE /2);
MoveToEx( hDC, p.x + SQUARE_SIZE /2 , p.y, NULL );
LineTo(hDC, p.x +SQUARE_SIZE/2, p.y + SQUARE_SIZE);
}
SelectObject(hDC, hOldBrush);
ReleaseDC(Application->MainForm->Handle, hDC);
}
void ClearDisplay()
{
SQUARETYPE sq;
ClearInfoWindow();
for (sq = 0; sq <= 0x98; sq++)
Display[sq].piece = empty;
}
/*
在屏幕上显示棋盘10行9列,如0x78表示第八行第九列
*/
void DrawChessBoard()
{
unsigned char no;
HDC hDC;
const SQUARETYPE printno[90] = { 0, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,0x90,
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
0x88, 0x78, 0x68, 0x58, 0x48, 0x38, 0x28, 0x18,
8, 7, 6, 5, 4, 3, 2, 1,
0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, 0x81,
0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x77, 0x67, 0x57, 0x47, 0x37, 0x27, 0x17,
0x16, 0x15, 0x14, 0x13, 0x12,
0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
0x73, 0x74, 0x75, 0x76,
0x66, 0x56, 0x46, 0x36, 0x26,
0x25, 0x24, 0x23,
0x33, 0x43, 0x53, 0x63,
0x64, 0x65,
0x55, 0x45, 0x35,
0x34, 0x44, 0x54};
ChessBoardRect.left = BORDERSIZE;
ChessBoardRect.top = 2.5* BORDERSIZE + 5;
ChessBoardRect.right = BORDERSIZE + (2 * MYFRAMESIZE) + (9 * SQUARE_SIZE);
ChessBoardRect.bottom = BORDERSIZE + (2 * MYFRAMESIZE) + (11 * SQUARE_SIZE)-3;
hDC = GetDC(MainForm->Handle);
DrawFrame(hDC, ChessBoardRect);
ReleaseDC(MainForm->Handle, hDC);
for (no = 0; no < 90; no++)
ClearSquare(printno[no]);
}
/*
显示棋子
*/
void PrintPiece(SQUARETYPE square, PIECETYPE piece, COLORTYPE color, DWORD Rop)
{
HBITMAP hBitmap, hOldBmp, hMaskBmp;
BITMAP Bitmap;
HDC hMemoryDC, hDC;
POINT p;
if (piece == empty)
return;
hBitmap = PieceBmpArray[piece-1][color];
hMaskBmp = MaskArray[piece-1];
hDC = GetDC(MainForm->Handle);
hMemoryDC = CreateCompatibleDC(hDC);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &Bitmap);
hOldBmp = (HBITMAP)SelectObject(hMemoryDC, hMaskBmp);
p = GetSquareXY(square);
BitBlt(hDC, p.x, p.y , Bitmap.bmWidth, Bitmap.bmHeight,
hMemoryDC, 0, 0, SRCAND);
SelectObject(hMemoryDC, hBitmap);
BitBlt(hDC, p.x, p.y , Bitmap.bmWidth, Bitmap.bmHeight,
hMemoryDC, 0, 0, Rop);
SelectObject(hMemoryDC, hOldBmp);
DeleteDC(hMemoryDC);
ReleaseDC(MainForm->Handle, hDC);
}
/*
初始化显示
*/
void InitDisplay()
{
SQUARETYPE square;
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
if ((ChessBoard[square].piece != Display[square].piece) ||
(ChessBoard[square].piece != empty) && (ChessBoard[square].color !=
Display[square].color))
{
Display[square].piece = ChessBoard[square].piece;
Display[square].color = ChessBoard[square].color;
}
}
/*
在受攻击的棋子边上画一个矩形框
如果受到攻击又没有保护的话,显示红框
如果受到攻击但有保护的话,显示黑框
*/
static void FrameSquare(SQUARETYPE square, bool Defended)
{
POINT p;
HPEN hOldPen;
HBRUSH hOldBrush;
HDC hDC;
hDC = GetDC(MainForm->Handle);
p = GetSquareXY(square);
hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
if (Defended)
hOldPen = (HPEN)SelectObject(hDC, GetStockObject(BLACK_PEN));
else
hOldPen = (HPEN)SelectObject(hDC, CreatePen(PS_SOLID,1,RGB(192, 0, 0)));
Rectangle(hDC, p.x+1, p.y+1, p.x+SQUARE_SIZE-4, p.y+SQUARE_SIZE-1);
SelectObject(hDC, hOldBrush);
if (Defended)
SelectObject(hDC, hOldPen);
else
DeleteObject(SelectObject(hDC, hOldPen));
ReleaseDC(MainForm->Handle, hDC);
}
/*
对受到攻击的棋子隐藏边框
*/
void HideAttacks(void)
{
SQUARETYPE square;
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
{
if (ChessBoard[square].attacked == true)
{
ChessBoard[square].attacked = false;
ClearSquare(square);
PrintPiece(square, ChessBoard[square].piece,
ChessBoard[square].color, SRCINVERT);
}
}
}
/*
对受到攻击的棋子显示边框
*/
void ShowAttacks()
{
SQUARETYPE square;
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
{
if (Attacks(ComputerColor, square) && ChessBoard[square].color != ComputerColor && ChessBoard[square].piece != empty)
{
ChessBoard[square].attacked = true;
if (Attacks((COLORTYPE)!ComputerColor, square))
FrameSquare(square, true);
else
FrameSquare(square, false);
}
else if (ChessBoard[square].attacked == true)
{
ChessBoard[square].attacked = false;
ClearSquare(square);
PrintPiece(square, ChessBoard[square].piece,
ChessBoard[square].color, SRCINVERT);
}
}
}
/*
根据选项重画棋盘
*/
void UpdateChessBoard()
{
SQUARETYPE square;
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
if ((ChessBoard[square].piece != Display[square].piece) ||
(ChessBoard[square].piece != empty) && (ChessBoard[square].color !=
Display[square].color))
{
if (Display[square].piece != empty)
ClearSquare(square);
Display[square].piece = ChessBoard[square].piece;
Display[square].color = ChessBoard[square].color;
if (ChessBoard[square].piece != empty)
PrintPiece(square, ChessBoard[square].piece,
ChessBoard[square].color, SRCINVERT);
}
if (Level == easygame && !Editing)
ShowAttacks();
}
static void DrawAlphaNum();
/*
打印棋盘。包括棋盘、棋子、记录棋子位置的行列数字。
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -