What is the general idea of writing snake games in Java?
I have the code and jar package here. Let me briefly talk about the idea: First, we need to draw a block on the canvas. This block is the head of a snake, but the snake will get longer, so we need to use something to store the snake, so we can use array, ArrayList, LinkedList and so on (I prefer to use LinkedList). Although the snake is mentioned here, it is actually the x and y coordinates of a block. The snake is well drawn. This requires a thread and a move () method to keep it moving. The snake is moving, but it has no direction. At this time, we need a way to make it have a direction, but we should pay attention to the fact that the opposite direction can't change the direction (that is, the snake has a direction and can't move, but it won't work when it reaches the edge. At this time, the game will be out of bounds and food will appear. Be careful that food is not allowed out of bounds. If there is food, the snake will eat it. At this time, it is necessary to eat the food in a way. When it is eaten, the snake will grow a piece and the food will reappear. Snakes grow up, but they can touch their own bodies. Then you have to do something to let it touch and end the game. This is the original idea. Here are some details, so I won't talk about them.