title: C# Console Snake Tail won't be Removed
body: <p>I needed to program a snake game in a C# console application. I have a snake that can move, but the only problem is that it's tail won't cut, which means you can basiclly keep growing on every step done without eating a single block. I'll be happy if you could help me with that. Here's the code:</p>
  
  <pre><code>namespace ConsoleApplication11
  {
   class Program
   {
      static void MainMenu() 
      {
          Console.SetCursorPosition(40, 12);
          Console.ForegroundColor = ConsoleColor.Blue;
          Console.Write("S");
          Console.ForegroundColor = ConsoleColor.Green;
          Console.Write("N");
          Console.ForegroundColor = ConsoleColor.Red;
          Console.Write("A");
          Console.ForegroundColor = ConsoleColor.Magenta;
          Console.Write("K");
          Console.ForegroundColor = ConsoleColor.Yellow;
          Console.WriteLine("E");
          Console.ResetColor();
          Console.SetCursorPosition(32, 13);
          Console.WriteLine("Press Enter to start!");
      }
      static void SnakeMovement()
      {
          Console.Clear();
          Random rnd = new Random();
          int foodX = rnd.Next(1, 80);
          int foodY = rnd.Next(1, 25);
          int snakeX = rnd.Next(1, 80);
          int snakeY = rnd.Next(1, 25);
          if ((snakeX == foodX) &amp;&amp; (snakeY == foodY))
          {
              snakeX = rnd.Next(1, 80);
              snakeY = rnd.Next(1, 25);
          }
          int i = 0;
          int userScore = 0;
          ConsoleKeyInfo userAction;
          int[] ArrSnakeItselfX = new int[2000];
          int[] ArrSnakeItselfY = new int[2000];
          ArrSnakeItselfX[1] = (snakeX);
          ArrSnakeItselfY[1] = (snakeY);
          ArrSnakeItselfX[2] = (snakeX);
          ArrSnakeItselfY[2] = (snakeY - 1);
          ArrSnakeItselfX[3] = (snakeX);
          ArrSnakeItselfY[3] = (snakeY - 2);
          Console.SetCursorPosition(foodX, foodY);
          Console.ForegroundColor = ConsoleColor.Yellow;
          Console.Write("#");
          Console.ResetColor();
          i = ArrSnakeItselfX.Count();
          while (true)
          {
              Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0]);
              Console.Write("@");
              Console.SetCursorPosition(ArrSnakeItselfX[1], ArrSnakeItselfY[1]);
              Console.Write("$");
              Console.SetCursorPosition(ArrSnakeItselfX[2], ArrSnakeItselfY[2]);
              Console.Write("$");
              if ((snakeX == foodX) &amp;&amp; (snakeY == foodY))
              {
                  foodX = rnd.Next(1, 80);
                  foodY = rnd.Next(1, 25);
                  Console.SetCursorPosition(foodX, foodY);
                  Console.ForegroundColor = ConsoleColor.Yellow;
                  Console.Write("#");
                  Console.ResetColor();
                  i = ArrSnakeItselfX.Count();
                  userScore++;
              }
              userAction = Console.ReadKey(true);
              if (userAction.Key == ConsoleKey.W)
              {
                  while (!Console.KeyAvailable)
                  {
                      ArrSnakeItselfY[0]--;
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0]);
                      Console.Write("@");
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0] + 1);
                      Console.Write("$");
                      Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                      Console.Write(" ");
                      Thread.Sleep(500);
                      if ((ArrSnakeItselfX[0] == foodX) &amp;&amp; (ArrSnakeItselfY[0] == foodY))
                      {
                          foodX = rnd.Next(1, 80);
                          foodY = rnd.Next(1, 25);
                          Console.SetCursorPosition(foodX, foodY);
                          Console.ForegroundColor = ConsoleColor.Yellow;
                          Console.Write("#");
                          Console.ResetColor();
                          ArrSnakeItselfX[i] = (ArrSnakeItselfX[i - 1]);
                          ArrSnakeItselfY[i] = (ArrSnakeItselfY[i - 1] + 1);
                          i = ArrSnakeItselfX.Count();
                          Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                          userScore++;
                      }
                  }
              }
              if (userAction.Key == ConsoleKey.D)
              {
                  while (!Console.KeyAvailable)
                  {
                      ArrSnakeItselfX[0] = ArrSnakeItselfX[0] + 1;
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0]);
                      Console.Write("@");
                      Console.SetCursorPosition(ArrSnakeItselfX[0] - 1, ArrSnakeItselfY[0]);
                      Console.Write("$");
                      Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                      Console.Write("");
                      Thread.Sleep(500);
                      if ((ArrSnakeItselfX[0] == foodX) &amp;&amp; (ArrSnakeItselfY[0] == foodY))
                      {
                          foodX = rnd.Next(1, 80);
                          foodY = rnd.Next(1, 25);
                          Console.SetCursorPosition(foodX, foodY);
                          Console.ForegroundColor = ConsoleColor.Yellow;
                          Console.Write("#");
                          Console.ResetColor();
                          ArrSnakeItselfX[i] = (ArrSnakeItselfX[i - 1]);
                          ArrSnakeItselfY[i] = (ArrSnakeItselfY[i - 1] + 1);
                          i = ArrSnakeItselfX.Count();
                          Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                          userScore++;
                      }
                  }
              }
              if (userAction.Key == ConsoleKey.A)
              {
                  while (!Console.KeyAvailable)
                  {
                      ArrSnakeItselfX[0] = ArrSnakeItselfX[0] - 1;
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0]);
                      Console.Write("@");
                      Console.SetCursorPosition(ArrSnakeItselfX[0] + 1, ArrSnakeItselfY[0]);
                      Console.Write("$");
                      Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                      Console.Write("");
                      Thread.Sleep(500);
                      if ((ArrSnakeItselfX[0] == foodX) &amp;&amp; (ArrSnakeItselfY[0] == foodY))
                      {
                          foodX = rnd.Next(1, 80);
                          foodY = rnd.Next(1, 25);
                          Console.SetCursorPosition(foodX, foodY);
                          Console.ForegroundColor = ConsoleColor.Yellow;
                          Console.Write("#");
                          Console.ResetColor();
                          ArrSnakeItselfX[i] = (ArrSnakeItselfX[i - 1]);
                          ArrSnakeItselfY[i] = (ArrSnakeItselfY[i - 1] + 1);
                          i = ArrSnakeItselfX.Count();
                          Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                          userScore++;
                      }
                  }
              }
              if (userAction.Key == ConsoleKey.S)
              {
                  while (!Console.KeyAvailable)
                  {
                      ArrSnakeItselfY[0]++;
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0]);
                      Console.Write("@");
                      Console.SetCursorPosition(ArrSnakeItselfX[0], ArrSnakeItselfY[0] - 1);
                      Console.Write("$");
                      Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                      Console.Write("");
                      Thread.Sleep(500);
                      if ((ArrSnakeItselfX[0] == foodX) &amp;&amp; (ArrSnakeItselfY[0] == foodY))
                      {
                          foodX = rnd.Next(1, 80);
                          foodY = rnd.Next(1, 25);
                          Console.SetCursorPosition(foodX, foodY);
                          Console.ForegroundColor = ConsoleColor.Yellow;
                          Console.Write("#");
                          Console.ResetColor();
                          ArrSnakeItselfX[i] = (ArrSnakeItselfX[i - 1]);
                          ArrSnakeItselfY[i] = (ArrSnakeItselfY[i - 1] + 1);
                          i = ArrSnakeItselfX.Count();
                          Console.SetCursorPosition(ArrSnakeItselfX[i - 1], ArrSnakeItselfY[i - 1]);
                          userScore++;
                      }
                  }
              }
          }
      }      
      static void Main(string[] args)
      {
          while (true)
          {
              Console.CursorVisible = false;
              ConsoleKeyInfo userStartingGame;
              MainMenu();
              userStartingGame = Console.ReadKey(true);
              if (userStartingGame.Key == ConsoleKey.Enter)
              {
                  SnakeMovement();
              }
              else
              {
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>