{"id":4950,"date":"2024-10-04T23:01:02","date_gmt":"2024-10-04T15:01:02","guid":{"rendered":""},"modified":"2024-10-04T23:01:02","modified_gmt":"2024-10-04T15:01:02","slug":"\u4fc4\u7f57\u65af\u65b9\u5757C\u8bed\u8a00\u4ee3\u7801_\u4fc4\u7f57\u65af\u65b9\u5757c++\u4ee3\u7801","status":"publish","type":"post","link":"https:\/\/mushiming.com\/4950.html","title":{"rendered":"\u4fc4\u7f57\u65af\u65b9\u5757C\u8bed\u8a00\u4ee3\u7801_\u4fc4\u7f57\u65af\u65b9\u5757c++\u4ee3\u7801"},"content":{"rendered":"

\u76ee\u5f55<\/strong><\/p>\n

\u4e00. \u4fc4\u7f57\u65af\u65b9\u5757\u7b80\u6613\u7248\u7684\u5b9e\u73b0<\/p>\n

1. \u56fe\u5f62\u7684\u5b58\u50a8<\/p>\n

2. \u56fe\u5f62\u7684\u663e\u793a<\/p>\n

3. \u56fe\u5f62\u7684\u64cd\u4f5c<\/p>\n

4. \u78b0\u649e\u68c0\u6d4b<\/p>\n

1. \u78b0\u649e\u68c0\u6d4b\uff1a\u79fb\u52a8<\/p>\n

2. \u78b0\u649e\u68c0\u6d4b\uff1a\u65cb\u8f6c<\/p>\n

5. \u6d88\u9664\u6574\u884c<\/p>\n

6. \u6e38\u620f\u7ed3\u675f<\/p>\n

7. \u5b8c\u6574\u4ee3\u7801<\/p>\n

\u4e8c. \u4fc4\u7f57\u65af\u65b9\u5757\u7b80\u6613\u7248\u7684\u5347\u7ea7<\/p>\n

1. \u65b0\u589e\u5c5e\u6027<\/p>\n

2. \u66f4\u6539\u521d\u59cb\u5316\u51fd\u6570<\/p>\n

3. \u66f4\u6539\u6d88\u9664\u6574\u884c\u51fd\u6570<\/p>\n

4. \u66f4\u6539\u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u8f85\u52a9\u51fd\u6570<\/p>\n

5. \u66f4\u6539\u63a7\u5236\u901f\u5ea6\u7684\u8bed\u53e5<\/p>\n

6. \u5b8c\u6574\u4ee3\u7801<\/p>\n

7. \u8fd0\u884c\u6548\u679c<\/p>\n


\n

\u4e00. \u4fc4\u7f57\u65af\u65b9\u5757\u7b80\u6613\u7248\u7684\u5b9e\u73b0<\/h2>\n

1. \u56fe\u5f62\u7684\u5b58\u50a8<\/h3>\n

        \u4fc4\u7f57\u65af\u65b9\u5757\u4e00\u51717\u79cd\u57fa\u7840\u56fe\u5f62\uff0c\u65cb\u8f6c\u540e\u4f1a\u5f97\u523019\u79cd\u5f62\u6001\u3002\u90a3\u4e48\u53ef\u4ee5\u8ba4\u4e3a\u6211\u4eec\u67097\u79cd\u57fa\u7840\u56fe\u5f62\uff0c\u901a\u8fc7\u65cb\u8f6c\u64cd\u4f5c\u8fd97\u79cd\u57fa\u7840\u56fe\u5f62\u53c8\u4f1a\u5f97\u5230\u4e0d\u540c\u7684\u72b6\u6001\uff0c\u6211\u4eec\u53ef\u4ee5\u53ea\u5b58\u50a8\u8fd97\u79cd\u57fa\u672c\u7684\u56fe\u5f62\uff0c\u4f46\u662f\u8ba8\u8bba\u56fe\u5f62\u65cb\u8f6c\u7684\u72b6\u6001\u53d8\u5316\u4f1a\u6bd4\u8f83\u9ebb\u70e6\u3002\u6211\u4eec\u6362\u4e00\u79cd\u601d\u8def\uff0c\u90a3\u5c31\u662f\u5b58\u50a8\u6bcf\u4e00\u79cd\u72b6\u6001\u7684\u5750\u6807\uff0c\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u65cb\u8f6c\u53d8\u6362\u4fbf\u662f\u72b6\u6001\u7684\u53d8\u6362\uff0c\u4e5f\u5c31\u662f\u8bf4\u65cb\u8f6c\u540e\u7684\u72b6\u6001\u6211\u4eec\u5df2\u7ecf\u8bb0\u5f55\u4e0b\u6765\u4e86\uff0c\u5728\u65cb\u8f6c\u7684\u78b0\u649e\u68c0\u6d4b\u65f6\u5c31\u7701\u53bb\u4e86\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3002<\/p>\n

        \u601d\u8def\u6709\u4e86\u63a5\u4e0b\u6765\u5c31\u5b9e\u73b0\u4e00\u4e0b\uff0c\u5047\u8bbe\u6211\u4eec\u4f7f\u75284 * 4\u7684\u7f51\u683c\u6765\u5b58\u653e\u6240\u6709\u7684\u72b6\u6001\uff0c\u90a3\u4e48\u6bcf\u79cd\u72b6\u6001\u5c31\u4f1a\u5bf9\u5e944\u4e2a\u5750\u6807\u5bf9\uff0c\u5047\u8bbe\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u4e3a0~3\uff0c\u4ece\u4e0a\u5230\u4e0b\u9875\u4f9d\u6b21\u4e3a0~3\uff0c\u90a3\u4e48\u6211\u4eec\u6839\u636e\u6bcf\u79cd\u72b6\u6001\u56db\u4e2a\u5c0f\u65b9\u5757\u7684\u4f4d\u7f6e\u53ef\u4ee5\u5199\u51fa\u5982\u4e0b\u4ee3\u7801\u3002<\/p>\n

\/\/ \u58f0\u660e\u8fd919\u79cd\u56fe\u5f62 \/\/ \u56fe\u5f624\u4e2a\u50cf\u7d20\u70b9\u7684\u58f0\u660e\u987a\u5e8f\u65e0\u5173\u7d27\u8981 \/\/ \u4f46\u6bcf\u79cd\u56fe\u5f62\u5fc5\u987b\u6309\u65cb\u8f6c\u53d8\u6362\u7684\u987a\u5e8f\u4f9d\u6b21\u58f0\u660e Point From[19][4] = { \/\/ \u6761\u5f62 { \n  {0, 0}, {1, 0}, {2, 0}, {3, 0}}, { \n  {0, 0}, {0, 1}, {0, 2}, {0, 3}}, \/\/ \u65b9\u5f62 { \n  {0, 0}, {1, 0}, {0, 1}, {1, 1}}, \/\/ L\u5f62 { \n  {0, 0}, {0, 1}, {0, 2}, {1, 2}}, { \n  {2, 0}, {1, 0}, {0, 0}, {0, 1}}, { \n  {2, 2}, {2, 1}, {2, 0}, {1, 0}}, { \n  {0, 2}, {1, 2}, {2, 2}, {2, 1}}, \/\/ \u955c\u50cfL\u5f62 { \n  {2, 0}, {2, 1}, {2, 2}, {1, 2}}, { \n  {2, 2}, {1, 2}, {0, 2}, {0, 1}}, { \n  {0, 2}, {0, 1}, {0, 0}, {1, 0}}, { \n  {0, 0}, {1, 0}, {2, 0}, {2, 1}}, \/\/ T\u578b { \n  {1, 1}, {0, 2}, {1, 2}, {2, 2}}, { \n  {1, 1}, {0, 0}, {0, 1}, {0, 2}}, { \n  {1, 1}, {2, 0}, {1, 0}, {0, 0}}, { \n  {1, 1}, {2, 0}, {2, 1}, {2, 2}}, \/\/ \u95ea\u7535\u5f62 { \n  {0, 0}, {0, 1}, {1, 1}, {1, 2}}, { \n  {2, 0}, {1, 0}, {1, 1}, {0, 1}}, \/\/ \u955c\u50cf\u95ea\u7535\u5f62 { \n  {0, 0}, {1, 0}, {1, 1}, {2, 1}}, { \n  {1, 0}, {1, 1}, {0, 1}, {0, 2}}};<\/code><\/pre>\n

        4\u4e2a\u50cf\u7d20\u70b9\u7684\u58f0\u660e\u987a\u5e8f\u65e0\u5173\u7d27\u8981\uff0c\u4f46\u6bcf\u79cd\u56fe\u5f62\u5fc5\u987b\u6309\u65cb\u8f6c\u53d8\u6362\u7684\u987a\u5e8f\u4f9d\u6b21\u58f0\u660e\uff0c\u7ed3\u5408\u78b0\u649e\u68c0\u6d4b\u4ee3\u7801\u548c\u65cb\u8f6c\u4ee3\u7801\u7684\u5b9e\u73b0\u60f3\u60f3\u4e3a\u4ec0\u4e48\u3002<\/p>\n

        \u8fd9\u91cc\u6211\u4eec\u9700\u8981\u5b58\u50a8\u7684\u5750\u6807\u5bf9\u5e76\u4e0d\u7b97\u591a\uff0c\u5e76\u4e0d\u9700\u8981\u5728\u5806\u4e0a\u7533\u8bf7\u5185\u5b58\uff0c\u4e5f\u6ca1\u5fc5\u8981\u538b\u7f29\u5b58\u50a8\u3002<\/p>\n

2. \u56fe\u5f62\u7684\u663e\u793a<\/h3>\n

        \u6211\u4eec\u9996\u5148\u601d\u8003\u4e00\u4e0b\u6211\u4eec\u9700\u8981\u54ea\u4e9b\u53d8\u91cf\u3002\u6309\u60ef\u4f8b\uff0c\u9996\u5148\u662f\u573a\u666f\u7684\u5bbd\u5ea6BW\u3001\u573a\u666f\u7684\u9ad8\u5ea6BH\uff0c\u7d27\u63a5\u7740\u662f\u56fe\u5f62\u7684\u521d\u59cb\u5750\u6807HomeX\u3001HomeY\uff0c\u7136\u540e\u662f\u65b9\u5757\u7684\u663e\u793a\u6570\u7ec4Board\u3002\u6700\u540e\uff0c\u9488\u5bf9\u4fc4\u7f57\u65af\u65b9\u5757\u8fd9\u4e2a\u6e38\u620f\uff0c\u6211\u4eec\u9700\u8981\u58f0\u660e\u4fc4\u7f57\u65af\u65b9\u5757\u7684\u5f62\u72b6sharp\uff0c\u4fc4\u7f57\u65af\u65b9\u5757\u7684\u5750\u6807x\u3001y\u3002<\/p>\n

const int BW(20); \/\/ BW\u8868\u793a\u573a\u666f\u5bbd\u5ea6 const int BH(27); \/\/ BH\u8868\u793a\u573a\u666f\u9ad8\u5ea6 const int HomeX(BW - 1 >> 1); \/\/ HomeX\u8868\u793a\u56fe\u5f62\u521d\u59cb\u6a2a\u5750\u6807 const int HomeY(1); \/\/ HomeY\u8868\u793a\u56fe\u5f62\u521d\u59cb\u7eb5\u5750\u6807 bool Board[BW * BH]; \/\/ Board[x + y * BW]\u8868\u793a(x, y)\u5904\u662f\u5426\u4e3a\u5c0f\u65b9\u5757 int sharp; \/\/ \u56fe\u5f62\u7684\u5f62\u72b6(\u5f62\u72b6\u968f\u673a\u4ea7\u751f) int x, y; \/\/ \u56fe\u5f62\u7684\u6a2a\u7eb5\u5750\u6807<\/code><\/pre>\n

        \u6309\u60ef\u4f8b\u6211\u4eec\u5148\u5b8c\u6210main()<\/strong><\/em><\/span>\u51fd\u6570\u3002<\/p>\n

int main() { SetConsole(\"\u4fc4\u7f57\u65af\u65b9\u5757\", 40, 27, \"80\"); srand((int)time(0)); run(); }<\/code><\/pre>\n

        \u7d27\u63a5\u7740\u6211\u4eec\u6309\u7167\u4e4b\u524d\u7684\u6a21\u7248\u5feb\u901f\u5199\u51farun()<\/em><\/strong><\/span>\u51fd\u6570\u3002Initialize()\u3001Drop()\u3001Left()\u3001Right()\u3001Ratote()<\/em><\/strong><\/span>\u8fd95\u4e2a\u51fd\u6570\u5148\u58f0\u660e\u4e0d\u5b9e\u73b0\u3002<\/p>\n

\/\/ \u8fd0\u884c\u6e38\u620f void run() { Initialize(); int t = 0; while (true) { \/\/ \u65f6\u95f4\u590d\u6742\u5ea6O(BW * BH * BH) Sleep(1); if (t++ > 50) { Drop(); t = 0; } if (kbhit()) { int ch = getch(); if (ch == 224) { switch (getch()) { case 72: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0a\u952e Ratote(); \/\/ \u65cb\u8f6c\u56fe\u5f62 break; case 80: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0b\u952e Drop(); \/\/ \u4e0b\u964d\u56fe\u5f62 break; case 75: \/\/ \u6309\u4e0b\u952e\u76d8\u5de6\u952e Left(); \/\/ \u5de6\u79fb\u56fe\u5f62 break; case 77: \/\/ \u6309\u4e0b\u952e\u76d8\u53f3\u952e Right(); \/\/ \u53f3\u79fb\u56fe\u5f62 break; } } else if (ch == 32) Pause(); } } }<\/code><\/pre>\n

        \u63a5\u4e0b\u6765\u5c31\u8981\u5f00\u59cb\u52a8\u4e00\u4e0b\u8111\u5b50\u4e86\u3002\u6211\u4eec\u77e5\u9053\u56fe\u5f62\u7684\u5750\u6807(x, y)\uff0c\u56fe\u5f62\u7684\u5f62\u72b6sharp\uff0c\u90a3\u4e48\u6211\u4eec\u5982\u4f55\u663e\u793a\u56fe\u5f62\u5462\uff0c\u6211\u4eec\u4f9d\u6b21\u6253\u5370\u8868\u793a\u56fe\u5f62\u76844\u4e2a\u50cf\u7d20\u70b9\u5373\u53ef\uff0c\u5c06\u6211\u4eec\u5b58\u50a8\u7684\u5c0f\u65b9\u5757\u7684\u76f8\u5bf9\u5750\u6807\u8f6c\u6210\u7edd\u5bf9\u5750\u6807\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u50cf\u7d20\u70b9\u7edd\u5bf9\u5750\u6807\u5904\u5bf9\u5e94\u7684Board\u503c\u8bbe\u7f6e\u4e3atrue(\u8be5\u5904\u5b58\u5728\u5c0f\u65b9\u5757)\uff0c\u7136\u540e\u7528FillStr()<\/em><\/strong><\/span>\u51fd\u6570\u6765\u6253\u5370\u5c0f\u65b9\u5757\u5373\u53ef\u3002\u8003\u8651\u5230\u4ee3\u7801\u91cd\u590d\u5ea6\u8f83\u9ad8\uff0c\u6211\u4eec\u518d\u5199\u4e00\u4e2a\u8f85\u52a9\u51fd\u6570ShowOrClear()<\/em><\/strong><\/span>\u6765\u5b8c\u6210\u91cd\u590d\u7684\u5de5\u4f5c\u3002<\/p>\n

\/\/ \u76f8\u5bf9\u5750\u6807\u8f6c\u7edd\u5bf9\u5750\u6807 Point SiteChange(Point p) { return {x + p.x, y + p.y}; } \/\/ \u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u7684\u8f85\u52a9\u51fd\u6570 void ShowOrClear(bool exist, const std::string &fill) { for (int i = 0; i < 4; ++i) { Point Pixel = SiteChange(From[sharp][i]); Board[Pixel.x + Pixel.y * BW] = exist; FillStr(Pixel.x, Pixel.y, fill); } } \/\/ \u663e\u793a\u56fe\u5f62 void ShowGraph() { ShowOrClear(true, \"\u25a0\"); } \/\/ \u6e05\u9664\u56fe\u5f62 void ClearGraph() { ShowOrClear(false, \" \"); }<\/code><\/pre>\n

        \u5b9e\u73b0\u4e00\u4e0bInitialize()<\/em><\/strong><\/span>\u51fd\u6570\u3002<\/p>\n

\/\/ \u521d\u59cb\u5316\u6e38\u620f void Initialize() { system(\"cls\"); AddGraph(); score = 0; speed = 1; MaxScore = 0; for (bool b : Board) b = false; }<\/code><\/pre>\n

       \u5b9e\u73b0\u4e00\u4e0bAddGraph()<\/em><\/strong><\/span>\u51fd\u6570\u3002<\/p>\n

\/\/ \u6dfb\u52a0\u56fe\u5f62 void AddGraph() { sharp = rand() % 19; x = HomeX; y = HomeY; ShowGraph(); }<\/code><\/pre>\n

3. \u56fe\u5f62\u7684\u64cd\u4f5c<\/h3>\n

        \u63a5\u4e0b\u6765\u6211\u4eec\u5b9e\u73b0\u4e00\u4e0b\u57fa\u672c\u64cd\u4f5c\u3002 <\/p>\n

        \u4e0b\u964d\u51fd\u6570Drop()<\/em><\/strong><\/span>\u3002\u5148\u6e05\u9664\u5c4f\u5e55\u4e0a\u7684\u56fe\u5f62\uff0c\u6539\u53d8\u7eb5\u5750\u6807\u7684\u4f4d\u7f6e\uff0c\u91cd\u65b0\u6253\u5370\u5c4f\u5e55\u4e0a\u7684\u56fe\u5f62\u3002\u8be5\u56fe\u5f62\u65e0\u6cd5\u7ee7\u7eed\u4e0b\u964d\u4e86\uff0c\u5148\u68c0\u6d4b\u662f\u5426\u6709\u6ee1\u884c\u53ef\u4ee5\u6d88\u9664\uff0c\u518d\u6dfb\u52a0\u65b0\u7684\u56fe\u5f62\u5230\u5c4f\u5e55\u4e0a\u3002<\/p>\n

\/\/ \u56fe\u5f62\u4e0b\u964d void Drop() { if (!Drop_CD()) { ClearGraph(); ++y; ShowGraph(); } else { LineRemove(); AddGraph(); } }<\/code><\/pre>\n

        \u5de6\u79fb\u51fd\u6570Left()<\/em><\/span><\/strong>\u3002\u548c\u4e0b\u964d\u51fd\u6570\u540c\u7406\u3002<\/p>\n

\/\/ \u56fe\u5f62\u5de6\u79fb void Left() { if (!Left_CD()) { ClearGraph(); --x; ShowGraph(); } }<\/code><\/pre>\n

        \u53f3\u79fb\u51fd\u6570Right()<\/em><\/strong><\/span>\u3002\u548c\u4e0b\u964d\u51fd\u6570\u540c\u7406\u3002<\/p>\n

\/\/ \u56fe\u5f62\u53f3\u79fb void Right() { if (!Right_CD()) { ClearGraph(); ++x; ShowGraph(); } }<\/code><\/pre>\n

        \u65cb\u8f6c\u51fd\u6570Ratote()<\/em><\/strong><\/span>\u3002\u5148\u8bb0\u5f55\u65cb\u8f6c\u540e\u7684\u72b6\u6001\uff0c\u518d\u5224\u65ad\u65cb\u8f6c\u540e\u7684\u72b6\u6001\u662f\u5426\u53ef\u884c\u3002\u5982\u679c\u7406\u89e3\u4e0d\u4e86\u53ef\u4ee5\u7528switch()<\/em><\/strong><\/span>\u8bed\u53e5\u6765\u8868\u793a\u65cb\u8f6c\u7684\u72b6\u6001\u8f6c\u6362\uff0c\u8fd9\u91cc\u5de7\u5999\u7684\u907f\u5f00\u4e86\u5750\u6807\u7684\u53d8\u6362\u8ba1\u7b97\uff0c\u56e0\u4e3a\u6bcf\u79cd\u72b6\u6001\u90fd\u8bb0\u5f55\u4e86\u76f8\u5e94\u7684\u76f8\u5bf9\u5750\u6807\u3002<\/p>\n

        \u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u8bb0\u5f55\u4e86\u6bcf\u79cd\u72b6\u6001\u5bf9\u5e94\u7684\u76f8\u5bf9\u5750\u6807\u4e86\uff0c\u6211\u4eec\u8fd9\u91cc\u53ea\u9700\u8981\u641e\u6e05\u695a\u6bcf\u79cd\u72b6\u6001\u7684\u4e0b\u4e00\u4e2a\u72b6\u6001\u662f\u4ec0\u4e48\u5c31\u884c\u4e86\uff0c\u6211\u6700\u521d\u5e76\u4e0d\u662f\u8fd9\u4e48\u505a\u7684\uff0c\u800c\u662f\u5206\u60c5\u51b5\u8ba8\u8bba\u4e86\u6bcf\u79cd\u72b6\u6001\u7684\u65cb\u8f6c\u64cd\u4f5c\u5bf9\u5e94\u7684\u5750\u6807\u8f6c\u6362\u516c\u5f0f\uff0c\u4e5f\u5c31\u662f\u901a\u8fc7sharp\u91cd\u65b0\u8ba1\u7b97\u4e86sharp\u65cb\u8f6c\u53d8\u6362\u540e\u5bf9\u5e94\u7684\u76f8\u5bf9\u5750\u6807\u3002\u5f53\u7136\u6211\u4eec\u53ef\u4ee5\u5de7\u5999\u5730\u907f\u5f00\u8fd9\u4e9b\u7e41\u7410\u7684\u8ba1\u7b97\uff0c\u4e8e\u662f\u6211\u4eec\u5f97\u5230\u4e86\u4e0b\u9762\u8fd9\u4e2a\u5341\u5206\u7b80\u6d01\u7684\u65cb\u8f6c\u51fd\u6570\u3002<\/p>\n

\/\/ \u56fe\u5f62\u65cb\u8f6c void Ratote() { int NextSharp = sharp; if (sharp == 6 || sharp == 10 || sharp == 14) NextSharp -= 3; else if (sharp == 1 || sharp == 16 || sharp == 18) --NextSharp; else ++NextSharp; if (!Ratote_CD(NextSharp)) { ClearGraph(); sharp = NextSharp; ShowGraph(); } }<\/code><\/pre>\n

        \u6b64\u65f6\u4ee3\u7801\u5982\u4e0b\u3002<\/strong><\/p>\n

#include \"..\/Engine\/BrickEngine.h\" const int BW(20); \/\/ BW\u8868\u793a\u573a\u666f\u5bbd\u5ea6 const int BH(27); \/\/ BH\u8868\u793a\u573a\u666f\u9ad8\u5ea6 const int HomeX(BW - 1 >> 1); \/\/ HomeX\u8868\u793a\u56fe\u5f62\u521d\u59cb\u6a2a\u5750\u6807 const int HomeY(1); \/\/ HomeY\u8868\u793a\u56fe\u5f62\u521d\u59cb\u7eb5\u5750\u6807 bool Board[BW * BH]; \/\/ Board[x + y * BW]\u8868\u793a(x, y)\u5904\u662f\u5426\u4e3a\u5c0f\u65b9\u5757 int sharp; \/\/ \u56fe\u5f62\u7684\u5f62\u72b6(\u5f62\u72b6\u968f\u673a\u4ea7\u751f) int x, y; \/\/ \u56fe\u5f62\u7684\u6a2a\u7eb5\u5750\u6807 \/\/ \u58f0\u660e\u8fd919\u79cd\u56fe\u5f62 \/\/ \u56fe\u5f624\u4e2a\u50cf\u7d20\u70b9\u7684\u58f0\u660e\u987a\u5e8f\u65e0\u5173\u7d27\u8981 \/\/ \u4f46\u6bcf\u79cd\u56fe\u5f62\u5fc5\u987b\u6309\u65cb\u8f6c\u53d8\u6362\u7684\u987a\u5e8f\u4f9d\u6b21\u58f0\u660e Point From[19][4] = { \/\/ \u6761\u5f62 { \n  {0, 0}, {1, 0}, {2, 0}, {3, 0}}, { \n  {0, 0}, {0, 1}, {0, 2}, {0, 3}}, \/\/ \u65b9\u5f62 { \n  {0, 0}, {1, 0}, {0, 1}, {1, 1}}, \/\/ L\u5f62 { \n  {0, 0}, {0, 1}, {0, 2}, {1, 2}}, { \n  {2, 0}, {1, 0}, {0, 0}, {0, 1}}, { \n  {2, 2}, {2, 1}, {2, 0}, {1, 0}}, { \n  {0, 2}, {1, 2}, {2, 2}, {2, 1}}, \/\/ \u955c\u50cfL\u5f62 { \n  {2, 0}, {2, 1}, {2, 2}, {1, 2}}, { \n  {2, 2}, {1, 2}, {0, 2}, {0, 1}}, { \n  {0, 2}, {0, 1}, {0, 0}, {1, 0}}, { \n  {0, 0}, {1, 0}, {2, 0}, {2, 1}}, \/\/ T\u578b { \n  {1, 1}, {0, 2}, {1, 2}, {2, 2}}, { \n  {1, 1}, {0, 0}, {0, 1}, {0, 2}}, { \n  {1, 1}, {2, 0}, {1, 0}, {0, 0}}, { \n  {1, 1}, {2, 0}, {2, 1}, {2, 2}}, \/\/ \u95ea\u7535\u5f62 { \n  {0, 0}, {0, 1}, {1, 1}, {1, 2}}, { \n  {2, 0}, {1, 0}, {1, 1}, {0, 1}}, \/\/ \u955c\u50cf\u95ea\u7535\u5f62 { \n  {0, 0}, {1, 0}, {1, 1}, {2, 1}}, { \n  {1, 0}, {1, 1}, {0, 1}, {0, 2}}}; void run(); \/\/ \u76f8\u5bf9\u5750\u6807\u8f6c\u7edd\u5bf9\u5750\u6807 Point SiteChange(Point p) { return {x + p.x, y + p.y}; } \/\/ \u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u7684\u8f85\u52a9\u51fd\u6570 void ShowOrClear(bool exist, const std::string &fill) { for (int i = 0; i < 4; ++i) { Point Pixel = SiteChange(From[sharp][i]); Board[Pixel.x + Pixel.y * BW] = exist; FillStr(Pixel.x, Pixel.y, fill); } } \/\/ \u663e\u793a\u56fe\u5f62 void ShowGraph() { ShowOrClear(true, \"\u25a0\"); } \/\/ \u6e05\u9664\u56fe\u5f62 void ClearGraph() { ShowOrClear(false, \" \"); } \/\/ \u6dfb\u52a0\u56fe\u5f62 void AddGraph() { sharp = rand() % 19; x = HomeX; y = HomeY; ShowGraph(); } \/\/ \u6574\u884c\u6d88\u9664 void LineRemove() {} \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u4e0b\u964d bool Drop_CD() { return false; } \/\/ \u56fe\u5f62\u4e0b\u964d void Drop() { if (!Drop_CD()) { ClearGraph(); ++y; ShowGraph(); } else { LineRemove(); AddGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u5de6\u79fb bool Left_CD() { return false; } \/\/ \u56fe\u5f62\u5de6\u79fb void Left() { if (!Left_CD()) { ClearGraph(); --x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u53f3\u79fb bool Right_CD() { return false; } \/\/ \u56fe\u5f62\u53f3\u79fb void Right() { if (!Right_CD()) { ClearGraph(); ++x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u65cb\u8f6c bool Ratote_CD(int NextSharp) { return false; } \/\/ \u56fe\u5f62\u65cb\u8f6c void Ratote() { int NextSharp = sharp; if (sharp == 6 || sharp == 10 || sharp == 14) NextSharp -= 3; else if (sharp == 1 || sharp == 16 || sharp == 18) --NextSharp; else ++NextSharp; if (!Ratote_CD(NextSharp)) { ClearGraph(); sharp = NextSharp; ShowGraph(); } } \/\/ \u521d\u59cb\u5316\u6e38\u620f void Initialize() { system(\"cls\"); AddGraph(); for (bool b : Board) b = false; } \/\/ \u8fd0\u884c\u6e38\u620f void run() { Initialize(); int t = 0; while (true) { Sleep(1); if (t++ > 50) { Drop(); t = 0; } if (kbhit()) { int ch = getch(); if (ch == 224) { switch (getch()) { case 72: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0a\u952e Ratote(); \/\/ \u65cb\u8f6c\u56fe\u5f62 break; case 80: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0b\u952e Drop(); \/\/ \u4e0b\u964d\u56fe\u5f62 break; case 75: \/\/ \u6309\u4e0b\u952e\u76d8\u5de6\u952e Left(); \/\/ \u5de6\u79fb\u56fe\u5f62 break; case 77: \/\/ \u6309\u4e0b\u952e\u76d8\u53f3\u952e Right(); \/\/ \u53f3\u79fb\u56fe\u5f62 break; } } else if (ch == 32) Pause(); } } } int main() { SetConsole(\"\u4fc4\u7f57\u65af\u65b9\u5757\", 40, 27, \"80\"); srand((int)time(0)); run(); }<\/code><\/pre>\n

        \u5de6\u79fb\u3001\u53f3\u79fb\u3001\u4e0b\u964d\u3001\u65cb\u8f6c\uff0c4\u4e2a\u57fa\u672c\u529f\u80fd\u5c31\u5b8c\u6210\u4e86\uff0c\u4e14\u8fbe\u5230\u4e86\u9884\u671f\u7684\u6548\u679c\u3002<\/p>\n

4. \u78b0\u649e\u68c0\u6d4b<\/h3>\n

        \u6700\u91cd\u8981\u4e5f\u662f\u6700\u96be\u5b9e\u73b0\u7684\u6a21\u5757\u5c31\u662f\u78b0\u649e\u68c0\u6d4b\u4e86\u3002<\/p>\n

1. \u78b0\u649e\u68c0\u6d4b\uff1a\u79fb\u52a8<\/h4>\n

        \u4e0b\u964d\u3001\u5de6\u79fb\u3001\u53f3\u79fb\u7684\u78b0\u649e\u68c0\u6d4b\u4ee3\u7801\u5dee\u4e0d\u591a\u3002\u6211\u4eec\u4ee5\u4e0b\u964d\u4e3a\u4f8b\u3002<\/p>\n

        \u4e0d\u7ba1\u54ea\u79cd\u78b0\u649e\u68c0\u6d4b\uff0c\u6211\u4eec\u90fd\u9700\u8981\u5224\u65ad\u56fe\u5f62\u4e2d\u6bcf\u4e00\u4e2a\u5c0f\u65b9\u5757\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u662f\u5426\u6709\u5176\u4ed6\u5c0f\u65b9\u5757(\u4e0d\u80fd\u662f\u56fe\u5f62\u672c\u8eab\u7684)\uff0c\u53e6\u5916\u8fd8\u9700\u8981\u5224\u65ad\u5c0f\u65b9\u5757\u662f\u5426\u4f1a\u8d8a\u754c\u3002\u5728\u7b2c\u4e00\u7c7b\u78b0\u649e\u68c0\u6d4b\u7684\u5224\u65ad\u4e2d\uff0c\u5bf9\u4e8e\u4e0b\u964d\u6765\u8bf4\u6211\u4eec\u53ef\u4ee5\u53ea\u5224\u65ad\u8be5\u56fe\u5f62\u6700\u4e0b\u9762\u7684\u70b9\u4e0b\u964d\u540e\u662f\u5426\u4f1a\u78b0\u649e\u5230\u969c\u788d\u7269\uff0c\u56e0\u6b64\u5927\u81f4\u4e0a\u662f\u4e24\u4e2a\u6b65\u9aa4\uff0c\u5148\u5224\u65ad\u8be5\u5c0f\u65b9\u5757\u662f\u5426\u662f\u6700\u4e0b\u9762\u7684\u70b9\uff0c\u518d\u5224\u65ad\u8be5\u70b9\u4e0b\u4e00\u4f4d\u7f6e\u662f\u5426\u6709\u5c0f\u65b9\u5757\u3002\u4e0d\u96be\u53d1\u73b0\u5bf9\u4e8e\u662f\u5426\u8d8a\u754c\u7684\u5224\u65ad\u6211\u4eec\u53ef\u4ee5\u7ed9\u51fa\u66f4\u52a0\u901a\u7528\u7684\u5224\u65ad\u6761\u4ef6\uff0c\u4f46\u662f\u5728\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u6211\u4eec\u53ea\u67094\u5904\u8d8a\u754c\u5224\u65ad\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u53ea\u5199\u6bcf\u79cd\u60c5\u51b5\u5bf9\u5e94\u7684\u8d8a\u754c\u5224\u65ad\u6761\u4ef6\uff0c\u4ee5\u8282\u7701\u591a\u4f59\u5224\u65ad\u6240\u5e26\u6765\u7684\u989d\u5916\u5f00\u9500\uff0c\u590d\u7528\u6027\u964d\u4f4e\u5730\u540c\u65f6\u63d0\u9ad8\u4e86\u6027\u80fd\u3002<\/p>\n

\/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u4e0b\u964d bool Drop_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u4e0b\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.y > BH - 2) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y > Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + (Pixel0.y + 1) * BW]) return true; } return false; }<\/code><\/pre>\n

2. \u78b0\u649e\u68c0\u6d4b\uff1a\u65cb\u8f6c<\/h4>\n

        \u65cb\u8f6c\u78b0\u649e\u68c0\u6d4b\u5176\u5b9e\u548c\u79fb\u52a8\u7684\u78b0\u649e\u68c0\u6d4b\u4e5f\u5dee\u4e0d\u591a\uff0c\u552f\u4e00\u7684\u5dee\u522b\u662f\u8fd9\u91cc\u7684Pixel0\u662f\u65cb\u8f6c\u4e4b\u540e\u7684\u5c0f\u65b9\u5757\uff0c\u800c\u4e4b\u524d\u7684Pixel0\u662f\u79fb\u52a8\u524d\u7684\u5c0f\u65b9\u5757\u3002\u76f8\u5f53\u4e8e\u8fd9\u91cc\u662f\u5148\u64cd\u4f5c\u518d\u770b\u884c\u4e0d\u884c\uff0c\u79fb\u52a8\u90a3\u91cc\u662f\u5148\u770b\u884c\u4e0d\u884c\u518d\u64cd\u4f5c\uff0c\u672c\u8d28\u4e0a\u662f\u4e00\u6837\u7684\u3002<\/p>\n

\/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u65cb\u8f6c bool Ratote_CD(int NextSharp) { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u4e0b\u4e00\u4f4d\u7f6e\u662f\u5426\u65e0\u5176\u4ed6\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[NextSharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x < 0 || BW - 1 < Pixel0.x || Pixel0.y > BH - 1) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y == Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + Pixel0.y * BW]) return true; } return false; }<\/code><\/pre>\n

