Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use 63 lines of code in html5 to realize the game of gluttonous snake

Shulou Source: shulou.com Published: 2022-06-01 07:26:45 10月01日 Update

This article mainly introduces how to use 63 lines of code to achieve the gluttonous Snake game in html5. The article is very detailed and has a certain reference value. Interested friends must read it!

The code is as follows:

Var c=document.getElementById ("myCanvas"); var time = 160,160; / Snake Speed var cxt=c.getContext ("2d"); var x = y = 8 interval var a = 0; / / Food coordinates var t = 20; / / body length var map = []; / / record snake running path var size = 8; / / Snake body unit size var direction = 2; / / 1 upward 2 to right 0 left 3 down interval = window.setInterval (set_game_speed, time) / / Mobile snake function set_game_speed () {/ / Mobile snake switch (direction) {case 1vex = y case sizescapebreakcase 2burex = xMusizescapebreakCase 0Wholx = xMusizescaptCase 3ZX;} if (x > 400 | | y > 400 | | x

Tags: Color code food content array rectangle article border movement value element interest unit reason coordinate size boy buddy tail data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei OPPO Reno Shulou Tech Info NVidia