完善运行链路 调整中文界面
This commit is contained in:
+108
-2
@@ -3,6 +3,8 @@
|
||||
#include "Tetris.h"
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
#define GAME_TIMER_ID 1
|
||||
#define GAME_TIMER_INTERVAL 500
|
||||
|
||||
HINSTANCE hInst;
|
||||
TCHAR szTitle[MAX_LOADSTRING];
|
||||
@@ -31,6 +33,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
|
||||
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING);
|
||||
lstrcpy(szTitle, _T("俄罗斯方块"));
|
||||
MyRegisterClass(hInstance);
|
||||
|
||||
if (!InitInstance(hInstance, nCmdShow))
|
||||
@@ -126,8 +129,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
/**
|
||||
* @brief 主窗口消息处理函数,负责响应菜单、绘制和退出等系统消息。
|
||||
*
|
||||
* 当前阶段主要处理“关于”和“退出”菜单命令、窗口重绘请求以及销毁消息,
|
||||
* 其余未处理的消息统一交给系统默认窗口过程继续处理。
|
||||
* 该函数除菜单和绘制外,还负责初始化游戏、处理定时下落、
|
||||
* 响应键盘操作以及管理暂停、重开和游戏结束状态。
|
||||
*
|
||||
* @param hWnd 当前窗口句柄。
|
||||
* @param message 当前接收到的消息类型。
|
||||
@@ -139,6 +142,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_CREATE:
|
||||
srand((unsigned int)time(nullptr));
|
||||
Restart();
|
||||
SetTimer(hWnd, GAME_TIMER_ID, GAME_TIMER_INTERVAL, nullptr);
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
@@ -156,6 +165,101 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_TIMER:
|
||||
if (wParam == GAME_TIMER_ID && !suspendFlag && !gameOverFlag)
|
||||
{
|
||||
if (CanMoveDown())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
Fixing();
|
||||
DeleteLines();
|
||||
gameOverFlag = GameOver();
|
||||
}
|
||||
|
||||
if (!gameOverFlag)
|
||||
{
|
||||
ComputeTarget();
|
||||
}
|
||||
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
if (wParam == 'R')
|
||||
{
|
||||
Restart();
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (wParam == 'P')
|
||||
{
|
||||
suspendFlag = !suspendFlag;
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (wParam == 'G')
|
||||
{
|
||||
targetFlag = !targetFlag;
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (gameOverFlag || suspendFlag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_LEFT:
|
||||
if (CanMoveLeft())
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
if (CanMoveRight())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
break;
|
||||
case VK_DOWN:
|
||||
if (CanMoveDown())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
Fixing();
|
||||
DeleteLines();
|
||||
gameOverFlag = GameOver();
|
||||
}
|
||||
break;
|
||||
case VK_UP:
|
||||
Rotate();
|
||||
break;
|
||||
case VK_SPACE:
|
||||
DropDown();
|
||||
Fixing();
|
||||
DeleteLines();
|
||||
gameOverFlag = GameOver();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!gameOverFlag)
|
||||
{
|
||||
ComputeTarget();
|
||||
}
|
||||
|
||||
InvalidateRect(hWnd, nullptr, TRUE);
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
@@ -165,6 +269,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
KillTimer(hWnd, GAME_TIMER_ID);
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
@@ -193,6 +298,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
SetWindowText(hDlg, _T("关于俄罗斯方块"));
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
|
||||
Reference in New Issue
Block a user