title: programming snake in c# with console
body: <p>I'm trying to make a snake in the console to keep me in training in c #. I have a problem in the movement. To test I wanted to do so by pressing the letter "a" would shift the "food" on the X I noticed that in terms of graphics, but does not move through a Console.Write is incremented. Can you give me a hand? I am attaching the main classes, world food</p>
  
  <p>Main:</p>
  
  <pre><code>namespace Snake
  {
      class Program
      {
          static void Main(string[] args)
          {
  
              char s;
              World mondo = new World(20, 10);
              do
              {
                  s = char.Parse(Console.ReadLine());
  
  
                  mondo.update();
                  mondo.drawWorld();
  
              }
  
              while (s == 'a');
  
              Console.ReadLine();
  
          }
      }
  }
  </code></pre>
  
  <p>World:</p>
  
  <pre><code>namespace Snake
  {
      class World
      {
          public int larghezza;
          public int altezza;
          public int sizeSnake = 3;
          public Food food;
          public Snake[] snake;
          public Snake s;
  
          public enum Box { FREE , FOOD, SNAKE };//0,1,2
          public Box[,] size;
  
  
          public World(int larghezza, int altezza)
          {
              this.larghezza = larghezza;
              this.altezza = altezza;
              size = new Box[larghezza, altezza];
              food = new Food();
              snake = new Snake[sizeSnake];
              s = new Snake();
              food.InstaceFood(altezza, larghezza);
              size[food.pos.x,food.pos.y] = Box.FOOD;
  
              for (int i = 0; i &lt; sizeSnake; i++)
              {
                  snake[i] = s;
                  snake[0].startSnake(altezza, larghezza);
                  size[snake[i].pos.x-i, snake[i].pos.y] = Box.SNAKE;
              }
  
  
         }
  
          public void update()
          {
  
             // snake[0].move(snake);
              food.moveee();
          }
  
          public void control (Box type)
          {
              switch (type)
              {
                  case Box.FOOD:
                       Console.ForegroundColor = ConsoleColor.Red;
                       Console.Write('X');
                       Console.ResetColor();
                       break;
  
                  case Box.FREE:
                       Console.Write(' ');
                       break;
                  case Box.SNAKE:
                       Console.ForegroundColor = ConsoleColor.Green;
                       Console.Write('█');
                       Console.ResetColor();
                       break;
  
              }
  
          }
  
  
  
  
          public void drawWorld()
          {
  
              Console.Write('╔');
              for (int i = 0; i &lt; larghezza; i++)
              {
                  Console.Write('═');
              }
              Console.Write('╗');
  
              for (int i = 0; i &lt; altezza; i++)
              {
                  Console.Write('\n');
  
                  for (int j = 0; j &lt; larghezza; j++)
                  {
  
                      if (j == 0)
                      {
                          Console.Write('║');
                      }
  
                         control(size[j,i]);
  
                          if (j == larghezza - 1)
                          Console.Write('║');
                  }
  
              }
              Console.Write('\n');
              Console.Write('╚');
              for (int i = 0; i &lt; larghezza; i++)
              {
                  Console.Write('═');
              }
              Console.WriteLine('╝');
          }
      }
  }
  </code></pre>
  
  <p>Food:</p>
  
  <pre><code>namespace Snake
  {
      class Food
      {
          Random rnd = new Random();
          public Vector2 pos;
  
          public Food()
          {
  
          }
  
  
          public void InstaceFood(int _Altezza, int _Larghezza)
          {
  
              int rndY = rnd.Next(0, _Altezza);
              int rndX = rnd.Next(0, _Larghezza);
              pos.x = rndX;
              pos.y = rndY;
          }
  
          public void moveee()
          {
              this.pos.x += 1;
          }
      }
  }
  </code></pre>
  
  <p>Vector2:</p>
  
  <pre><code>namespace Snake
  {
      struct Vector2
      {
          public int x;
          public int y;
  
          public Vector2(int xx, int yy)
          {
              x = xx;
              y = yy;
  
          }
      }
  }
  </code></pre>