Step 1: Design the lattice generation function. This is a common generation function. You can input rows, columns, and cell Heights on your own. Each cell is a div. With the adjustment of CSS code, various ground sizes and widths can be generated. 2. Generate a snake. An array is used to represent the snake. Each... SyntaxHighlighter. all (); Step 1 of Program Design: design the lattice generation function. This is a common generation function. You can input rows, columns, and cell Heights on your own. Each cell is a div. With the adjustment of CSS code, various ground sizes and widths can be generated. 2. Generate a snake. An array is used to represent the snake. Each element is a div. You can use the id value to obtain the row and column attributes of the element. 3. Check direction buttons 4. Design a function to determine the next position. In this function, first determine whether there is a collision. If there is no collision, then determine the next position and change the snake shape. There are two situations at this time. The first one is not eating food. add new elements to the snake array to delete the element at the end of the Snake. The other is eating food, at this time, only new elements are added and new foods are generated. 5. Call the function code [javascript] in the previous step through setInterval.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.