📄 delphiaicchess.dpr
字号:
program DelphiAICChess;
//{$R 'XQWLIGHT.res' 'XQWLIGHT.RC'}
{$R 'XQWLIGHT.res'}
uses
Windows,
Messages,graphics,sysutils,mmsystem,AICChess;
function MainWndProc (hWindow:HWND;nMsg:UINT;wPrm:WPARAM;lPrm:LPARAM):LRESULT;stdcall;
var
ps:PAINTSTRUCT;
x, y:integer;
hdc:windows.hdc;
rect:TRECT;
begin
case nMsg of
WM_CREATE:
begin
GetWindowRect(hWindow, rect);
rect.right := rect.left + BOARD_WIDTH;
rect.bottom := rect.top + BOARD_HEIGHT;
AdjustWindowRect(rect, WS_OVERLAPPED or WS_SYSMENU or WS_CAPTION or WS_MINIMIZEBOX, TRUE);
MoveWindow(hWindow, (GetSystemMetrics(SM_CXSCREEN) -BOARD_WIDTH) div 2, (GetSystemMetrics(SM_CYSCREEN) -BOARD_HEIGHT) div 2-50, rect.right - rect.left, rect.bottom - rect.top, TRUE);
Result:=0;
Exit;
end;
WM_DESTROY:
begin
PostQuitMessage(0);
Result:=0;
Exit;
end;
WM_PAINT:
begin
hdc := BeginPaint(Xqwl.hWnd, ps);
DrawBoard(hdc);
EndPaint(Xqwl.hWnd, ps);
Result:= 0;
Exit;
end;
WM_SIZE:
begin
Result:= 0;
Exit;
end;
WM_LBUTTONDOWN:
begin
x := FILE_LEFT + (LOWORD(lPrm) - BOARD_EDGE) div SQUARE_SIZE;
y := RANK_TOP + (HIWORD(lPrm) - BOARD_EDGE) div SQUARE_SIZE;
if ((x >= FILE_LEFT) and (x <= FILE_RIGHT) and (y >= RANK_TOP) and (y <= RANK_BOTTOM)) then
begin
ClickSquare(COORD_XY(x, y));
end;
Result:= 0;
Exit;
end;
WM_RBUTTONDOWN:
begin
//按右键看电脑下棋
if Xqwl.bGameOver=true then
begin
Result:= 0;
Exit;
end;
if bend =false then
begin
bend:=true;
Xqwl.bFlipped:=true;
CStartup;
hdc := GetDC(Xqwl.hWnd);
DrawBoard(hdc);
Xqwl.hdc := hdc;
Xqwl.hdcTmp := CreateCompatibleDC(Xqwl.hdc);
ResponseMove();
DeleteDC(Xqwl.hdcTmp);
ReleaseDC(Xqwl.hWnd, hdc);
end
else
begin
hdc := GetDC(Xqwl.hWnd);
DrawBoard(hdc);
Xqwl.hdc := hdc;
Xqwl.hdcTmp := CreateCompatibleDC(Xqwl.hdc);
ResponseMove;
DeleteDC(Xqwl.hdcTmp);
ReleaseDC(Xqwl.hWnd, hdc);
end;
Result:= 0;
Exit;
end;
WM_COMMAND:
begin
OnCommand(wPrm);
Result:= 0;
Exit;
end;
end;
Result:=DefWindowProc (hWindow, nMsg, wPrm, lPrm);
end;
//winmain
var
MyMsg:MSG;
wcex:WNDCLASSEX;
i:integer;
begin
// 初始化全局变量
Xqwl.hInst :=MainInstance; // hInstance;
Xqwl.bFlipped := FALSE;
Xqwl.bGameOver:=false;
CStartup();
// 装入图片
LIMIT_DEPTH:=4;
Xqwl.bmpBoard := LoadResBmp(200); //(IDB_BOARD);
Xqwl.bmpSelected := LoadResBmp(201); //(IDB_SELECTED);
for i := PIECE_KING to PIECE_PAWN do
begin
Xqwl.bmpPieces[SIDE_TAG(0) + i] := LoadResBmp(208 + i);
Xqwl.bmpPieces[SIDE_TAG(1) + i] := LoadResBmp(216 + i);
end;
wcex.cbSize := SizeOf(WNDCLASSEX);
wcex.style :=0; //CS_HREDRAW or CS_VREDRAW;
wcex.lpfnWndProc := @MainWndProc;
wcex.cbClsExtra := 0;
wcex.cbWndExtra := 0;
wcex.hInstance := MainInstance;
wcex.hIcon :=LoadIcon(MainInstance, 'IDIAPPICON'); //LoadIcon (0, IDI_APPLICATION);
wcex.hCursor :=LoadCursor (MainInstance, 'IDCCURSOR'); //LoadCursor (0, IDC_ARROW);
wcex.hbrBackground := HBRUSH(COLOR_WINDOW+1);
wcex.lpszClassName := 'JDYCHESS';
wcex.lpszMenuName := 'IDMMAINMENU';
wcex.hIconSm :=LoadIcon(MainInstance, 'IDIAPPICON'); //LoadIcon (0, IDI_APPLICATION);
RegisterClassEx (wcex);
hWindowMain := CreateWindow (
'JDYCHESS',
'芷江东阳初级AI中国象棋[高级]--开发工具:Borland Delphi 6.0',
WS_OVERLAPPED or WS_SYSMENU or WS_CAPTION or WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
MainInstance,
nil
);
Xqwl.hWnd:=hWindowMain;
ShowWindow(Xqwl.hWnd, CmdShow);
UpdateWindow (Xqwl.hWnd);
while GetMessage (MyMsg, 0, 0, 0)=True do
begin
TranslateMessage (MyMsg);
DispatchMessage (MyMsg);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -