Logic for Cobrinha game [closed]

1

Hello, I want to play a game of C in the C library using the curses library, I started, but I'm not finding a logic to draw the snake on the screen when the user presses the arrows, I want to know what a logic would be to draw it in according to the keys. I do not know if my doubt was clear.

    
asked by anonymous 28.03.2016 / 18:38

1 answer

2

With a brief search, I found some tutorials on the net.

Brief explanation:

You hold all snake units in a list.

There are head and tail, which are the first and last elements of the list. So it's really a queue.

At every turn, determine the direction in which you should move. For example, if the direction is left, then the coordinates of the next head will be at (-1.0) relative to the current head. Insert new unit in the list in the head position with the coordinates determined previously.

Remove the tail unit from the list (on the screen). It will organize the movement. If you find a little food in the head position, start a growth counter. At every instant, counter-growth > 0, decrease it and ignore the tail unit removal. Thus, only the head will move until it grows.

  

references:    link

     

link

     

link

    
28.03.2016 / 19:04