完善样式设计:樱花粉风格
This commit is contained in:
@@ -11,6 +11,11 @@ constexpr int nGameWidth = 10;
|
|||||||
constexpr int nGameHeight = 20;
|
constexpr int nGameHeight = 20;
|
||||||
constexpr int nWidth = 16;
|
constexpr int nWidth = 16;
|
||||||
constexpr int nHeight = 22;
|
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
|
struct Point
|
||||||
|
|||||||
+45
-8
@@ -31,6 +31,19 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
|||||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
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, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||||
LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING);
|
LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING);
|
||||||
lstrcpy(szTitle, _T("俄罗斯方块"));
|
lstrcpy(szTitle, _T("俄罗斯方块"));
|
||||||
@@ -97,7 +110,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
|
|||||||
*/
|
*/
|
||||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
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);
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, TRUE);
|
||||||
|
|
||||||
hInst = hInstance;
|
hInst = hInstance;
|
||||||
@@ -146,7 +159,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
srand((unsigned int)time(nullptr));
|
srand((unsigned int)time(nullptr));
|
||||||
Restart();
|
Restart();
|
||||||
SetTimer(hWnd, GAME_TIMER_ID, GAME_TIMER_INTERVAL, nullptr);
|
SetTimer(hWnd, GAME_TIMER_ID, GAME_TIMER_INTERVAL, nullptr);
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
break;
|
break;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
{
|
{
|
||||||
@@ -184,28 +197,28 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
ComputeTarget();
|
ComputeTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
if (wParam == 'R')
|
if (wParam == 'R')
|
||||||
{
|
{
|
||||||
Restart();
|
Restart();
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wParam == 'P')
|
if (wParam == 'P')
|
||||||
{
|
{
|
||||||
suspendFlag = !suspendFlag;
|
suspendFlag = !suspendFlag;
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wParam == 'G')
|
if (wParam == 'G')
|
||||||
{
|
{
|
||||||
targetFlag = !targetFlag;
|
targetFlag = !targetFlag;
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,13 +271,37 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
ComputeTarget();
|
ComputeTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateRect(hWnd, nullptr, TRUE);
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
break;
|
break;
|
||||||
|
case WM_ERASEBKGND:
|
||||||
|
return 1;
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hWnd, &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);
|
EndPaint(hWnd, &ps);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ int bricks[7][4][4][4] =
|
|||||||
|
|
||||||
COLORREF BrickColor[7] =
|
COLORREF BrickColor[7] =
|
||||||
{
|
{
|
||||||
RGB(255, 0, 0),
|
RGB(244, 144, 165),
|
||||||
RGB(0, 255, 0),
|
RGB(255, 181, 197),
|
||||||
RGB(0, 0, 255),
|
RGB(170, 215, 255),
|
||||||
RGB(0, 255, 255),
|
RGB(134, 230, 220),
|
||||||
RGB(255, 150, 0),
|
RGB(255, 187, 143),
|
||||||
RGB(255, 255, 0),
|
RGB(255, 223, 146),
|
||||||
RGB(168, 0, 168)
|
RGB(197, 170, 255)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+228
-85
@@ -16,34 +16,119 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
|||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
GetClientRect(hWnd, &clientRect);
|
GetClientRect(hWnd, &clientRect);
|
||||||
|
|
||||||
HBRUSH backgroundBrush = CreateSolidBrush(RGB(245, 245, 245));
|
const RECT gameRect =
|
||||||
FillRect(hdc, &clientRect, backgroundBrush);
|
|
||||||
DeleteObject(backgroundBrush);
|
|
||||||
|
|
||||||
RECT gameRect =
|
|
||||||
{
|
{
|
||||||
GRID,
|
WINDOW_PADDING,
|
||||||
GRID,
|
WINDOW_PADDING,
|
||||||
GRID + nGameWidth * GRID,
|
WINDOW_PADDING + nGameWidth * GRID,
|
||||||
GRID + nGameHeight * 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));
|
HBRUSH boardBrush = CreateSolidBrush(boardColor);
|
||||||
FillRect(hdc, &gameRect, gameBrush);
|
FillRect(hdc, &gameRect, boardBrush);
|
||||||
DeleteObject(gameBrush);
|
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 borderPen = CreatePen(PS_SOLID, 2, RGB(132, 108, 146));
|
||||||
HPEN oldPen = (HPEN)SelectObject(hdc, borderPen);
|
oldPen = (HPEN)SelectObject(hdc, borderPen);
|
||||||
HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
||||||
Rectangle(hdc, gameRect.left, gameRect.top, gameRect.right, gameRect.bottom);
|
RoundRect(hdc, gameRect.left, gameRect.top, gameRect.right, gameRect.bottom, 18, 18);
|
||||||
SelectObject(hdc, oldBrush);
|
SelectObject(hdc, oldBrush);
|
||||||
SelectObject(hdc, oldPen);
|
SelectObject(hdc, oldPen);
|
||||||
DeleteObject(borderPen);
|
DeleteObject(borderPen);
|
||||||
|
|
||||||
// 绘制网格线
|
// 绘制网格线
|
||||||
HPEN gridPen = CreatePen(PS_SOLID, 1, RGB(55, 55, 55));
|
HPEN gridPen = CreatePen(PS_SOLID, 1, lineColor);
|
||||||
oldPen = (HPEN)SelectObject(hdc, gridPen);
|
oldPen = (HPEN)SelectObject(hdc, gridPen);
|
||||||
|
|
||||||
for (int i = 1; i < nGameWidth; i++)
|
for (int i = 1; i < nGameWidth; i++)
|
||||||
@@ -73,15 +158,21 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
|||||||
int colorIndex = workRegion[i][j] - 1;
|
int colorIndex = workRegion[i][j] - 1;
|
||||||
RECT brickRect =
|
RECT brickRect =
|
||||||
{
|
{
|
||||||
gameRect.left + j * GRID + 1,
|
gameRect.left + j * GRID + 2,
|
||||||
gameRect.top + i * GRID + 1,
|
gameRect.top + i * GRID + 2,
|
||||||
gameRect.left + (j + 1) * GRID - 1,
|
gameRect.left + (j + 1) * GRID - 2,
|
||||||
gameRect.top + (i + 1) * GRID - 1
|
gameRect.top + (i + 1) * GRID - 2
|
||||||
};
|
};
|
||||||
|
|
||||||
HBRUSH brickBrush = CreateSolidBrush(BrickColor[colorIndex]);
|
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(brickBrush);
|
||||||
|
DeleteObject(brickPen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +180,7 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
|||||||
// 绘制预测落点
|
// 绘制预测落点
|
||||||
if (targetFlag)
|
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);
|
oldPen = (HPEN)SelectObject(hdc, targetPen);
|
||||||
oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
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)
|
if (drawY >= 0 && drawY < nGameHeight && drawX >= 0 && drawX < nGameWidth)
|
||||||
{
|
{
|
||||||
Rectangle(
|
RoundRect(
|
||||||
hdc,
|
hdc,
|
||||||
gameRect.left + drawX * GRID + 4,
|
gameRect.left + drawX * GRID + 5,
|
||||||
gameRect.top + drawY * GRID + 4,
|
gameRect.top + drawY * GRID + 5,
|
||||||
gameRect.left + (drawX + 1) * GRID - 4,
|
gameRect.left + (drawX + 1) * GRID - 5,
|
||||||
gameRect.top + (drawY + 1) * GRID - 4);
|
gameRect.top + (drawY + 1) * GRID - 5,
|
||||||
|
8, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,59 +226,64 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
|||||||
{
|
{
|
||||||
RECT brickRect =
|
RECT brickRect =
|
||||||
{
|
{
|
||||||
gameRect.left + drawX * GRID + 1,
|
gameRect.left + drawX * GRID + 2,
|
||||||
gameRect.top + drawY * GRID + 1,
|
gameRect.top + drawY * GRID + 2,
|
||||||
gameRect.left + (drawX + 1) * GRID - 1,
|
gameRect.left + (drawX + 1) * GRID - 2,
|
||||||
gameRect.top + (drawY + 1) * GRID - 1
|
gameRect.top + (drawY + 1) * GRID - 2
|
||||||
};
|
};
|
||||||
|
|
||||||
HBRUSH brickBrush = CreateSolidBrush(BrickColor[type]);
|
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(brickBrush);
|
||||||
|
DeleteObject(brickPen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制右侧信息面板
|
// 绘制右侧信息面板
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
HFONT oldFont = (HFONT)SelectObject(hdc, titleFont);
|
||||||
SetTextColor(hdc, RGB(40, 40, 40));
|
SetTextColor(hdc, titleColor);
|
||||||
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 22, _T("俄罗斯方块"), lstrlen(_T("俄罗斯方块")));
|
||||||
|
|
||||||
RECT infoRect =
|
HPEN accentPen = CreatePen(PS_SOLID, 3, accentColor);
|
||||||
{
|
oldPen = (HPEN)SelectObject(hdc, accentPen);
|
||||||
gameRect.right + GRID,
|
MoveToEx(hdc, panelRect.left + 24, panelRect.top + 68, nullptr);
|
||||||
gameRect.top,
|
LineTo(hdc, panelRect.left + 160, panelRect.top + 68);
|
||||||
clientRect.right - GRID,
|
SelectObject(hdc, oldPen);
|
||||||
gameRect.bottom
|
DeleteObject(accentPen);
|
||||||
};
|
|
||||||
|
|
||||||
DrawText(hdc, _T("俄罗斯方块"), -1, &infoRect, DT_TOP | DT_LEFT | DT_SINGLELINE);
|
SelectObject(hdc, sectionFont);
|
||||||
|
SetTextColor(hdc, textColor);
|
||||||
|
|
||||||
TCHAR scoreText[64];
|
TCHAR scoreText[64];
|
||||||
_stprintf_s(scoreText, _T("当前得分:%d"), tScore);
|
_stprintf_s(scoreText, _T("当前得分 %d"), tScore);
|
||||||
TextOut(hdc, infoRect.left, infoRect.top + GRID * 2, scoreText, lstrlen(scoreText));
|
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,
|
panelRect.left + 24,
|
||||||
infoRect.top + GRID * 5,
|
panelRect.top + 210,
|
||||||
infoRect.left + GRID * 4,
|
panelRect.left + 24 + GRID * 4 + 32,
|
||||||
infoRect.top + GRID * 9
|
panelRect.top + 210 + GRID * 4 + 32
|
||||||
};
|
};
|
||||||
|
|
||||||
HBRUSH nextBackBrush = CreateSolidBrush(RGB(220, 220, 220));
|
HBRUSH nextCardBrush = CreateSolidBrush(RGB(255, 238, 244));
|
||||||
FillRect(hdc, &nextRect, nextBackBrush);
|
HPEN nextCardPen = CreatePen(PS_SOLID, 1, RGB(233, 191, 208));
|
||||||
DeleteObject(nextBackBrush);
|
oldPen = (HPEN)SelectObject(hdc, nextCardPen);
|
||||||
|
oldBrush = (HBRUSH)SelectObject(hdc, nextCardBrush);
|
||||||
HPEN nextBorderPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120));
|
RoundRect(hdc, nextCard.left, nextCard.top, nextCard.right, nextCard.bottom, 22, 22);
|
||||||
oldPen = (HPEN)SelectObject(hdc, nextBorderPen);
|
|
||||||
oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
|
|
||||||
Rectangle(hdc, nextRect.left, nextRect.top, nextRect.right, nextRect.bottom);
|
|
||||||
SelectObject(hdc, oldBrush);
|
SelectObject(hdc, oldBrush);
|
||||||
SelectObject(hdc, oldPen);
|
SelectObject(hdc, oldPen);
|
||||||
DeleteObject(nextBorderPen);
|
DeleteObject(nextCardBrush);
|
||||||
|
DeleteObject(nextCardPen);
|
||||||
|
|
||||||
// 绘制下一方块预览
|
// 绘制下一方块预览
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
@@ -197,44 +294,90 @@ void TDrawScreen(HDC hdc, HWND hWnd)
|
|||||||
{
|
{
|
||||||
RECT brickRect =
|
RECT brickRect =
|
||||||
{
|
{
|
||||||
nextRect.left + j * GRID,
|
nextCard.left + 16 + j * GRID,
|
||||||
nextRect.top + i * GRID,
|
nextCard.top + 16 + i * GRID,
|
||||||
nextRect.left + (j + 1) * GRID,
|
nextCard.left + 16 + (j + 1) * GRID - 2,
|
||||||
nextRect.top + (i + 1) * GRID
|
nextCard.top + 16 + (i + 1) * GRID - 2
|
||||||
};
|
};
|
||||||
|
|
||||||
HBRUSH brickBrush = CreateSolidBrush(BrickColor[nType]);
|
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(brickBrush);
|
||||||
|
DeleteObject(brickPen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextOut(hdc, infoRect.left, infoRect.top + GRID * 11, _T("操作说明:"), lstrlen(_T("操作说明:")));
|
SelectObject(hdc, sectionFont);
|
||||||
TextOut(hdc, infoRect.left, infoRect.top + GRID * 12, _T("方向键:移动 / 旋转"), lstrlen(_T("方向键:移动 / 旋转")));
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 390, _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:显示/隐藏落点")));
|
|
||||||
|
|
||||||
if (suspendFlag)
|
SelectObject(hdc, bodyFont);
|
||||||
{
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 432, _T("方向键:移动 / 旋转"), lstrlen(_T("方向键:移动 / 旋转")));
|
||||||
SetTextColor(hdc, RGB(220, 120, 0));
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 468, _T("空格:快速下落"), lstrlen(_T("空格:快速下落")));
|
||||||
TextOut(hdc, infoRect.left, infoRect.top + GRID * 17, _T("游戏已暂停"), lstrlen(_T("游戏已暂停")));
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 504, _T("P:暂停 R:重新开始"), lstrlen(_T("P:暂停 R:重新开始")));
|
||||||
SetTextColor(hdc, RGB(40, 40, 40));
|
TextOut(hdc, panelRect.left + 24, panelRect.top + 540, _T("G:显示 / 隐藏落点"), lstrlen(_T("G:显示 / 隐藏落点")));
|
||||||
}
|
|
||||||
|
|
||||||
if (gameOverFlag)
|
if (suspendFlag || gameOverFlag)
|
||||||
{
|
{
|
||||||
RECT overRect = gameRect;
|
RECT overlayRect =
|
||||||
SetTextColor(hdc, RGB(255, 80, 80));
|
|
||||||
DrawText(hdc, _T("游戏结束"), -1, &overRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
|
||||||
RECT tipRect =
|
|
||||||
{
|
{
|
||||||
gameRect.left,
|
gameRect.left + GRID,
|
||||||
gameRect.top + GRID * 11,
|
gameRect.top + GRID * 6,
|
||||||
gameRect.right,
|
gameRect.right - GRID,
|
||||||
gameRect.top + GRID * 13
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user