{"id":99,"date":"2020-10-04T11:46:10","date_gmt":"2020-10-04T03:46:10","guid":{"rendered":"https:\/\/www.lazybirds.top\/?p=99"},"modified":"2021-10-19T23:16:59","modified_gmt":"2021-10-19T15:16:59","slug":"%e8%b4%aa%e5%90%83%e8%9b%87-100%e8%a1%8c%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.lazybirds.top\/?p=99","title":{"rendered":"\u8d2a\u5403\u86c7 &#8211; 100\u884c\u7248\u672c"},"content":{"rendered":"\n<h1 id=\"\u7b80\u4ecb\">\u7b80\u4ecb<\/h1>\n\n\n\n<p>\u9ad8\u4e00\u65f6\u53d7\u5b66\u6821\u56fe\u5f62\u8ba1\u7b97\u5668\u4e0a\u539f\u88c5\u8d2a\u5403\u86c7\u7a0b\u5e8f\u542f\u53d1\u800c\u5199\u7684C++\u5c0f\u6e38\u620f<\/p>\n\n\n\n<p>\u9ad8\u4e09\u65f6\u6574\u7406\u538b\u7f29\u81f3100\u884c<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 id=\"\u4ee3\u7801\">\u4ee3\u7801<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">\/\/By Eric Jin 2018     \u7f16\u8bd1\u540e\u5207\u6362\u81f3\u82f1\u6587  a\u5de6d\u53f3w\u4e0as\u4e0b       \u4f7f\u7528\u4e86Sleep() _kbhit() _getch() system(\"cls\")\u7b49\n#include &lt;iostream&gt; \n#include &lt;sstream&gt;\n#include &lt;string&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;conio.h&gt;\n#include &lt;time.h&gt;\n#include &lt;windows.h&gt;\nstd::string o(int i)\/\/4\u5de66\u53f38\u4e0a2\u4e0b\n{\n\tif (i == 0) return \"  \";\n\telse if (i == 1) return \"# \";\n\telse if (i == 3) return \"$ \";\n\telse return \"* \";\n}\nvoid drawmap(int h, int l, int maptest[100][100])\/\/\u7ed8\u56fe\n{\n\tstd::stringstream ss;\n\tfor (int i = 1; i &lt;= h; i++)\n\t{\n\t\tfor (int j = 1; j &lt;= l; j++) ss &lt;&lt; o(maptest[i][j]);\n\t\tss &lt;&lt; std::endl;\n\t}\n\tstd::string out = ss.str();\n\tsystem(\"cls\");\n\tstd::cout &lt;&lt; out;\n}\nvoid findfood(int maptest[100][100], int&amp; foodx, int&amp; foody, int h, int l)\/\/\u51fa\u98df\u7269\n{\n\tfor (;;)\n\t{\n\t\tsrand((int)time(0));\n\t\tfoodx = rand() % h + 1, foody = rand() % l + 1;\n\t\tif (maptest[foodx][foody] == 0) break;\n\t}\n}\nint gamein()\n{\n\tint speed, h = 20, l = 30, tail = 6, maptest[100][100], x = h \/ 2, y = l \/ 2, tx = h \/ 2, ty = l \/ 2 - tail, foodx, foody, dir = 6, tdir = 6, food = 0;\n\tbool skip = 0;\n\tstd::cout &lt;&lt; \"Speed (100-slow 50-medium 10-fast):\" &lt;&lt; std::endl;\n\tstd::cin &gt;&gt; speed;\n\tSleep(500);\n\tsystem(\"cls\");\n\tfor (int i = 1; i &lt;= h; i++)\/\/\u8bbe\u7f6e\u8fb9\u754c\n\t{\n\t\tfor (int j = 1; j &lt;= l; j++)\n\t\t{\n\t\t\tmaptest[i][j] = 0;\n\t\t\tif (i == 1 || i == h) maptest[i][j] = 1;\n\t\t}\n\t\tmaptest[i][1] = 1, maptest[i][l] = 1;\n\t}\n\tfor (int i = ty + 1; i &lt;= y; i++) maptest[x][i] = 6;\n\tfindfood(maptest, foodx, foody, h, l);\n\tmaptest[foodx][foody] = 3;\n\tdrawmap(h, l, maptest);\n\tfor (;;)\n\t{\n\t\tmaptest[x][y] = dir;\n\t\tx = (dir == 2) ? (x + 1) : (dir == 8 ? x - 1 : x), y = (dir == 6) ? (y + 1) : (dir == 4 ? y - 1 : y);\n\t\tif (maptest[x][y] == 0 || maptest[x][y] == 3) maptest[x][y] = dir;\n\t\telse\n\t\t{\n\t\t\tstd::cout &lt;&lt; std::endl &lt;&lt; \"You died.\" &lt;&lt; std::endl &lt;&lt; \"Score: \" &lt;&lt; food &lt;&lt; std::endl &lt;&lt; \"Speed: \" &lt;&lt; speed &lt;&lt; std::endl;\n\t\t\tstd::cout &lt;&lt; \"0:exit\" &lt;&lt; std::endl;\n\t\t\tstd::cout &lt;&lt; \"1:new game\" &lt;&lt; std::endl;\n\t\t\tchar in1 = _getch();\n\t\t\tstd::cout &lt;&lt; std::endl;\n\t\t\tif (in1 == '0') return 0;\n\t\t\telse return gamein();\n\t\t}\n\t\tif (skip == 0)\n\t\t\ttx = (tdir == 2) ? (tx + 1) : (tdir == 8 ? tx - 1 : tx), ty = (tdir == 6) ? (ty + 1) : (tdir == 4 ? ty - 1 : ty), tdir = maptest[tx][ty];\n\t\telse skip = 0;\n\t\tmaptest[tx][ty] = 0;\n\t\tdrawmap(h, l, maptest);\n\t\tstd::cout &lt;&lt; \"Score: \" &lt;&lt; food &lt;&lt; std::endl &lt;&lt; \"Speed: \" &lt;&lt; speed &lt;&lt; std::endl;\n\t\tSleep(speed);\n\t\tif (_kbhit() != 0)\n\t\t{\n\t\t\tint in = _getch();\n\t\t\tif (in == 97 &amp;&amp; dir != 4 &amp;&amp; dir != 6) dir = 4;\n\t\t\tif (in == 115 &amp;&amp; dir != 2 &amp;&amp; dir != 8) dir = 2;\n\t\t\tif (in == 119 &amp;&amp; dir != 2 &amp;&amp; dir != 8) dir = 8;\n\t\t\tif (in == 100 &amp;&amp; dir != 4 &amp;&amp; dir != 6) dir = 6;\n\t\t}\n\t\tif (x == foodx &amp;&amp; y == foody)\n\t\t{\n\t\t\tfood++;\n\t\t\tfindfood(maptest, foodx, foody, h, l);\n\t\t\tmaptest[foodx][foody] = 3;\n\t\t\tskip = 1;\n\t\t}\n\t}\n}\nint main()\n{\n\treturn gamein();\n}<\/code><\/pre>\n\n\n\n<h1 id=\"\u56fe\u7247\">\u56fe\u7247<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"720\" height=\"589\" src=\"https:\/\/i0.wp.com\/www.lazybirds.top\/wp-content\/uploads\/2020\/10\/2020-04-08-Snake.jpg?resize=720%2C589&#038;ssl=1\" alt=\"\" class=\"wp-image-100\" srcset=\"https:\/\/i0.wp.com\/www.lazybirds.top\/wp-content\/uploads\/2020\/10\/2020-04-08-Snake.jpg?w=720&amp;ssl=1 720w, https:\/\/i0.wp.com\/www.lazybirds.top\/wp-content\/uploads\/2020\/10\/2020-04-08-Snake.jpg?resize=300%2C245&amp;ssl=1 300w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" data-recalc-dims=\"1\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u9ad8\u4e00\u65f6\u53d7\u5b66\u6821\u56fe\u5f62\u8ba1\u7b97\u5668\u4e0a\u539f\u88c5\u8d2a\u5403\u86c7\u7a0b\u5e8f\u542f\u53d1\u800c\u5199\u7684C++\u5c0f\u6e38\u620f \u9ad8\u4e09\u65f6\u6574\u7406\u538b\u7f29\u81f3100\u884c<\/p>\n","protected":false},"author":1,"featured_media":100,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[12,11],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.lazybirds.top\/wp-content\/uploads\/2020\/10\/2020-04-08-Snake.jpg?fit=720%2C589&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":0,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=\/wp\/v2\/media\/100"}],"wp:attachment":[{"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lazybirds.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}