5. \u6d88\u9664\u6574\u884c<\/h3>\n

        \u4ece\u6700\u4e0b\u9762\u90a3\u4e00\u884c\u5f00\u59cb\u626b\u63cf\uff0c\u5982\u679c\u53d1\u73b0\u6ee1\u884c\u5c31\u6d88\u9664\u8be5\u884c\u5e76\u91cd\u65b0\u626b\u63cf\u8be5\u884c\uff0c\u5426\u5219\u5c31\u626b\u63cf\u4e0a\u4e00\u884c\uff0c\u76f4\u5230\u626b\u63cf\u5b8c\u6240\u6709\u884c\u4e14\u6ca1\u53d1\u73b0\u6ee1\u884c\u65f6\u9000\u51fa\u51fd\u6570\u3002\u6709\u4e00\u4e2a\u7ec6\u8282\u662f\uff1a\u56e0\u4e3a\u6211\u4eec\u8981\u5c06\u6d88\u9664\u7684\u90a3\u4e00\u884c\u4e0a\u9762\u7684\u6240\u6709\u884c\u4e0b\u79fb\uff0c\u8fd9\u91cc\u6211\u4eec\u4ece\u53f3\u5411\u5de6\u3001\u4ece\u4e0b\u5230\u4e0a\u4f9d\u6b21\u79fb\u52a8\u5c31\u597d\uff1b\u5982\u679c\u662f\u4ece\u5de6\u4e0a\u5230\u53f3\u4e0b\u904d\u5386\uff0c\u5219\u4f1a\u8986\u76d6\u8fd8\u672a\u64cd\u4f5c\u7684\u5c0f\u65b9\u5757\uff0c\u6211\u4e4b\u524d\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5c06\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u79fb\u52a8\u540e\u7684\u5750\u6807\u7f13\u5b58\u4e0b\u6765\u4e4b\u540e\u518d\u53d6\u51fa\uff0c\u90a3\u6837\u7684\u8bdd\u9700\u8981\u904d\u53862\u6b21\u3002\u53e6\u5916\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6d88\u9664\u8be5\u884c\u540e\u4e00\u5b9a\u8981\u9000\u56de\u5230\u8be5\u884c\u91cd\u65b0\u626b\u63cf\u3002\u5426\u5219\uff0c\u8be5\u51fd\u65701\u6b21\u5c31\u53ea\u80fd\u6d88\u96641\u884c\u3002<\/p>\n

