添加模式选择开始菜单并修复中文界面乱码
This commit is contained in:
+142
-36
@@ -1,16 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "Tetris.h"
|
||||
|
||||
/**
|
||||
* @brief 完整绘制当前游戏界面。
|
||||
*
|
||||
* 该函数负责绘制窗口背景、游戏工作区边框、网格、已经固定的方块、
|
||||
* 当前活动方块、预测落点、右侧信息面板以及游戏结束提示文字。
|
||||
* 绘制过程只负责根据当前全局游戏状态进行显示,不修改任何游戏逻辑数据。
|
||||
*
|
||||
* @param hdc 当前窗口绘图设备上下文。
|
||||
* @param hWnd 当前窗口句柄,用于获取客户区尺寸。
|
||||
*/
|
||||
void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
{
|
||||
RECT clientRect;
|
||||
@@ -49,7 +39,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
};
|
||||
|
||||
int grid = SS(GRID);
|
||||
int padding = SS(WINDOW_PADDING);
|
||||
int panelGap = SS(SIDE_PANEL_GAP);
|
||||
int panelWidth = SS(SIDE_PANEL_WIDTH);
|
||||
int boardWidth = grid * nGameWidth;
|
||||
@@ -87,7 +76,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
FillRect(hdc, &clientRect, pageBrush);
|
||||
DeleteObject(pageBrush);
|
||||
|
||||
// 绘制淡粉背景装饰
|
||||
HBRUSH blobBrushA = CreateSolidBrush(blobColorA);
|
||||
HBRUSH blobBrushB = CreateSolidBrush(blobColorB);
|
||||
HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, blobBrushA);
|
||||
@@ -101,7 +89,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
DeleteObject(blobBrushA);
|
||||
DeleteObject(blobBrushB);
|
||||
|
||||
// 创建中文清晰字体
|
||||
HFONT titleFont = CreateFont(
|
||||
-SS(34), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
|
||||
DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY,
|
||||
@@ -125,7 +112,129 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
SetTextColor(hdc, textColor);
|
||||
|
||||
// 绘制主卡片和侧边栏卡片
|
||||
if (currentScreen == SCREEN_MENU)
|
||||
{
|
||||
RECT menuCard =
|
||||
{
|
||||
SX(110),
|
||||
SY(70),
|
||||
SX(WINDOW_CLIENT_WIDTH - 110),
|
||||
SY(WINDOW_CLIENT_HEIGHT - 70)
|
||||
};
|
||||
|
||||
HPEN menuFramePen = CreatePen(PS_SOLID, 1, frameColor);
|
||||
HBRUSH menuCardBrush = CreateSolidBrush(cardColor);
|
||||
oldPen = (HPEN)SelectObject(hdc, menuFramePen);
|
||||
oldBrush = (HBRUSH)SelectObject(hdc, menuCardBrush);
|
||||
RoundRect(hdc, menuCard.left, menuCard.top, menuCard.right, menuCard.bottom, SS(34), SS(34));
|
||||
SelectObject(hdc, oldBrush);
|
||||
SelectObject(hdc, oldPen);
|
||||
DeleteObject(menuCardBrush);
|
||||
DeleteObject(menuFramePen);
|
||||
|
||||
HFONT oldFont = (HFONT)SelectObject(hdc, titleFont);
|
||||
SetTextColor(hdc, titleColor);
|
||||
|
||||
RECT titleRect =
|
||||
{
|
||||
menuCard.left,
|
||||
menuCard.top + SS(24),
|
||||
menuCard.right,
|
||||
menuCard.top + SS(70)
|
||||
};
|
||||
DrawText(hdc, _T("Rogue Tetris"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
|
||||
RECT subtitleRect =
|
||||
{
|
||||
menuCard.left,
|
||||
menuCard.top + SS(72),
|
||||
menuCard.right,
|
||||
menuCard.top + SS(110)
|
||||
};
|
||||
SelectObject(hdc, bodyFont);
|
||||
SetTextColor(hdc, textColor);
|
||||
DrawText(hdc, _T("\u8bf7\u9009\u62e9\u5f00\u59cb\u6a21\u5f0f"), -1, &subtitleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
|
||||
const TCHAR* modeNames[2] =
|
||||
{
|
||||
_T("\u7ecf\u5178\u6a21\u5f0f"),
|
||||
_T("Rogue \u6a21\u5f0f")
|
||||
};
|
||||
|
||||
const TCHAR* modeDescriptions[2] =
|
||||
{
|
||||
_T("\u4fdd\u7559\u5f53\u524d\u539f\u7248\u4fc4\u7f57\u65af\u65b9\u5757\u73a9\u6cd5\uff0c\u76f4\u63a5\u5f00\u59cb\u5bf9\u5c40\u3002"),
|
||||
_T("\u8fdb\u5165 Rogue \u5165\u53e3\uff0c\u5f53\u524d\u5148\u63a5\u5165\u57fa\u7840\u5bf9\u5c40\u6d41\u7a0b\u3002")
|
||||
};
|
||||
|
||||
for (int i = 0; i < menuState.optionCount; i++)
|
||||
{
|
||||
bool isSelected = (i == menuState.selectedIndex);
|
||||
int top = menuCard.top + SS(140) + i * SS(130);
|
||||
|
||||
RECT optionRect =
|
||||
{
|
||||
menuCard.left + SS(36),
|
||||
top,
|
||||
menuCard.right - SS(36),
|
||||
top + SS(104)
|
||||
};
|
||||
|
||||
HBRUSH optionBrush = CreateSolidBrush(isSelected ? RGB(255, 232, 240) : RGB(255, 247, 250));
|
||||
HPEN optionPen = CreatePen(PS_SOLID, isSelected ? SS(3) : 1, isSelected ? accentColor : RGB(226, 198, 210));
|
||||
oldPen = (HPEN)SelectObject(hdc, optionPen);
|
||||
oldBrush = (HBRUSH)SelectObject(hdc, optionBrush);
|
||||
RoundRect(hdc, optionRect.left, optionRect.top, optionRect.right, optionRect.bottom, SS(24), SS(24));
|
||||
SelectObject(hdc, oldBrush);
|
||||
SelectObject(hdc, oldPen);
|
||||
DeleteObject(optionBrush);
|
||||
DeleteObject(optionPen);
|
||||
|
||||
RECT modeNameRect =
|
||||
{
|
||||
optionRect.left + SS(24),
|
||||
optionRect.top + SS(14),
|
||||
optionRect.right - SS(24),
|
||||
optionRect.top + SS(44)
|
||||
};
|
||||
|
||||
RECT modeDescriptionRect =
|
||||
{
|
||||
optionRect.left + SS(24),
|
||||
optionRect.top + SS(46),
|
||||
optionRect.right - SS(24),
|
||||
optionRect.bottom - SS(14)
|
||||
};
|
||||
|
||||
SelectObject(hdc, sectionFont);
|
||||
SetTextColor(hdc, isSelected ? titleColor : textColor);
|
||||
DrawText(hdc, modeNames[i], -1, &modeNameRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
|
||||
|
||||
SelectObject(hdc, smallFont);
|
||||
SetTextColor(hdc, RGB(118, 96, 110));
|
||||
DrawText(hdc, modeDescriptions[i], -1, &modeDescriptionRect, DT_LEFT | DT_WORDBREAK);
|
||||
}
|
||||
|
||||
RECT hintRect =
|
||||
{
|
||||
menuCard.left + SS(36),
|
||||
menuCard.bottom - SS(92),
|
||||
menuCard.right - SS(36),
|
||||
menuCard.bottom - SS(36)
|
||||
};
|
||||
|
||||
SelectObject(hdc, smallFont);
|
||||
SetTextColor(hdc, RGB(128, 104, 118));
|
||||
DrawText(hdc, _T("\u65b9\u5411\u952e / WASD \u5207\u6362\uff0cEnter \u6216 Space \u5f00\u59cb\uff0cEsc \u9000\u51fa"), -1, &hintRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
|
||||
SelectObject(hdc, oldFont);
|
||||
DeleteObject(titleFont);
|
||||
DeleteObject(sectionFont);
|
||||
DeleteObject(bodyFont);
|
||||
DeleteObject(smallFont);
|
||||
return;
|
||||
}
|
||||
|
||||
HPEN framePen = CreatePen(PS_SOLID, 1, frameColor);
|
||||
HBRUSH gameCardBrush = CreateSolidBrush(cardColor);
|
||||
HBRUSH panelBrush = CreateSolidBrush(cardColor);
|
||||
@@ -140,7 +249,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
DeleteObject(panelBrush);
|
||||
DeleteObject(framePen);
|
||||
|
||||
// 绘制游戏区背景
|
||||
HBRUSH boardBrush = CreateSolidBrush(boardColor);
|
||||
FillRect(hdc, &gameRect, boardBrush);
|
||||
DeleteObject(boardBrush);
|
||||
@@ -157,7 +265,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
FillRect(hdc, &innerRect, innerBrush);
|
||||
DeleteObject(innerBrush);
|
||||
|
||||
// 绘制游戏区边框
|
||||
HPEN borderPen = CreatePen(PS_SOLID, SS(2), RGB(132, 108, 146));
|
||||
oldPen = (HPEN)SelectObject(hdc, borderPen);
|
||||
oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
||||
@@ -166,7 +273,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
SelectObject(hdc, oldPen);
|
||||
DeleteObject(borderPen);
|
||||
|
||||
// 绘制网格线
|
||||
HPEN gridPen = CreatePen(PS_SOLID, 1, lineColor);
|
||||
oldPen = (HPEN)SelectObject(hdc, gridPen);
|
||||
|
||||
@@ -187,7 +293,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
SelectObject(hdc, oldPen);
|
||||
DeleteObject(gridPen);
|
||||
|
||||
// 绘制已经固定的方块
|
||||
for (int i = 0; i < nGameHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < nGameWidth; j++)
|
||||
@@ -216,7 +321,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预测落点
|
||||
if (targetFlag && !gameOverFlag)
|
||||
{
|
||||
HPEN targetPen = CreatePen(PS_DOT, SS(2), RGB(255, 240, 245));
|
||||
@@ -251,7 +355,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
DeleteObject(targetPen);
|
||||
}
|
||||
|
||||
// 绘制当前活动方块
|
||||
if (!gameOverFlag)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
@@ -288,10 +391,9 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制右侧信息面板
|
||||
HFONT oldFont = (HFONT)SelectObject(hdc, titleFont);
|
||||
SetTextColor(hdc, titleColor);
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(22), _T("俄罗斯方块"), lstrlen(_T("俄罗斯方块")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(22), _T("\u4fc4\u7f57\u65af\u65b9\u5757"), lstrlen(_T("\u4fc4\u7f57\u65af\u65b9\u5757")));
|
||||
|
||||
HPEN accentPen = CreatePen(PS_SOLID, SS(3), accentColor);
|
||||
oldPen = (HPEN)SelectObject(hdc, accentPen);
|
||||
@@ -304,17 +406,21 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
SetTextColor(hdc, textColor);
|
||||
|
||||
TCHAR scoreText[64];
|
||||
_stprintf_s(scoreText, _T("当前得分 %d"), tScore);
|
||||
_stprintf_s(scoreText, _T("\u5f53\u524d\u5f97\u5206 %d"), tScore);
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(104), scoreText, lstrlen(scoreText));
|
||||
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(172), _T("下一个方块"), lstrlen(_T("下一个方块")));
|
||||
TCHAR modeText[64];
|
||||
_stprintf_s(modeText, _T("\u5f53\u524d\u6a21\u5f0f %s"), currentMode == MODE_CLASSIC ? _T("\u7ecf\u5178") : _T("Rogue"));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(140), modeText, lstrlen(modeText));
|
||||
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(188), _T("\u4e0b\u4e00\u4e2a\u65b9\u5757"), lstrlen(_T("\u4e0b\u4e00\u4e2a\u65b9\u5757")));
|
||||
|
||||
RECT nextCard =
|
||||
{
|
||||
panelRect.left + SS(24),
|
||||
panelRect.top + SS(210),
|
||||
panelRect.top + SS(226),
|
||||
panelRect.left + SS(24) + grid * 4 + SS(32),
|
||||
panelRect.top + SS(210) + grid * 4 + SS(32)
|
||||
panelRect.top + SS(226) + grid * 4 + SS(32)
|
||||
};
|
||||
|
||||
HBRUSH nextCardBrush = CreateSolidBrush(RGB(255, 238, 244));
|
||||
@@ -327,7 +433,6 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
DeleteObject(nextCardBrush);
|
||||
DeleteObject(nextCardPen);
|
||||
|
||||
// 绘制下一方块预览
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
@@ -356,13 +461,14 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
}
|
||||
|
||||
SelectObject(hdc, sectionFont);
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(390), _T("操作提示"), lstrlen(_T("操作提示")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(406), _T("\u64cd\u4f5c\u63d0\u793a"), lstrlen(_T("\u64cd\u4f5c\u63d0\u793a")));
|
||||
|
||||
SelectObject(hdc, bodyFont);
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(432), _T("方向键 / WASD:移动 / 旋转"), lstrlen(_T("方向键 / WASD:移动 / 旋转")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(468), _T("空格:快速下落"), lstrlen(_T("空格:快速下落")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(504), _T("P:暂停 R:重新开始"), lstrlen(_T("P:暂停 R:重新开始")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(540), _T("G:显示 / 隐藏落点"), lstrlen(_T("G:显示 / 隐藏落点")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(448), _T("\u65b9\u5411\u952e / WASD\uff1a\u79fb\u52a8 / \u65cb\u8f6c"), lstrlen(_T("\u65b9\u5411\u952e / WASD\uff1a\u79fb\u52a8 / \u65cb\u8f6c")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(484), _T("Space\uff1a\u5feb\u901f\u4e0b\u843d"), lstrlen(_T("Space\uff1a\u5feb\u901f\u4e0b\u843d")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(520), _T("P\uff1a\u6682\u505c R\uff1a\u91cd\u65b0\u5f00\u59cb"), lstrlen(_T("P\uff1a\u6682\u505c R\uff1a\u91cd\u65b0\u5f00\u59cb")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(556), _T("G\uff1a\u663e\u793a / \u9690\u85cf\u843d\u70b9"), lstrlen(_T("G\uff1a\u663e\u793a / \u9690\u85cf\u843d\u70b9")));
|
||||
TextOut(hdc, panelRect.left + SS(24), panelRect.top + SS(592), _T("M\uff1a\u8fd4\u56de\u83dc\u5355"), lstrlen(_T("M\uff1a\u8fd4\u56de\u83dc\u5355")));
|
||||
|
||||
if (suspendFlag || gameOverFlag)
|
||||
{
|
||||
@@ -405,15 +511,15 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
||||
|
||||
if (suspendFlag)
|
||||
{
|
||||
DrawText(hdc, _T("游戏已暂停"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
DrawText(hdc, _T("\u6e38\u620f\u5df2\u6682\u505c"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
SelectObject(hdc, bodyFont);
|
||||
DrawText(hdc, _T("按 P 键继续游戏"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
DrawText(hdc, _T("\u6309 P \u952e\u7ee7\u7eed\u6e38\u620f"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText(hdc, _T("游戏结束"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
DrawText(hdc, _T("\u6e38\u620f\u7ed3\u675f"), -1, &titleRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
SelectObject(hdc, bodyFont);
|
||||
DrawText(hdc, _T("按 R 键重新开始"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
DrawText(hdc, _T("\u6309 R \u952e\u91cd\u65b0\u5f00\u59cb \u6216 M \u8fd4\u56de\u83dc\u5355"), -1, &tipRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user