Exemplo n.º 1
0
 public void ModifyLength(Vector2 NewHeadPosition)
 {
     //if snake needs to grow don't remove the last body part
     if (TimesToGrow > 0)
     {
         TimesToGrow--;
         Vector2 newBodyPart = new Vector2(HeadPosition); //old head possition becomes new bodyPart
         BodyParts.Enqueue(newBodyPart);                  //add to bodyParts old head possition
         HeadPosition = NewHeadPosition;                  //update head possition
         length++;
         TryUpdateScore();
         CheckForWin();
     }
     else
     {
         Vector2 newBodyPart = new Vector2(HeadPosition); //old head possition becomes new bodyPart
         BodyParts.Dequeue();                             //remove the last bodyPart
         if (TimesToGrow < 0)
         {
             if (length > 4)
             {
                 TimesToGrow++;
                 BodyParts.Dequeue();
                 length--;
                 TryUpdateScore();
             }
             else
             {
                 TimesToGrow = 0;
             }
         }
         BodyParts.Enqueue(newBodyPart); //add to bodyParts old head possition
         HeadPosition = NewHeadPosition; //update head possition
     }
 }