\/\/ \u6574\u884c\u6d88\u9664 void LineRemove() { int JudgeY = BH - 1; \/\/ \u5f53\u524d\u5224\u65ad\u7684\u884c\u6570 while (JudgeY >= 0) { int cnt = 0; for (int i = 0; i < BW; ++i) if (Board[BW * JudgeY + i]) ++cnt; if (cnt != BW) \/\/ \u672a\u6ee1\u884c, \u5224\u65ad\u4e0a\u4e00\u884c --JudgeY; else \/\/ \u6ee1\u884c\u6d88\u9664 { \/\/ \u79fb\u9664JudgeY\u8fd9\u4e00\u884c for (int i = 0; i < BW; ++i) { Board[i + JudgeY * BW] = false; FillStr(i, JudgeY, \" \"); } \/\/ \u5c06JudgeY\u8fd9\u884c\u4e0a\u65b9\u7684\u6240\u6709\u65b9\u5757\u4e0b\u79fb\u4e00\u884c for (int i = BW * JudgeY - 1; i >= 0; --i) if (Board[i]) { Board[i] = false; FillStr(i % BW, i \/ BW, \" \"); Board[i + BW] = true; FillStr(i % BW, i \/ BW + 1, \"\u25a0\"); } } } }<\/code><\/pre>\n

6. \u6e38\u620f\u7ed3\u675f<\/h3>\n

        \u5224\u65ad\u6e38\u620f\u7ed3\u675f\u7684\u4ee3\u7801\u4e5f\u5341\u5206\u5de7\u5999\u3002\u4ec5\u4ec5\u662f\u6211\u4eec\u5728\u4e4b\u524d\u7684\u51fd\u6570\u91cc\u6dfb\u52a0\u4e86\u4e00\u4e2aif()<\/em><\/strong><\/span>\u8bed\u53e5\u3002<\/p>\n

\/\/ \u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u7684\u8f85\u52a9\u51fd\u6570 void ShowOrClear(bool exist, const std::string &fill) { for (int i = 0; i < 4; ++i) { Point Pixel = SiteChange(From[sharp][i]); if (Board[Pixel.x + Pixel.y * BW] == exist) \/\/ \u8be5\u5904\u5df2\u5b58\u5728\u56fe\u5f62, \u6e38\u620f\u7ed3\u675f { SetPos(BW - 3 >> 1, BH >> 1); std::cout << \"Game Over!\"; Pause(); run(); } Board[Pixel.x + Pixel.y * BW] = exist; FillStr(Pixel.x, Pixel.y, fill); } }<\/code><\/pre>\n

       \u4e0d\u96be\u7406\u89e3\uff0c\u8fd9\u91cc\u5c31\u662f\u5224\u65ad\u5c06\u8981\u663e\u793a\u7684\u4f4d\u7f6e\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u56fe\u5f62\uff0c\u5982\u679c\u8fc7\u5b58\u5728\u5219\u6e38\u620f\u7ed3\u675f\u3002\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u884c\u5462\uff0c\u56de\u60f3\u4e00\u4e0b\u4e4b\u524d\u5199\u7684\u663e\u793a\u548c\u6e05\u9664\u8bed\u53e5\uff0c\u5b83\u4eec\u90fd\u5305\u542b\u57284\u4e2a\u57fa\u672c\u64cd\u4f5c\u7684\u51fd\u6570\u91cc\u9762\u4e86\uff0c\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u5df2\u7ecf\u8fdb\u884c\u4e86\u4e25\u683c\u7684\u78b0\u649e\u68c0\u6d4b\uff0c\u51fa\u73b0\u4f7f\u4e0a\u8ff0if()<\/em><\/strong><\/span>\u6210\u7acb\u7684\u60c5\u51b5\u53ea\u6709\u4e00\u79cd\uff0c\u90a3\u5c31\u662f\u65e7\u56fe\u5f62\u89e6\u5e95\u540e\u53d1\u73b0\u6ca1\u6709\u6dfb\u52a0\u65b0\u56fe\u5f62\u7684\u7a7a\u95f4\uff0c\u6709\u5c31\u662f\u4fc4\u7f57\u65af\u65b9\u5757\u4e2d\u7684\u6e38\u620f\u7ed3\u675f\u3002<\/p>\n

7. \u5b8c\u6574\u4ee3\u7801<\/h3>\n
#include \"..\/Engine\/BrickEngine.h\" const int BW(20); \/\/ BW\u8868\u793a\u573a\u666f\u5bbd\u5ea6 const int BH(27); \/\/ BH\u8868\u793a\u573a\u666f\u9ad8\u5ea6 const int HomeX(BW - 1 >> 1); \/\/ HomeX\u8868\u793a\u56fe\u5f62\u521d\u59cb\u6a2a\u5750\u6807 const int HomeY(1); \/\/ HomeY\u8868\u793a\u56fe\u5f62\u521d\u59cb\u7eb5\u5750\u6807 bool Board[BW * BH]; \/\/ Board[x + y * BW]\u8868\u793a(x, y)\u5904\u662f\u5426\u4e3a\u5c0f\u65b9\u5757 int sharp; \/\/ \u56fe\u5f62\u7684\u5f62\u72b6(\u5f62\u72b6\u968f\u673a\u4ea7\u751f) int x, y; \/\/ \u56fe\u5f62\u7684\u6a2a\u7eb5\u5750\u6807 \/\/ \u58f0\u660e\u8fd919\u79cd\u56fe\u5f62 \/\/ \u56fe\u5f624\u4e2a\u50cf\u7d20\u70b9\u7684\u58f0\u660e\u987a\u5e8f\u65e0\u5173\u7d27\u8981 \/\/ \u4f46\u6bcf\u79cd\u56fe\u5f62\u5fc5\u987b\u6309\u65cb\u8f6c\u53d8\u6362\u7684\u987a\u5e8f\u4f9d\u6b21\u58f0\u660e Point From[19][4] = { \/\/ \u6761\u5f62 { \n  {0, 0}, {1, 0}, {2, 0}, {3, 0}}, { \n  {0, 0}, {0, 1}, {0, 2}, {0, 3}}, \/\/ \u65b9\u5f62 { \n  {0, 0}, {1, 0}, {0, 1}, {1, 1}}, \/\/ L\u5f62 { \n  {0, 0}, {0, 1}, {0, 2}, {1, 2}}, { \n  {2, 0}, {1, 0}, {0, 0}, {0, 1}}, { \n  {2, 2}, {2, 1}, {2, 0}, {1, 0}}, { \n  {0, 2}, {1, 2}, {2, 2}, {2, 1}}, \/\/ \u955c\u50cfL\u5f62 { \n  {2, 0}, {2, 1}, {2, 2}, {1, 2}}, { \n  {2, 2}, {1, 2}, {0, 2}, {0, 1}}, { \n  {0, 2}, {0, 1}, {0, 0}, {1, 0}}, { \n  {0, 0}, {1, 0}, {2, 0}, {2, 1}}, \/\/ T\u578b { \n  {1, 1}, {0, 2}, {1, 2}, {2, 2}}, { \n  {1, 1}, {0, 0}, {0, 1}, {0, 2}}, { \n  {1, 1}, {2, 0}, {1, 0}, {0, 0}}, { \n  {1, 1}, {2, 0}, {2, 1}, {2, 2}}, \/\/ \u95ea\u7535\u5f62 { \n  {0, 0}, {0, 1}, {1, 1}, {1, 2}}, { \n  {2, 0}, {1, 0}, {1, 1}, {0, 1}}, \/\/ \u955c\u50cf\u95ea\u7535\u5f62 { \n  {0, 0}, {1, 0}, {1, 1}, {2, 1}}, { \n  {1, 0}, {1, 1}, {0, 1}, {0, 2}}}; void run(); \/\/ \u76f8\u5bf9\u5750\u6807\u8f6c\u7edd\u5bf9\u5750\u6807 Point SiteChange(Point p) { return {x + p.x, y + p.y}; } \/\/ \u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u7684\u8f85\u52a9\u51fd\u6570 void ShowOrClear(bool exist, const std::string &fill) { for (int i = 0; i < 4; ++i) { Point Pixel = SiteChange(From[sharp][i]); if (Board[Pixel.x + Pixel.y * BW] == exist) \/\/ \u8be5\u5904\u5df2\u5b58\u5728\u56fe\u5f62, \u6e38\u620f\u7ed3\u675f { SetPos(BW - 3 >> 1, BH >> 1); std::cout << \"Game Over!\"; Pause(); run(); } Board[Pixel.x + Pixel.y * BW] = exist; FillStr(Pixel.x, Pixel.y, fill); } } \/\/ \u663e\u793a\u56fe\u5f62 void ShowGraph() { ShowOrClear(true, \"\u25a0\"); } \/\/ \u6e05\u9664\u56fe\u5f62 void ClearGraph() { ShowOrClear(false, \" \"); } \/\/ \u6dfb\u52a0\u56fe\u5f62 void AddGraph() { sharp = rand() % 19; x = HomeX; y = HomeY; ShowGraph(); } \/\/ \u6574\u884c\u6d88\u9664 void LineRemove() { int JudgeY = BH - 1; \/\/ \u5f53\u524d\u5224\u65ad\u7684\u884c\u6570 while (JudgeY >= 0) { int cnt = 0; for (int i = 0; i < BW; ++i) if (Board[BW * JudgeY + i]) ++cnt; if (cnt != BW) \/\/ \u672a\u6ee1\u884c, \u5224\u65ad\u4e0a\u4e00\u884c --JudgeY; else \/\/ \u6ee1\u884c\u6d88\u9664 { \/\/ \u79fb\u9664JudgeY\u8fd9\u4e00\u884c for (int i = 0; i < BW; ++i) { Board[i + JudgeY * BW] = false; FillStr(i, JudgeY, \" \"); } \/\/ \u5c06JudgeY\u8fd9\u884c\u4e0a\u65b9\u7684\u6240\u6709\u65b9\u5757\u4e0b\u79fb\u4e00\u884c for (int i = BW * JudgeY - 1; i >= 0; --i) if (Board[i]) { Board[i] = false; FillStr(i % BW, i \/ BW, \" \"); Board[i + BW] = true; FillStr(i % BW, i \/ BW + 1, \"\u25a0\"); } } } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u4e0b\u964d bool Drop_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u4e0b\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.y > BH - 2) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y > Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + (Pixel0.y + 1) * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u4e0b\u964d void Drop() { if (!Drop_CD()) { ClearGraph(); ++y; ShowGraph(); } else { LineRemove(); AddGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u5de6\u79fb bool Left_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u6700\u5de6\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x < 1) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.y == Pixel0.y && Pixel1.x < Pixel0.x) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x - 1 + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u5de6\u79fb void Left() { if (!Left_CD()) { ClearGraph(); --x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u53f3\u79fb bool Right_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u6700\u53f3\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x > BW - 2) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.y == Pixel0.y && Pixel1.x > Pixel0.x) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + 1 + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u53f3\u79fb void Right() { if (!Right_CD()) { ClearGraph(); ++x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u65cb\u8f6c bool Ratote_CD(int NextSharp) { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u4e0b\u4e00\u4f4d\u7f6e\u662f\u5426\u65e0\u5176\u4ed6\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[NextSharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x < 0 || BW - 1 < Pixel0.x || Pixel0.y > BH - 1) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y == Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u65cb\u8f6c void Ratote() { int NextSharp = sharp; if (sharp == 6 || sharp == 10 || sharp == 14) NextSharp -= 3; else if (sharp == 1 || sharp == 16 || sharp == 18) --NextSharp; else ++NextSharp; if (!Ratote_CD(NextSharp)) { ClearGraph(); sharp = NextSharp; ShowGraph(); } } \/\/ \u521d\u59cb\u5316\u6e38\u620f void Initialize() { system(\"cls\"); AddGraph(); for (bool b : Board) b = false; } \/\/ \u8fd0\u884c\u6e38\u620f void run() { Initialize(); int t = 0; while (true) { Sleep(1); if (t++ > 50) { Drop(); t = 0; } if (kbhit()) { int ch = getch(); if (ch == 224) { switch (getch()) { case 72: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0a\u952e Ratote(); \/\/ \u65cb\u8f6c\u56fe\u5f62 break; case 80: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0b\u952e Drop(); \/\/ \u4e0b\u964d\u56fe\u5f62 break; case 75: \/\/ \u6309\u4e0b\u952e\u76d8\u5de6\u952e Left(); \/\/ \u5de6\u79fb\u56fe\u5f62 break; case 77: \/\/ \u6309\u4e0b\u952e\u76d8\u53f3\u952e Right(); \/\/ \u53f3\u79fb\u56fe\u5f62 break; } } else if (ch == 32) Pause(); } } } int main() { SetConsole(\"\u4fc4\u7f57\u65af\u65b9\u5757\", 40, 27, \"80\"); srand((int)time(0)); run(); }<\/code><\/pre>\n

\u4e8c. \u4fc4\u7f57\u65af\u65b9\u5757\u7b80\u6613\u7248\u7684\u5347\u7ea7<\/h2>\n

1. \u65b0\u589e\u5c5e\u6027<\/h3>\n

        \u2460 \u6e38\u620f\u5f97\u5206score<\/em><\/span><\/p>\n

        <\/em><\/span>\u2461 \u56fe\u5f62\u4e0b\u964d\u901f\u5ea6speed<\/em><\/span><\/p>\n

        <\/em><\/span>\u2462 \u573a\u666f\u5de6\u4e0a\u89d2\u7684\u6a2a\u7eb5\u5750\u6807BX\u3001BY<\/em><\/span><\/p>\n

const int BX(1); \/\/ BX\u8868\u793a\u573a\u666f\u7684\u6a2a\u5750\u6807 const int BY(0); \/\/ BY\u8868\u793a\u573a\u666f\u7684\u7eb5\u5750\u6807 int score; \/\/ \u6e38\u620f\u5f97\u5206 int speed; \/\/ \u56fe\u5f62\u4e0b\u843d\u7684\u901f\u5ea6<\/code><\/pre>\n

2. \u66f4\u6539\u521d\u59cb\u5316\u51fd\u6570<\/h3>\n

        \u7ed9\u573a\u666f\u52a0\u4e0a\u8fb9\u6846\uff1b\u5728\u573a\u666f\u53f3\u8fb9\u663e\u793a\u901f\u5ea6\u548c\u5206\u6570\u3002<\/p>\n

\/\/ \u521d\u59cb\u5316\u573a\u666f FillRec(BX - 1, BY, 1, BH, \"\u2502\"); FillRec(BX + BW, BY, 1, BH, \"\u2503\"); FillRec(BX, BY + BH, BW * 2 - 1, 1, \"\u2501\"); FillStr(BX - 1, BY + BH, \"\u2570\"); FillStr(BX + BW, BY + BH, \"\u256f\"); FillStr(BW + 2, 3, \" SCORE\"); std::cout << std::setw(4); FillStr(BW + 3, 4, std::to_string(score)); FillStr(BW + 2, 7, \" SPEED\"); std::cout << std::setw(2); FillStr(BW + 4, 8, std::to_string(speed));<\/code><\/pre>\n

3. \u66f4\u6539\u6d88\u9664\u6574\u884c\u51fd\u6570<\/h3>\n

        \u66f4\u6539\u586b\u5145\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4f7f\u573a\u666f\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\uff1b\u6dfb\u52a0\u66f4\u65b0\u73a9\u5bb6\u5f97\u5206\u64cd\u4f5c\u3002<\/p>\n

\/\/ \u79fb\u9664JudgeY\u8fd9\u4e00\u884c for (int i = 0; i < BW; ++i) { Board[i + JudgeY * BW] = false; FillStr(i + BX, JudgeY + BY, \" \"); } \/\/ \u5c06JudgeY\u8fd9\u884c\u4e0a\u65b9\u7684\u6240\u6709\u65b9\u5757\u4e0b\u79fb\u4e00\u884c for (int i = BW * JudgeY - 1; i >= 0; --i) if (Board[i]) { Board[i] = false; FillStr(i % BW + BX, i \/ BW + BY, \" \"); Board[i + BW] = true; FillStr(i % BW + BX, i \/ BW + 1 + BY, \"\u25a0\"); } ++score; std::cout << std::setw(4); FillStr(BW + 3, 4, std::to_string(score)); std::cout << std::setw(2); FillStr(BW + 4, 8, std::to_string(speed));<\/code><\/pre>\n

4. \u66f4\u6539\u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u8f85\u52a9\u51fd\u6570<\/h3>\n

        \u66f4\u6539\u586b\u5145\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4f7f\u573a\u666f\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002<\/p>\n

FillStr(Pixel.x + BX, Pixel.y + BY, fill);<\/code><\/pre>\n

5. \u66f4\u6539\u63a7\u5236\u901f\u5ea6\u7684\u8bed\u53e5<\/h3>\n

        \u7a0d\u4f5c\u4fee\u6539\u4f7f\u5f97score\u51b3\u5b9aspeed\uff0cspeed\u5f71\u54cd\u65b9\u5757\u4e0b\u964d\u7684\u901f\u5ea6\u3002<\/p>\n

speed = score \/ 5 + 1; if (t++ > (30 - speed)) { Drop(); t = 0; }<\/code><\/pre>\n

6. \u5b8c\u6574\u4ee3\u7801<\/h3>\n
#include \"..\/Engine\/BrickEngine.h\" const int BW(14); \/\/ BW\u8868\u793a\u573a\u666f\u5bbd\u5ea6 const int BH(24); \/\/ BH\u8868\u793a\u573a\u666f\u9ad8\u5ea6 const int BX(1); \/\/ BX\u8868\u793a\u573a\u666f\u7684\u6a2a\u5750\u6807 const int BY(0); \/\/ BY\u8868\u793a\u573a\u666f\u7684\u7eb5\u5750\u6807 const int HomeX(BW - 1 >> 1); \/\/ HomeX\u8868\u793a\u56fe\u5f62\u521d\u59cb\u6a2a\u5750\u6807 const int HomeY(1); \/\/ HomeY\u8868\u793a\u56fe\u5f62\u521d\u59cb\u7eb5\u5750\u6807 bool Board[BW * BH]; \/\/ Board[x + y * BW]\u8868\u793a(x, y)\u5904\u662f\u5426\u4e3a\u5c0f\u65b9\u5757 int sharp; \/\/ \u56fe\u5f62\u7684\u5f62\u72b6(\u5f62\u72b6\u968f\u673a\u4ea7\u751f) int x, y; \/\/ \u56fe\u5f62\u7684\u6a2a\u7eb5\u5750\u6807 int score; \/\/ \u6e38\u620f\u5f97\u5206 int speed; \/\/ \u56fe\u5f62\u4e0b\u843d\u7684\u901f\u5ea6 \/\/ \u58f0\u660e\u8fd919\u79cd\u56fe\u5f62 \/\/ \u56fe\u5f624\u4e2a\u50cf\u7d20\u70b9\u7684\u58f0\u660e\u987a\u5e8f\u65e0\u5173\u7d27\u8981 \/\/ \u4f46\u6bcf\u79cd\u56fe\u5f62\u5fc5\u987b\u6309\u65cb\u8f6c\u53d8\u6362\u7684\u987a\u5e8f\u4f9d\u6b21\u58f0\u660e Point From[19][4] = { \/\/ \u6761\u5f62 { \n  {0, 0}, {1, 0}, {2, 0}, {3, 0}}, { \n  {0, 0}, {0, 1}, {0, 2}, {0, 3}}, \/\/ \u65b9\u5f62 { \n  {0, 0}, {1, 0}, {0, 1}, {1, 1}}, \/\/ L\u5f62 { \n  {0, 0}, {0, 1}, {0, 2}, {1, 2}}, { \n  {2, 0}, {1, 0}, {0, 0}, {0, 1}}, { \n  {2, 2}, {2, 1}, {2, 0}, {1, 0}}, { \n  {0, 2}, {1, 2}, {2, 2}, {2, 1}}, \/\/ \u955c\u50cfL\u5f62 { \n  {2, 0}, {2, 1}, {2, 2}, {1, 2}}, { \n  {2, 2}, {1, 2}, {0, 2}, {0, 1}}, { \n  {0, 2}, {0, 1}, {0, 0}, {1, 0}}, { \n  {0, 0}, {1, 0}, {2, 0}, {2, 1}}, \/\/ T\u578b { \n  {1, 1}, {0, 2}, {1, 2}, {2, 2}}, { \n  {1, 1}, {0, 0}, {0, 1}, {0, 2}}, { \n  {1, 1}, {2, 0}, {1, 0}, {0, 0}}, { \n  {1, 1}, {2, 0}, {2, 1}, {2, 2}}, \/\/ \u95ea\u7535\u5f62 { \n  {0, 0}, {0, 1}, {1, 1}, {1, 2}}, { \n  {2, 0}, {1, 0}, {1, 1}, {0, 1}}, \/\/ \u955c\u50cf\u95ea\u7535\u5f62 { \n  {0, 0}, {1, 0}, {1, 1}, {2, 1}}, { \n  {1, 0}, {1, 1}, {0, 1}, {0, 2}}}; void run(); \/\/ \u76f8\u5bf9\u5750\u6807\u8f6c\u7edd\u5bf9\u5750\u6807 Point SiteChange(Point p) { return {x + p.x, y + p.y}; } \/\/ \u663e\u793a\u3001\u6e05\u9664\u56fe\u5f62\u7684\u8f85\u52a9\u51fd\u6570 void ShowOrClear(bool exist, const std::string &fill) { for (int i = 0; i < 4; ++i) { Point Pixel = SiteChange(From[sharp][i]); if (Board[Pixel.x + Pixel.y * BW] == exist) \/\/ \u8be5\u5904\u5df2\u5b58\u5728\u56fe\u5f62, \u6e38\u620f\u7ed3\u675f { SetPos(7, BH + 1); std::cout << \"Game Over!\"; Pause(); run(); } Board[Pixel.x + Pixel.y * BW] = exist; FillStr(Pixel.x + BX, Pixel.y + BY, fill); } } \/\/ \u663e\u793a\u56fe\u5f62 void ShowGraph() { ShowOrClear(true, \"\u25a0\"); } \/\/ \u6e05\u9664\u56fe\u5f62 void ClearGraph() { ShowOrClear(false, \" \"); } \/\/ \u6dfb\u52a0\u56fe\u5f62 void AddGraph() { sharp = rand() % 19; x = HomeX; y = HomeY; ShowGraph(); } \/\/ \u6574\u884c\u6d88\u9664 void LineRemove() { int JudgeY = BH - 1; \/\/ \u5f53\u524d\u5224\u65ad\u7684\u884c\u6570 while (JudgeY >= 0) { int cnt = 0; for (int i = 0; i < BW; ++i) if (Board[BW * JudgeY + i]) ++cnt; if (cnt != BW) \/\/ \u672a\u6ee1\u884c, \u5224\u65ad\u4e0a\u4e00\u884c --JudgeY; else \/\/ \u6ee1\u884c\u6d88\u9664 { \/\/ \u79fb\u9664JudgeY\u8fd9\u4e00\u884c for (int i = 0; i < BW; ++i) { Board[i + JudgeY * BW] = false; FillStr(i + BX, JudgeY + BY, \" \"); } \/\/ \u5c06JudgeY\u8fd9\u884c\u4e0a\u65b9\u7684\u6240\u6709\u65b9\u5757\u4e0b\u79fb\u4e00\u884c for (int i = BW * JudgeY - 1; i >= 0; --i) if (Board[i]) { Board[i] = false; FillStr(i % BW + BX, i \/ BW + BY, \" \"); Board[i + BW] = true; FillStr(i % BW + BX, i \/ BW + 1 + BY, \"\u25a0\"); } ++score; std::cout << std::setw(4); FillStr(BW + 3, 4, std::to_string(score)); std::cout << std::setw(2); FillStr(BW + 4, 8, std::to_string(speed)); } } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u4e0b\u964d bool Drop_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u4e0b\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.y > BH - 2) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y > Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + (Pixel0.y + 1) * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u4e0b\u964d void Drop() { if (!Drop_CD()) { ClearGraph(); ++y; ShowGraph(); } else { LineRemove(); AddGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u5de6\u79fb bool Left_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u6700\u5de6\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x < 1) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.y == Pixel0.y && Pixel1.x < Pixel0.x) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x - 1 + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u5de6\u79fb void Left() { if (!Left_CD()) { ClearGraph(); --x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u53f3\u79fb bool Right_CD() { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u662f\u5426\u4e3a\u8be5\u884c\u6700\u53f3\u8fb9\u7684\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[sharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x > BW - 2) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.y == Pixel0.y && Pixel1.x > Pixel0.x) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + 1 + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u53f3\u79fb void Right() { if (!Right_CD()) { ClearGraph(); ++x; ShowGraph(); } } \/\/ \u78b0\u649e\u68c0\u6d4b\uff1a\u56fe\u5f62\u65cb\u8f6c bool Ratote_CD(int NextSharp) { for (int i = 0; i < 4; ++i) { bool Point_CD = true; \/\/ \u68c0\u6d4b\u8be5\u70b9\u4e0b\u4e00\u4f4d\u7f6e\u662f\u5426\u65e0\u5176\u4ed6\u50cf\u7d20\u70b9 Point Pixel0 = SiteChange(From[NextSharp][i]); \/\/ \u662f\u5426\u8d8a\u754c if (Pixel0.x < 0 || BW - 1 < Pixel0.x || Pixel0.y > BH - 1) return true; \/\/ \u662f\u5426\u78b0\u5230\u969c\u788d\u7269 for (int j = 0; j < 4; ++j) { Point Pixel1 = SiteChange(From[sharp][j]); if (Pixel1.x == Pixel0.x && Pixel1.y == Pixel0.y) { Point_CD = false; break; } } if (Point_CD && Board[Pixel0.x + Pixel0.y * BW]) return true; } return false; } \/\/ \u56fe\u5f62\u65cb\u8f6c void Ratote() { int NextSharp = sharp; if (sharp == 6 || sharp == 10 || sharp == 14) NextSharp -= 3; else if (sharp == 1 || sharp == 16 || sharp == 18) --NextSharp; else ++NextSharp; if (!Ratote_CD(NextSharp)) { ClearGraph(); sharp = NextSharp; ShowGraph(); } } \/\/ \u521d\u59cb\u5316\u6e38\u620f void Initialize() { system(\"cls\"); AddGraph(); score = 0; speed = 1; for (bool b : Board) b = false; \/\/ \u521d\u59cb\u5316\u573a\u666f FillRec(BX - 1, BY, 1, BH, \"\u2502\"); FillRec(BX + BW, BY, 1, BH, \"\u2503\"); FillRec(BX, BY + BH, BW * 2 - 1, 1, \"\u2501\"); FillStr(BX - 1, BY + BH, \"\u2570\"); FillStr(BX + BW, BY + BH, \"\u256f\"); FillStr(BW + 2, 3, \" SCORE\"); std::cout << std::setw(4); FillStr(BW + 3, 4, std::to_string(score)); FillStr(BW + 2, 7, \" SPEED\"); std::cout << std::setw(2); FillStr(BW + 4, 8, std::to_string(speed)); } \/\/ \u8fd0\u884c\u6e38\u620f void run() { Initialize(); int t = 0; while (true) { \/\/ \u65f6\u95f4\u590d\u6742\u5ea6O(BW * BH * BH) Sleep(1); speed = score \/ 5 + 1; if (t++ > (30 - speed)) { Drop(); t = 0; } if (kbhit()) { int ch = getch(); if (ch == 224) { switch (getch()) { case 72: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0a\u952e Ratote(); \/\/ \u65cb\u8f6c\u56fe\u5f62 break; case 80: \/\/ \u6309\u4e0b\u952e\u76d8\u4e0b\u952e Drop(); \/\/ \u4e0b\u964d\u56fe\u5f62 break; case 75: \/\/ \u6309\u4e0b\u952e\u76d8\u5de6\u952e Left(); \/\/ \u5de6\u79fb\u56fe\u5f62 break; case 77: \/\/ \u6309\u4e0b\u952e\u76d8\u53f3\u952e Right(); \/\/ \u53f3\u79fb\u56fe\u5f62 break; } } else if (ch == 32) Pause(); } } } int main() { SetConsole(\"\u4fc4\u7f57\u65af\u65b9\u5757\", 40, 27, \"80\"); srand((int)time(0)); run(); }<\/code><\/pre>\n

7. \u8fd0\u884c\u6548\u679c<\/h3>\n

\"\u4fc4\u7f57\u65af\u65b9\u5757C\u8bed\u8a00\u4ee3\u7801_\u4fc4\u7f57\u65af\u65b9\u5757c++\u4ee3\u7801<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"\u4fc4\u7f57\u65af\u65b9\u5757C\u8bed\u8a00\u4ee3\u7801_\u4fc4\u7f57\u65af\u65b9\u5757c++\u4ee3\u7801\u4fc4\u7f57\u65af\u65b9\u5757\u7b80\u6613\u7248\uff08C++\uff09_\u4fc4\u7f57\u65af\u65b9\u5757c++","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4950"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=4950"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4950\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=4950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=4950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=4950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}