Thread: Noob quastion reguarding snake.c

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Noob quastion reguarding snake.c

    Hi all, im working on a school project, where we is supposed to build the classic game snake.
    to represent the snake Im using a linked list(*list). To move the snake ill use a function called move_snake, where ill take the last body_segment (tale) and place it in front of the snake as the new head segment. Thats works fine except for the rest of the body parts, my problem and question is regarding the rest of the snake body.. Ill need a function for moving the rest of the body segment. Ill been asked to use a pointer that points to the rest of the body (**body). But dont know how to implement it. Ill hope I posted my question in the right forum, otherwise pls let me know.


    Code:
    void move_snake(snake_body *list, body_segments *pos){
    
       snake_body *tale, *cur, *newHead;
    
       switch(pos->dir){
    
        case RIGHT : list->segment.x++; break;
    
        case DOWN  : list->segment.y++; break;
    
        case LEFT  : list->segment.x--; break;
    
        case UP    : list->segment.y--; break;
    
      }
    
      for(cur = list; cur->next != NULL; cur = cur->next){
    
        tale=cur;
    
      } 
    
      tale->next = NULL;
    
      cur->next = list;
    
      cur->segment.x = pos->x;
    
      cur->segment.y = pos->y;
    
      cur->segment.dir = pos->dir;
    
      newHead=cur;
     
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    Oh got it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM