{"id":1978,"date":"2023-07-04T16:04:07","date_gmt":"2023-07-04T08:04:07","guid":{"rendered":"http:\/\/mgspace.wiki\/study2\/?p=1978"},"modified":"2023-07-07T09:51:22","modified_gmt":"2023-07-07T01:51:22","slug":"2023%e5%b9%b47%e6%9c%884%e6%97%a5-%e5%ad%99%e6%98%b1%e9%9c%96-%e5%b7%a5%e4%bd%9c%e6%97%a5%e5%bf%97","status":"publish","type":"post","link":"http:\/\/mgspace.wiki\/study2\/?p=1978","title":{"rendered":"2023\u5e747\u67084\u65e5-\u5b59\u6631\u9716-\u5de5\u4f5c\u65e5\u5fd7"},"content":{"rendered":"<p>\u70b9\u51fb\u6570\uff1a173<\/p>\n<p>\u4e00\u00b7\u5de5\u4f5c\u5185\u5bb9<\/p>\n\n\n\n<p>1\u00b7ChatGPT\u4f7f\u7528\uff0c\u95ee\u7b54\uff0c\u6e38\u620f\u7f16\u5199<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"631\" src=\"http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/image.png\" alt=\"\" class=\"wp-image-1984\" srcset=\"http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/image.png 625w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/image-297x300.png 297w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/image-150x150.png 150w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;title&gt;\u8d2a\u5403\u86c7\u6e38\u620f&lt;\/title&gt;\r\n    &lt;style&gt;\r\n        #game-board {\r\n            width: 400px;\r\n            height: 400px;\r\n            border: 1px solid black;\r\n        }\r\n        .cell {\r\n            width: 20px;\r\n            height: 20px;\r\n            float: left;\r\n        }\r\n        .snake {\r\n            background-color: green;\r\n        }\r\n        .food {\r\n            background-color: red;\r\n        }\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;h1&gt;\u8d2a\u5403\u86c7\u6e38\u620f&lt;\/h1&gt;\r\n    &lt;div id=\"game-board\"&gt;&lt;\/div&gt;\r\n\r\n    &lt;script&gt;\r\n        var gameBoard = document.getElementById(\"game-board\");\r\n        var gridSize = 20;\r\n        var snake = &#091;{ x: 10, y: 10 }];\r\n        var food = { x: 5, y: 5 };\r\n        var direction = \"right\";\r\n        var gameInterval;\r\n\r\n        function drawGameBoard() {\r\n            var cells = \"\";\r\n            for (var i = 0; i &lt; gridSize; i++) {\r\n                for (var j = 0; j &lt; gridSize; j++) {\r\n                    var cellClass = \"cell\";\r\n                    if (isSnakeCell(j, i)) {\r\n                        cellClass += \" snake\";\r\n                    } else if (isFoodCell(j, i)) {\r\n                        cellClass += \" food\";\r\n                    }\r\n                    cells += \"&lt;div class='\" + cellClass + \"'&gt;&lt;\/div&gt;\";\r\n                }\r\n            }\r\n            gameBoard.innerHTML = cells;\r\n        }\r\n\r\n        function isSnakeCell(x, y) {\r\n            for (var i = 0; i &lt; snake.length; i++) {\r\n                if (snake&#091;i].x === x &amp;&amp; snake&#091;i].y === y) {\r\n                    return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\r\n        function isFoodCell(x, y) {\r\n            return food.x === x &amp;&amp; food.y === y;\r\n        }\r\n\r\n        function handleKeydown(event) {\r\n            if (event.keyCode === 37 &amp;&amp; direction !== \"right\") {\r\n                direction = \"left\";\r\n            } else if (event.keyCode === 38 &amp;&amp; direction !== \"down\") {\r\n                direction = \"up\";\r\n            } else if (event.keyCode === 39 &amp;&amp; direction !== \"left\") {\r\n                direction = \"right\";\r\n            } else if (event.keyCode === 40 &amp;&amp; direction !== \"up\") {\r\n                direction = \"down\";\r\n            }\r\n        }\r\n\r\n        function updateGame() {\r\n            var head = Object.assign({}, snake&#091;0]);\r\n            if (direction === \"left\") {\r\n                head.x--;\r\n            } else if (direction === \"up\") {\r\n                head.y--;\r\n            } else if (direction === \"right\") {\r\n                head.x++;\r\n            } else if (direction === \"down\") {\r\n                head.y++;\r\n            }\r\n\r\n            snake.unshift(head);\r\n\r\n            if (isFoodCell(head.x, head.y)) {\r\n                food.x = Math.floor(Math.random() * gridSize);\r\n                food.y = Math.floor(Math.random() * gridSize);\r\n            } else {\r\n                snake.pop();\r\n            }\r\n\r\n            drawGameBoard();\r\n        }\r\n\r\n        function startGame() {\r\n            clearInterval(gameInterval);\r\n            snake = &#091;{ x: 10, y: 10 }];\r\n            direction = \"right\";\r\n            gameInterval = setInterval(updateGame, 200);\r\n        }\r\n\r\n        document.addEventListener(\"keydown\", handleKeydown);\r\n        startGame();\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>2\u00b7\u5b89\u88c5\u4e862\u81ea\u7531\u5ea6\u8235\u673a<\/p>\n\n\n\n<p>3\u00b7\u5b66\u4e60\u4e86ESP8266 D1 mini\u4e3b\u677f\uff0c\u63a7\u5236LED\u706f\u95ea\u70c1\uff0c\u63a7\u5236\u70b9\u5934\u6447\u5934<\/p>\n\n\n\n<p>4\u00b7\u5236\u4f5c\u4e86\u673a\u5668\u4eba\u7684\u4e3b\u4f53\u7ed3\u6784<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-768x1024.jpg\" alt=\"\" class=\"wp-image-1971\" width=\"321\" height=\"428\" srcset=\"http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-768x1024.jpg 768w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-225x300.jpg 225w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-1152x1536.jpg 1152w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-1536x2048.jpg 1536w, http:\/\/mgspace.wiki\/study2\/wp-content\/uploads\/2023\/07\/IMG_20230704_154048-scaled.jpg 1920w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/figure>\n\n\n\n<p>\u4e8c\u00b7\u611f\u609f<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u70b9\u51fb\u6570\uff1a173 \u4e00\u00b7\u5de5\u4f5c\u5185\u5bb9 1\u00b7ChatGPT\u4f7f\u7528\uff0c\u95ee\u7b54\uff0c\u6e38\u620f\u7f16\u5199 \u4ee3\u7801\u5982\u4e0b\uff1a 2\u00b7\u5b89\u88c5\u4e862\u81ea\u7531\u5ea6\u8235\u673a 3\u00b7 [&hellip;]<\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[80],"class_list":{"0":"post-1978","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-uncategorized","7":"tag-ai","8":"h-entry","9":"hentry","10":"h-as-article"},"_links":{"self":[{"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/posts\/1978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1978"}],"version-history":[{"count":1,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/posts\/1978\/revisions"}],"predecessor-version":[{"id":1987,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=\/wp\/v2\/posts\/1978\/revisions\/1987"}],"wp:attachment":[{"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1978"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mgspace.wiki\/study2\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}