title: C# Windows Form snake
body: <p>I have this simple snake game, my problem is that the tails wont add when it reaches three tails.</p>
  
  <pre><code>namespace Snake
  {
      public partial class Form1 : Form
      {
          bool left = false, right = false;
          bool top = false, down = false;
          PictureBox pic = new PictureBox();
          List&lt;PictureBox&gt; tails = new List&lt;PictureBox&gt;();
          int score = 0;
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_KeyPress(object sender, KeyPressEventArgs e)
          {
  
              if (((e.KeyChar.ToString() == "a") || (e.KeyChar.ToString() == "A"))&amp;&amp;(right == false))
              {
                  right = false;
                  top = false;
                  down = false;
                  left = true;
  
              }
              else if (((e.KeyChar.ToString() == "d") || (e.KeyChar.ToString() == "D"))&amp;&amp; (left == false))
              {
                  top = false;
                  down = false;
                  left = false;
                  right = true;
              }
              else if (((e.KeyChar.ToString() == "w") || (e.KeyChar.ToString() == "W"))&amp;&amp; (down == false))
              {
                  down = false;
                  left = false;
                  right = false;
                  top = true;
              }
              else if (((e.KeyChar.ToString() == "s") || (e.KeyChar.ToString() == "S"))&amp;&amp; (top == false))
              {
                  top = false;
                  left = false;
                  right = false;
                  down = true;
              }
  
          }
  
  
  
          private void timer1_Tick(object sender, EventArgs e)
          {
              //ticks every 1 sec
              if (pic.Location == head.Location)
              {
                  score++;
                  spawnFood();
                  tails.Add(addTails());
              }
              sortLocation();
              if (right == true)
              {
                  int r = head.Location.X + head.Height;
                  head.Location = new Point(r, head.Location.Y);
              }
              else if(left == true)
              {
                  int l = head.Location.X - head.Height;
                  head.Location = new Point(l, head.Location.Y);
              }
              else if (top == true)
              {
                  int t = head.Location.Y - head.Height;
                  head.Location = new Point(head.Location.X, t);
              }
              else if (down == true)
              {
                  int d = head.Location.Y + head.Height;
                  head.Location = new Point(head.Location.X,d);
              }
              txtScore.Text = score.ToString();
          }
  
          private void sortLocation()
          {
              if (tails.Count == 0)
              {
  
              }
              else
              {
                  for (int i = 1; i &lt; tails.Count; i++)
                  {
                      tails[i].Location = tails[i-1].Location;
                  }
                  tails[0].Location = head.Location;
              }
          }
  
          private PictureBox addTails()
          {
              PictureBox tail = new PictureBox();
              tail.Name = "tail" + score.ToString();
              tail.BackColor =  Color.Black;
              tail.Width = 10;
              tail.Height = 10;
              this.Controls.Add(tail);
              return tail;
          }
  
          private void spawnFood()
          {
              Random rnd = new Random();
              int rndLocationX = rnd.Next(10, 50);
              int rndLocationY = rnd.Next(10, 50);
              pic.BackColor = Color.Red;
              pic.Height = 10;
              pic.Width = 10;
              this.Controls.Add(pic);
              if (rndLocationX &gt;= 500)
              {
                  rndLocationX -= 10;
              }
              if (rndLocationY &gt;= 500)
              {
                  rndLocationY -= 10;
              }
              pic.Location = new Point(rndLocationX*10,rndLocationY*10);
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
              timer1.Start();
              spawnFood();
          }
      }
  }
  </code></pre>