Character game-Smart snake frame __ Frame

Source: Internet
Author: User
Tags array length sleep function

Mission Requirements: The task of this project is to make snakes have a certain intelligence, through the algorithm has "perception-decision-action" ability. In the next step, you can make a gorgeous character interface, realize the human-controlled snake and the smart snake grab food war.

The teacher recommended frame:

My general idea and main function for understanding:
1. The position of the snake and food is represented by X (transverse right) and Y (portrait below), so each coordinate is between (1,1) to (10,10).
2. Record the coordinates of x and y of snakes and food with two arrays, the first array records the X-coordinate, and the second array records y coordinates.
3. The first digit of each array is used for food coordinates, and the last digit is used for the head of the snake, except for the last few digits of the head used as the snake body. Each move the array length plus one.
4. Using an integer i to postpone the coordinate, I can be used as the number of steps. Use the snakelength to record the length of the snake, so that the program knows the coordinates of how many numbers to count. And when food was eaten to make it +1.


(Note that the sleep function is 1000 inside the Windows system, under the Unbutu should be sleep (1), they mean 1 seconds)

Here are only the main functions, and to learn more about the accompanying functions, please stamp my next blog post.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.