1, we need to create four header files, and then set the state of the snake, up, down, left and right respectively, which is the premise that the snake can walk in a direction. Then we set the nodes of the snake body and define a simple function, so that the whole body of the snake and its walking direction are completed.
2, snakes can't go through walls.
3, the second step, a function The purpose of this function is that snakes can't go through walls. It's very simple. Set the maximum displacement of length and width separately, and set it to 1 in the internal range to pass, otherwise you can't go through the wall. The snake randomly produces a kind of food.
4. Set a random function. This completes the snake code.
Smart programming is a building block code programming software for the field of STEAM education, which is developed based on graphical programming.