From c4fe49ab440f0a0f141fa81e735839c2e91baeb2 Mon Sep 17 00:00:00 2001 From: Qi-huanye <2728290997@qq.com> Date: Fri, 24 Apr 2026 20:48:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=88=86=E7=A0=B4=E6=96=B9?= =?UTF-8?q?=E5=9D=97=E5=BC=BA=E5=8C=96=E5=B9=B6=E6=8E=A5=E5=85=A53x3?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E6=B8=85=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 2 +- src/include/Tetris.h | 2 ++ src/source/TetrisLogic.cpp | 66 +++++++++++++++++++++++++++++++++++-- src/source/TetrisRender.cpp | 20 +++++++++-- 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 883fb3f..52640c8 100644 --- a/TODO.md +++ b/TODO.md @@ -164,7 +164,7 @@ - [x] Hold 功能改造成可解锁能力,而不是默认启用 - [ ] 扩展更多预览块显示 - [x] 清扫者:累计消行触发底部清除 -- [ ] 爆破方块:生成特殊方块并实现 3x3 清除 +- [x] 爆破方块:生成特殊方块并实现 3x3 清除 - [x] 减压:升级后清除最高占用行 - [ ] 稳定结构:小概率自动填补邻近空洞 - [ ] 双倍成长 / 赌徒 / 方块改运等特殊强化 diff --git a/src/include/Tetris.h b/src/include/Tetris.h index 02bde5b..d491a05 100644 --- a/src/include/Tetris.h +++ b/src/include/Tetris.h @@ -53,6 +53,7 @@ struct PlayerStats int pressureReliefLevel; int sweeperLevel; int sweeperCharge; + int explosiveLevel; }; struct UpgradeOption @@ -125,6 +126,7 @@ extern int currentFallInterval; extern int nextTypes[3]; extern int holdType; extern bool holdUsedThisTurn; +extern bool currentPieceIsExplosive; extern int bricks[7][4][4][4]; extern COLORREF BrickColor[7]; diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index 94b80f6..68b9869 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -22,6 +22,7 @@ int currentFallInterval = 500; int nextTypes[3] = { 0, 0, 0 }; int holdType = -1; bool holdUsedThisTurn = false; +bool currentPieceIsExplosive = false; enum UpgradeId { @@ -33,7 +34,8 @@ enum UpgradeId UPGRADE_LAST_CHANCE = 5, UPGRADE_HOLD_UNLOCK = 6, UPGRADE_PRESSURE_RELIEF = 7, - UPGRADE_SWEEPER = 8 + UPGRADE_SWEEPER = 8, + UPGRADE_EXPLOSIVE_PIECE = 9 }; static const UpgradeEntry kUpgradePool[] = @@ -46,7 +48,8 @@ static const UpgradeEntry kUpgradePool[] = { UPGRADE_LAST_CHANCE, 1, false, _T("\u6700\u540e\u4e00\u640f"), _T("\u4fdd\u547d"), _T("\u9996\u6b21\u9876\u6b7b\u65f6\u81ea\u52a8\u6e05\u9664\u5e95\u90e8 3 \u884c\u5e76\u7ee7\u7eed\u6e38\u620f\u3002") }, { UPGRADE_HOLD_UNLOCK, 1, false, _T("Hold \u89e3\u9501"), _T("\u7279\u6b8a"), _T("\u89e3\u9501 Hold \u69fd\uff0c\u5bf9\u5c40\u4e2d\u53ef\u7528 C \u6216 Shift \u6682\u5b58\u65b9\u5757\u3002") }, { UPGRADE_PRESSURE_RELIEF, -1, true, _T("\u51cf\u538b"), _T("\u7279\u6b8a"), _T("\u7acb\u5373\u6e05\u9664\u5f53\u524d\u6700\u9ad8\u5360\u7528\u884c\uff0c\u4e3a\u76d8\u9762\u817e\u51fa\u547c\u5438\u7a7a\u95f4\u3002") }, - { UPGRADE_SWEEPER, -1, true, _T("\u6e05\u626b\u8005"), _T("\u7279\u6b8a"), _T("\u7d2f\u8ba1\u6d88\u884c\u5145\u80fd\uff0c\u6536\u6ee1\u540e\u81ea\u52a8\u6e05\u9664\u5e95\u90e8 1 \u884c\u3002") } + { UPGRADE_SWEEPER, -1, true, _T("\u6e05\u626b\u8005"), _T("\u7279\u6b8a"), _T("\u7d2f\u8ba1\u6d88\u884c\u5145\u80fd\uff0c\u6536\u6ee1\u540e\u81ea\u52a8\u6e05\u9664\u5e95\u90e8 1 \u884c\u3002") }, + { UPGRADE_EXPLOSIVE_PIECE, -1, true, _T("\u7206\u7834\u65b9\u5757"), _T("\u7279\u6b8a"), _T("\u63d0\u9ad8\u7206\u7834\u65b9\u5757\u51fa\u73b0\u6982\u7387\uff0c\u843d\u5730\u65f6\u89e6\u53d1 3x3 \u6e05\u9664\u3002") } }; static constexpr int kUpgradePoolSize = sizeof(kUpgradePool) / sizeof(kUpgradePool[0]); @@ -201,6 +204,7 @@ static void ResetPlayerStats(PlayerStats& stats, bool useRogueRules) stats.pressureReliefLevel = 0; stats.sweeperLevel = 0; stats.sweeperCharge = 0; + stats.explosiveLevel = 0; } static int GetNextPreviewLimit() @@ -245,6 +249,8 @@ static int GetUpgradeCurrentLevel(int upgradeId) return rogueStats.pressureReliefLevel; case UPGRADE_SWEEPER: return rogueStats.sweeperLevel; + case UPGRADE_EXPLOSIVE_PIECE: + return rogueStats.explosiveLevel; default: return 0; } @@ -324,6 +330,36 @@ static int GetSweeperThreshold() return threshold < 3 ? 3 : threshold; } +static bool RollExplosivePiece() +{ + if (currentMode != MODE_ROGUE || rogueStats.explosiveLevel <= 0) + { + return false; + } + + int chancePercent = 12 + (rogueStats.explosiveLevel - 1) * 8; + if (chancePercent > 40) + { + chancePercent = 40; + } + + return (rand() % 100) < chancePercent; +} + +static void ClearExplosiveAreaAt(int centerY, int centerX) +{ + for (int y = centerY - 1; y <= centerY + 1; y++) + { + for (int x = centerX - 1; x <= centerX + 1; x++) + { + if (y >= 0 && y < nGameHeight && x >= 0 && x < nGameWidth) + { + workRegion[y][x] = 0; + } + } + } +} + static void ResetNextQueue() { for (int i = 0; i < 3; i++) @@ -471,6 +507,10 @@ static void ApplyUpgradeById(int upgradeId) rogueStats.sweeperLevel++; SetFeedbackMessage(_T("\u6e05\u626b\u8005\u5df2\u52a0\u5165"), _T("\u7d2f\u8ba1\u6d88\u884c\u540e\u5c06\u81ea\u52a8\u6e05\u7406\u5e95\u90e8\u79ef\u538b\u3002"), 12); break; + case UPGRADE_EXPLOSIVE_PIECE: + rogueStats.explosiveLevel++; + SetFeedbackMessage(_T("\u7206\u7834\u65b9\u5757\u5df2\u5f3a\u5316"), _T("\u540e\u7eed\u5c06\u6709\u66f4\u9ad8\u6982\u7387\u51fa\u73b0\u7206\u7834\u65b9\u5757\u3002"), 12); + break; default: break; } @@ -795,6 +835,8 @@ void DropDown() void Fixing() { bool overflowTop = false; + Point explosiveCells[4] = {}; + int explosiveCellCount = 0; for (int i = 0; i < 4; i++) { @@ -815,6 +857,12 @@ void Fixing() if (fixY >= 0 && fixY < nGameHeight && fixX >= 0 && fixX < nGameWidth) { workRegion[fixY][fixX] = bricks[type][state][i][j]; + if (currentPieceIsExplosive && explosiveCellCount < 4) + { + explosiveCells[explosiveCellCount].x = fixX; + explosiveCells[explosiveCellCount].y = fixY; + explosiveCellCount++; + } } } } @@ -843,11 +891,21 @@ void Fixing() } } + if (currentPieceIsExplosive) + { + for (int i = 0; i < explosiveCellCount; i++) + { + ClearExplosiveAreaAt(explosiveCells[i].y, explosiveCells[i].x); + } + SetFeedbackMessage(_T("\u7206\u7834\u65b9\u5757\u89e6\u53d1"), _T("\u843d\u5730\u540e\u5df2\u89e6\u53d1 3x3 \u8303\u56f4\u6e05\u9664\u3002"), 12); + } + // 生成下一个活动方块 type = ConsumeNextType(); nType = nextTypes[0]; state = 0; holdUsedThisTurn = false; + currentPieceIsExplosive = RollExplosivePiece(); point = GetSpawnPoint(type); target = point; ComputeTarget(); @@ -974,6 +1032,7 @@ void Restart() feedbackState.detail[0] = _T('\0'); holdType = -1; holdUsedThisTurn = false; + currentPieceIsExplosive = false; tScore = 0; ResetNextQueue(); @@ -981,6 +1040,7 @@ void Restart() nType = nextTypes[0]; state = 0; holdUsedThisTurn = false; + currentPieceIsExplosive = RollExplosivePiece(); point = GetSpawnPoint(type); target = point; @@ -1074,10 +1134,12 @@ void HoldCurrentPiece() { type = ConsumeNextType(); nType = nextTypes[0]; + currentPieceIsExplosive = RollExplosivePiece(); } else { type = previousHoldType; + currentPieceIsExplosive = false; } point = GetSpawnPoint(type); diff --git a/src/source/TetrisRender.cpp b/src/source/TetrisRender.cpp index 3f48ff8..2b4475e 100644 --- a/src/source/TetrisRender.cpp +++ b/src/source/TetrisRender.cpp @@ -362,7 +362,7 @@ void TDrawScreen(HDC hdc, HWND hWnd) hdc, _T("\u7ecf\u5178\u6a21\u5f0f\uff1a\u4fdd\u6301\u539f\u7248\u4fc4\u7f57\u65af\u65b9\u5757\u73a9\u6cd5\uff0c\u4ee5\u6d88\u884c\u548c\u751f\u5b58\u4e3a\u4e3b\u3002\r\n\r\n") _T("Rogue \u6a21\u5f0f\uff1a\u6d88\u884c\u540e\u9664\u4e86\u83b7\u5f97\u5206\u6570\uff0c\u8fd8\u4f1a\u83b7\u5f97 EXP\u3002EXP \u8fbe\u5230\u9608\u503c\u540e\u89e6\u53d1\u5347\u7ea7\uff0c\u4ece\u4e09\u4e2a\u5f3a\u5316\u4e2d\u9009\u4e00\u4e2a\u3002\r\n\r\n") - _T("\u5f53\u524d\u5df2\u63a5\u5165\uff1a\u5206\u6570\u500d\u7387\u3001EXP \u500d\u7387\u3001\u6162\u901f\u4e0b\u843d\u3001Hold \u89e3\u9501\u3001\u51cf\u538b\u3001\u6e05\u626b\u8005\u3002\r\n\r\n") + _T("\u5f53\u524d\u5df2\u63a5\u5165\uff1a\u5206\u6570\u500d\u7387\u3001EXP \u500d\u7387\u3001\u6162\u901f\u4e0b\u843d\u3001Hold \u89e3\u9501\u3001\u51cf\u538b\u3001\u6e05\u626b\u8005\u3001\u7206\u7834\u65b9\u5757\u3002\r\n\r\n") _T("\u63d0\u793a\uff1a\u6682\u505c\u3001\u5931\u8d25\u548c\u5347\u7ea7\u4f1a\u8fdb\u5165\u4e0d\u540c\u754c\u9762\uff0c\u8bf7\u6839\u636e\u5c4f\u5e55\u63d0\u793a\u64cd\u4f5c\u3002"), -1, &rulesBody, @@ -529,7 +529,7 @@ void TDrawScreen(HDC hdc, HWND hWnd) }; HBRUSH brickBrush = CreateSolidBrush(BrickColor[type]); - HPEN brickPen = CreatePen(PS_SOLID, 1, RGB(255, 250, 252)); + HPEN brickPen = CreatePen(PS_SOLID, currentPieceIsExplosive ? SS(3) : 1, currentPieceIsExplosive ? RGB(255, 214, 82) : RGB(255, 250, 252)); oldPen = (HPEN)SelectObject(hdc, brickPen); oldBrush = (HBRUSH)SelectObject(hdc, brickBrush); RoundRect(hdc, brickRect.left, brickRect.top, brickRect.right, brickRect.bottom, SS(12), SS(12)); @@ -680,6 +680,18 @@ void TDrawScreen(HDC hdc, HWND hWnd) TextOut(hdc, combatRect.left + SS(18), combatRect.top + SS(114), sweeperText, lstrlen(sweeperText)); } + if (rogueStats.explosiveLevel > 0) + { + TCHAR explosiveText[96]; + int explosiveChance = 12 + (rogueStats.explosiveLevel - 1) * 8; + if (explosiveChance > 40) + { + explosiveChance = 40; + } + _stprintf_s(explosiveText, _T("\u7206\u7834\u6982\u7387 %d%% %s"), explosiveChance, currentPieceIsExplosive ? _T("\u672c\u5757\u5df2\u7206\u7834") : _T("\u672c\u5757\u666e\u901a")); + TextOut(hdc, combatRect.left + SS(18), combatRect.top + SS(146), explosiveText, lstrlen(explosiveText)); + } + RECT upgradeListRect = { panelRect.left + SS(20), @@ -738,6 +750,10 @@ void TDrawScreen(HDC hdc, HWND hWnd) { _stprintf_s(upgradeSummary + lstrlen(upgradeSummary), 512 - lstrlen(upgradeSummary), _T("\u6e05\u626b\u8005 Lv.%d\r\n"), rogueStats.sweeperLevel); } + if (rogueStats.explosiveLevel > 0) + { + _stprintf_s(upgradeSummary + lstrlen(upgradeSummary), 512 - lstrlen(upgradeSummary), _T("\u7206\u7834\u65b9\u5757 Lv.%d\r\n"), rogueStats.explosiveLevel); + } if (lstrlen(upgradeSummary) == 0) { _stprintf_s(upgradeSummary, _T("\u6682\u672a\u9009\u62e9\u4efb\u4f55\u5f3a\u5316\u3002\r\n\u5347\u7ea7\u540e\u4f1a\u5728\u8fd9\u91cc\u7d2f\u79ef\u663e\u793a\u3002"));