diff --git a/image.png b/image.png new file mode 100644 index 0000000..e0526fb Binary files /dev/null and b/image.png differ diff --git a/src/include/Tetris.h b/src/include/Tetris.h index 2a157b9..c8b0c72 100644 --- a/src/include/Tetris.h +++ b/src/include/Tetris.h @@ -11,6 +11,11 @@ constexpr int nGameWidth = 10; constexpr int nGameHeight = 20; constexpr int nWidth = 16; constexpr int nHeight = 22; +constexpr int WINDOW_PADDING = 28; +constexpr int SIDE_PANEL_WIDTH = 320; +constexpr int SIDE_PANEL_GAP = 28; +constexpr int WINDOW_CLIENT_WIDTH = WINDOW_PADDING * 2 + nGameWidth * GRID + SIDE_PANEL_GAP + SIDE_PANEL_WIDTH; +constexpr int WINDOW_CLIENT_HEIGHT = WINDOW_PADDING * 2 + nGameHeight * GRID + 20; // 定义一个点,用来表示方块的位置 struct Point diff --git a/src/source/Tetris.cpp b/src/source/Tetris.cpp index 41bc0b8..60529bd 100644 --- a/src/source/Tetris.cpp +++ b/src/source/Tetris.cpp @@ -31,6 +31,19 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); + HMODULE user32Module = GetModuleHandle(_T("user32.dll")); + if (user32Module != nullptr) + { + typedef BOOL(WINAPI* SetProcessDPIAwareFunc)(); + SetProcessDPIAwareFunc setProcessDPIAware = + (SetProcessDPIAwareFunc)GetProcAddress(user32Module, "SetProcessDPIAware"); + + if (setProcessDPIAware != nullptr) + { + setProcessDPIAware(); + } + } + LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING); lstrcpy(szTitle, _T("俄罗斯方块")); @@ -97,7 +110,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance) */ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { - RECT rect = { 0, 0, GRID * nWidth, GRID * nHeight }; + RECT rect = { 0, 0, WINDOW_CLIENT_WIDTH, WINDOW_CLIENT_HEIGHT }; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, TRUE); hInst = hInstance; @@ -146,7 +159,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) srand((unsigned int)time(nullptr)); Restart(); SetTimer(hWnd, GAME_TIMER_ID, GAME_TIMER_INTERVAL, nullptr); - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); break; case WM_COMMAND: { @@ -184,28 +197,28 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ComputeTarget(); } - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); } break; case WM_KEYDOWN: if (wParam == 'R') { Restart(); - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); break; } if (wParam == 'P') { suspendFlag = !suspendFlag; - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); break; } if (wParam == 'G') { targetFlag = !targetFlag; - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); break; } @@ -258,13 +271,37 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ComputeTarget(); } - InvalidateRect(hWnd, nullptr, TRUE); + InvalidateRect(hWnd, nullptr, FALSE); break; + case WM_ERASEBKGND: + return 1; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); - TDrawScreen(hdc, hWnd); + RECT clientRect; + GetClientRect(hWnd, &clientRect); + + HDC memDC = CreateCompatibleDC(hdc); + HBITMAP memBitmap = CreateCompatibleBitmap( + hdc, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top); + HBITMAP oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap); + + TDrawScreen(memDC, hWnd); + BitBlt( + hdc, + 0, 0, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top, + memDC, + 0, 0, + SRCCOPY); + + SelectObject(memDC, oldBitmap); + DeleteObject(memBitmap); + DeleteDC(memDC); EndPaint(hWnd, &ps); } break; diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index e7a106d..51e0624 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -60,13 +60,13 @@ int bricks[7][4][4][4] = COLORREF BrickColor[7] = { - RGB(255, 0, 0), - RGB(0, 255, 0), - RGB(0, 0, 255), - RGB(0, 255, 255), - RGB(255, 150, 0), - RGB(255, 255, 0), - RGB(168, 0, 168) + RGB(244, 144, 165), + RGB(255, 181, 197), + RGB(170, 215, 255), + RGB(134, 230, 220), + RGB(255, 187, 143), + RGB(255, 223, 146), + RGB(197, 170, 255) }; /** diff --git a/src/source/TetrisRender.cpp b/src/source/TetrisRender.cpp index a8763df..6763198 100644 --- a/src/source/TetrisRender.cpp +++ b/src/source/TetrisRender.cpp @@ -16,34 +16,119 @@ void TDrawScreen(HDC hdc, HWND hWnd) RECT clientRect; GetClientRect(hWnd, &clientRect); - HBRUSH backgroundBrush = CreateSolidBrush(RGB(245, 245, 245)); - FillRect(hdc, &clientRect, backgroundBrush); - DeleteObject(backgroundBrush); - - RECT gameRect = + const RECT gameRect = { - GRID, - GRID, - GRID + nGameWidth * GRID, - GRID + nGameHeight * GRID + WINDOW_PADDING, + WINDOW_PADDING, + WINDOW_PADDING + nGameWidth * GRID, + WINDOW_PADDING + nGameHeight * GRID }; + const RECT panelRect = + { + gameRect.right + SIDE_PANEL_GAP, + WINDOW_PADDING, + gameRect.right + SIDE_PANEL_GAP + SIDE_PANEL_WIDTH, + WINDOW_PADDING + nGameHeight * GRID + }; + + const COLORREF pageColor = RGB(255, 244, 248); + const COLORREF blobColorA = RGB(255, 230, 238); + const COLORREF blobColorB = RGB(250, 221, 233); + const COLORREF cardColor = RGB(255, 252, 253); + const COLORREF boardColor = RGB(70, 57, 78); + const COLORREF boardInnerColor = RGB(54, 44, 62); + const COLORREF lineColor = RGB(104, 90, 116); + const COLORREF frameColor = RGB(212, 168, 188); + const COLORREF titleColor = RGB(104, 62, 84); + const COLORREF textColor = RGB(92, 73, 88); + const COLORREF accentColor = RGB(228, 145, 182); + + HBRUSH pageBrush = CreateSolidBrush(pageColor); + FillRect(hdc, &clientRect, pageBrush); + DeleteObject(pageBrush); + + // 绘制淡粉背景装饰 + HBRUSH blobBrushA = CreateSolidBrush(blobColorA); + HBRUSH blobBrushB = CreateSolidBrush(blobColorB); + HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, blobBrushA); + HPEN oldPen = (HPEN)SelectObject(hdc, GetStockObject(NULL_PEN)); + Ellipse(hdc, clientRect.right - 260, -20, clientRect.right + 80, 260); + Ellipse(hdc, -80, clientRect.bottom - 200, 220, clientRect.bottom + 70); + SelectObject(hdc, blobBrushB); + Ellipse(hdc, clientRect.right - 180, clientRect.bottom - 220, clientRect.right + 120, clientRect.bottom + 40); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); + DeleteObject(blobBrushA); + DeleteObject(blobBrushB); + + // 创建中文清晰字体 + HFONT titleFont = CreateFont( + -34, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, + DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, + VARIABLE_PITCH, _T("Microsoft YaHei UI")); + + HFONT sectionFont = CreateFont( + -24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, + DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, + VARIABLE_PITCH, _T("Microsoft YaHei UI")); + + HFONT bodyFont = CreateFont( + -20, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, + DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, + VARIABLE_PITCH, _T("Microsoft YaHei UI")); + + HFONT smallFont = CreateFont( + -17, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, + DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, + VARIABLE_PITCH, _T("Microsoft YaHei UI")); + + SetBkMode(hdc, TRANSPARENT); + SetTextColor(hdc, textColor); + + // 绘制主卡片和侧边栏卡片 + HPEN framePen = CreatePen(PS_SOLID, 1, frameColor); + HBRUSH gameCardBrush = CreateSolidBrush(cardColor); + HBRUSH panelBrush = CreateSolidBrush(cardColor); + oldPen = (HPEN)SelectObject(hdc, framePen); + oldBrush = (HBRUSH)SelectObject(hdc, gameCardBrush); + RoundRect(hdc, gameRect.left - 10, gameRect.top - 10, gameRect.right + 10, gameRect.bottom + 10, 28, 28); + SelectObject(hdc, panelBrush); + RoundRect(hdc, panelRect.left, panelRect.top, panelRect.right, panelRect.bottom, 30, 30); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); + DeleteObject(gameCardBrush); + DeleteObject(panelBrush); + DeleteObject(framePen); + // 绘制游戏区背景 - HBRUSH gameBrush = CreateSolidBrush(RGB(30, 30, 30)); - FillRect(hdc, &gameRect, gameBrush); - DeleteObject(gameBrush); + HBRUSH boardBrush = CreateSolidBrush(boardColor); + FillRect(hdc, &gameRect, boardBrush); + DeleteObject(boardBrush); + + RECT innerRect = + { + gameRect.left + 6, + gameRect.top + 6, + gameRect.right - 6, + gameRect.bottom - 6 + }; + + HBRUSH innerBrush = CreateSolidBrush(boardInnerColor); + FillRect(hdc, &innerRect, innerBrush); + DeleteObject(innerBrush); // 绘制游戏区边框 - HPEN borderPen = CreatePen(PS_SOLID, 2, RGB(80, 80, 80)); - HPEN oldPen = (HPEN)SelectObject(hdc, borderPen); - HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); - Rectangle(hdc, gameRect.left, gameRect.top, gameRect.right, gameRect.bottom); + HPEN borderPen = CreatePen(PS_SOLID, 2, RGB(132, 108, 146)); + oldPen = (HPEN)SelectObject(hdc, borderPen); + oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); + RoundRect(hdc, gameRect.left, gameRect.top, gameRect.right, gameRect.bottom, 18, 18); SelectObject(hdc, oldBrush); SelectObject(hdc, oldPen); DeleteObject(borderPen); // 绘制网格线 - HPEN gridPen = CreatePen(PS_SOLID, 1, RGB(55, 55, 55)); + HPEN gridPen = CreatePen(PS_SOLID, 1, lineColor); oldPen = (HPEN)SelectObject(hdc, gridPen); for (int i = 1; i < nGameWidth; i++) @@ -73,15 +158,21 @@ void TDrawScreen(HDC hdc, HWND hWnd) int colorIndex = workRegion[i][j] - 1; RECT brickRect = { - gameRect.left + j * GRID + 1, - gameRect.top + i * GRID + 1, - gameRect.left + (j + 1) * GRID - 1, - gameRect.top + (i + 1) * GRID - 1 + gameRect.left + j * GRID + 2, + gameRect.top + i * GRID + 2, + gameRect.left + (j + 1) * GRID - 2, + gameRect.top + (i + 1) * GRID - 2 }; HBRUSH brickBrush = CreateSolidBrush(BrickColor[colorIndex]); - FillRect(hdc, &brickRect, brickBrush); + HPEN brickPen = CreatePen(PS_SOLID, 1, RGB(255, 248, 250)); + oldPen = (HPEN)SelectObject(hdc, brickPen); + oldBrush = (HBRUSH)SelectObject(hdc, brickBrush); + RoundRect(hdc, brickRect.left, brickRect.top, brickRect.right, brickRect.bottom, 10, 10); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); DeleteObject(brickBrush); + DeleteObject(brickPen); } } } @@ -89,7 +180,7 @@ void TDrawScreen(HDC hdc, HWND hWnd) // 绘制预测落点 if (targetFlag) { - HPEN targetPen = CreatePen(PS_DOT, 1, RGB(220, 220, 220)); + HPEN targetPen = CreatePen(PS_DOT, 2, RGB(255, 240, 245)); oldPen = (HPEN)SelectObject(hdc, targetPen); oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); @@ -104,12 +195,13 @@ void TDrawScreen(HDC hdc, HWND hWnd) if (drawY >= 0 && drawY < nGameHeight && drawX >= 0 && drawX < nGameWidth) { - Rectangle( + RoundRect( hdc, - gameRect.left + drawX * GRID + 4, - gameRect.top + drawY * GRID + 4, - gameRect.left + (drawX + 1) * GRID - 4, - gameRect.top + (drawY + 1) * GRID - 4); + gameRect.left + drawX * GRID + 5, + gameRect.top + drawY * GRID + 5, + gameRect.left + (drawX + 1) * GRID - 5, + gameRect.top + (drawY + 1) * GRID - 5, + 8, 8); } } } @@ -134,59 +226,64 @@ void TDrawScreen(HDC hdc, HWND hWnd) { RECT brickRect = { - gameRect.left + drawX * GRID + 1, - gameRect.top + drawY * GRID + 1, - gameRect.left + (drawX + 1) * GRID - 1, - gameRect.top + (drawY + 1) * GRID - 1 + gameRect.left + drawX * GRID + 2, + gameRect.top + drawY * GRID + 2, + gameRect.left + (drawX + 1) * GRID - 2, + gameRect.top + (drawY + 1) * GRID - 2 }; HBRUSH brickBrush = CreateSolidBrush(BrickColor[type]); - FillRect(hdc, &brickRect, brickBrush); + HPEN brickPen = CreatePen(PS_SOLID, 1, RGB(255, 250, 252)); + oldPen = (HPEN)SelectObject(hdc, brickPen); + oldBrush = (HBRUSH)SelectObject(hdc, brickBrush); + RoundRect(hdc, brickRect.left, brickRect.top, brickRect.right, brickRect.bottom, 12, 12); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); DeleteObject(brickBrush); + DeleteObject(brickPen); } } } } // 绘制右侧信息面板 - SetBkMode(hdc, TRANSPARENT); - SetTextColor(hdc, RGB(40, 40, 40)); + HFONT oldFont = (HFONT)SelectObject(hdc, titleFont); + SetTextColor(hdc, titleColor); + TextOut(hdc, panelRect.left + 24, panelRect.top + 22, _T("俄罗斯方块"), lstrlen(_T("俄罗斯方块"))); - RECT infoRect = - { - gameRect.right + GRID, - gameRect.top, - clientRect.right - GRID, - gameRect.bottom - }; + HPEN accentPen = CreatePen(PS_SOLID, 3, accentColor); + oldPen = (HPEN)SelectObject(hdc, accentPen); + MoveToEx(hdc, panelRect.left + 24, panelRect.top + 68, nullptr); + LineTo(hdc, panelRect.left + 160, panelRect.top + 68); + SelectObject(hdc, oldPen); + DeleteObject(accentPen); - DrawText(hdc, _T("俄罗斯方块"), -1, &infoRect, DT_TOP | DT_LEFT | DT_SINGLELINE); + SelectObject(hdc, sectionFont); + SetTextColor(hdc, textColor); TCHAR scoreText[64]; - _stprintf_s(scoreText, _T("当前得分:%d"), tScore); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 2, scoreText, lstrlen(scoreText)); + _stprintf_s(scoreText, _T("当前得分 %d"), tScore); + TextOut(hdc, panelRect.left + 24, panelRect.top + 104, scoreText, lstrlen(scoreText)); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 4, _T("下一个方块:"), lstrlen(_T("下一个方块:"))); + TextOut(hdc, panelRect.left + 24, panelRect.top + 172, _T("下一个方块"), lstrlen(_T("下一个方块"))); - RECT nextRect = + RECT nextCard = { - infoRect.left, - infoRect.top + GRID * 5, - infoRect.left + GRID * 4, - infoRect.top + GRID * 9 + panelRect.left + 24, + panelRect.top + 210, + panelRect.left + 24 + GRID * 4 + 32, + panelRect.top + 210 + GRID * 4 + 32 }; - HBRUSH nextBackBrush = CreateSolidBrush(RGB(220, 220, 220)); - FillRect(hdc, &nextRect, nextBackBrush); - DeleteObject(nextBackBrush); - - HPEN nextBorderPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120)); - oldPen = (HPEN)SelectObject(hdc, nextBorderPen); - oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); - Rectangle(hdc, nextRect.left, nextRect.top, nextRect.right, nextRect.bottom); + HBRUSH nextCardBrush = CreateSolidBrush(RGB(255, 238, 244)); + HPEN nextCardPen = CreatePen(PS_SOLID, 1, RGB(233, 191, 208)); + oldPen = (HPEN)SelectObject(hdc, nextCardPen); + oldBrush = (HBRUSH)SelectObject(hdc, nextCardBrush); + RoundRect(hdc, nextCard.left, nextCard.top, nextCard.right, nextCard.bottom, 22, 22); SelectObject(hdc, oldBrush); SelectObject(hdc, oldPen); - DeleteObject(nextBorderPen); + DeleteObject(nextCardBrush); + DeleteObject(nextCardPen); // 绘制下一方块预览 for (int i = 0; i < 4; i++) @@ -197,44 +294,90 @@ void TDrawScreen(HDC hdc, HWND hWnd) { RECT brickRect = { - nextRect.left + j * GRID, - nextRect.top + i * GRID, - nextRect.left + (j + 1) * GRID, - nextRect.top + (i + 1) * GRID + nextCard.left + 16 + j * GRID, + nextCard.top + 16 + i * GRID, + nextCard.left + 16 + (j + 1) * GRID - 2, + nextCard.top + 16 + (i + 1) * GRID - 2 }; HBRUSH brickBrush = CreateSolidBrush(BrickColor[nType]); - FillRect(hdc, &brickRect, brickBrush); + HPEN brickPen = CreatePen(PS_SOLID, 1, RGB(255, 248, 250)); + oldPen = (HPEN)SelectObject(hdc, brickPen); + oldBrush = (HBRUSH)SelectObject(hdc, brickBrush); + RoundRect(hdc, brickRect.left, brickRect.top, brickRect.right, brickRect.bottom, 10, 10); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); DeleteObject(brickBrush); + DeleteObject(brickPen); } } } - TextOut(hdc, infoRect.left, infoRect.top + GRID * 11, _T("操作说明:"), lstrlen(_T("操作说明:"))); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 12, _T("方向键:移动 / 旋转"), lstrlen(_T("方向键:移动 / 旋转"))); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 13, _T("空格:快速下落"), lstrlen(_T("空格:快速下落"))); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 14, _T("P:暂停 R:重开"), lstrlen(_T("P:暂停 R:重开"))); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 15, _T("G:显示/隐藏落点"), lstrlen(_T("G:显示/隐藏落点"))); + SelectObject(hdc, sectionFont); + TextOut(hdc, panelRect.left + 24, panelRect.top + 390, _T("操作提示"), lstrlen(_T("操作提示"))); - if (suspendFlag) - { - SetTextColor(hdc, RGB(220, 120, 0)); - TextOut(hdc, infoRect.left, infoRect.top + GRID * 17, _T("游戏已暂停"), lstrlen(_T("游戏已暂停"))); - SetTextColor(hdc, RGB(40, 40, 40)); - } + SelectObject(hdc, bodyFont); + TextOut(hdc, panelRect.left + 24, panelRect.top + 432, _T("方向键:移动 / 旋转"), lstrlen(_T("方向键:移动 / 旋转"))); + TextOut(hdc, panelRect.left + 24, panelRect.top + 468, _T("空格:快速下落"), lstrlen(_T("空格:快速下落"))); + TextOut(hdc, panelRect.left + 24, panelRect.top + 504, _T("P:暂停 R:重新开始"), lstrlen(_T("P:暂停 R:重新开始"))); + TextOut(hdc, panelRect.left + 24, panelRect.top + 540, _T("G:显示 / 隐藏落点"), lstrlen(_T("G:显示 / 隐藏落点"))); - if (gameOverFlag) + if (suspendFlag || gameOverFlag) { - RECT overRect = gameRect; - SetTextColor(hdc, RGB(255, 80, 80)); - DrawText(hdc, _T("游戏结束"), -1, &overRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); - RECT tipRect = + RECT overlayRect = { - gameRect.left, - gameRect.top + GRID * 11, - gameRect.right, + gameRect.left + GRID, + gameRect.top + GRID * 6, + gameRect.right - GRID, gameRect.top + GRID * 13 }; - DrawText(hdc, _T("按 R 键重新开始"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + + HBRUSH overlayBrush = CreateSolidBrush(RGB(255, 241, 246)); + HPEN overlayPen = CreatePen(PS_SOLID, 2, RGB(232, 170, 194)); + oldPen = (HPEN)SelectObject(hdc, overlayPen); + oldBrush = (HBRUSH)SelectObject(hdc, overlayBrush); + RoundRect(hdc, overlayRect.left, overlayRect.top, overlayRect.right, overlayRect.bottom, 26, 26); + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); + DeleteObject(overlayBrush); + DeleteObject(overlayPen); + + RECT titleRect = + { + overlayRect.left, + overlayRect.top + GRID, + overlayRect.right, + overlayRect.top + GRID * 3 + }; + + RECT tipRect = + { + overlayRect.left + 20, + overlayRect.top + GRID * 3, + overlayRect.right - 20, + overlayRect.bottom - GRID + }; + + SetTextColor(hdc, RGB(121, 76, 99)); + SelectObject(hdc, titleFont); + + if (suspendFlag) + { + DrawText(hdc, _T("游戏已暂停"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + SelectObject(hdc, bodyFont); + DrawText(hdc, _T("按 P 键继续游戏"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + } + else + { + DrawText(hdc, _T("游戏结束"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + SelectObject(hdc, bodyFont); + DrawText(hdc, _T("按 R 键重新开始"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + } } + + SelectObject(hdc, oldFont); + DeleteObject(titleFont); + DeleteObject(sectionFont); + DeleteObject(bodyFont); + DeleteObject(smallFont); }