title: How do i restart a console game?
body: <p>I'm new to programming and i started with c#. So i followed a tutorial on making a simple game in console. <a href="https://www.youtube.com/watch?v=o1c7PYHhmow" rel="nofollow noreferrer">Here's the tutorial</a>. And when i finished the tutorial i was left with a decent game but it wasnt polished. The game doesn't restart itself.</p>
  
  <p>I've tried some different ways trying to get around it but nothing i tried seemed to work (because im new and half the coding didnt make sense).</p>
  
  <p>So i tried this. why doesn't this work?</p>
  
  <pre><code>using System;
  using System.Threading;
  using System.Diagnostics;
  
  namespace DodgeGame
  {
  
  public class Game
  {
      //This is our constructor,
      // it gets run auto when new instance is made.
      public Game()
      {
          //PLAYER
          playerUnit = new PlayerUnit(5, 5, "@");
  
          //ENEMY
          enemyUnits = new Unit[ numEnemies ];
  
          Random = new Random();
          Score = 0;
  
              for(int i = 0; i &lt; numEnemies; i++)
              {
                  int row = Random.Next(0, Console.WindowHeight - 1);
                  enemyUnits[i] = new EnemyUnit(Console.WindowWidth -1, row , "&lt;");
              }
  
          stopwatch = new Stopwatch();
      }
  
  
  
      private Stopwatch stopwatch;
  
      private Unit playerUnit;
  
      private int numEnemies = 20;
      private Unit[] enemyUnits;
  
      public static Random Random;
      public static int Score;
  
      public void Run()
      {
  
          stopwatch.Start();
          long timeAtPreviousFrame = stopwatch.ElapsedMilliseconds;
  
  
          while(true)
          {
              //Time since last frame.
              int deltaTimeMS = (int)(stopwatch.ElapsedMilliseconds
                                      - timeAtPreviousFrame);
              timeAtPreviousFrame = stopwatch.ElapsedMilliseconds;
  
  
              //Updating Units.
              playerUnit.Update(deltaTimeMS);
  
              for(int i = 0; i &lt; enemyUnits.Length; i++)
              {
                  enemyUnits[i].Update(deltaTimeMS);
  
                  if( playerUnit.IsCollidingWith(enemyUnits[i]))
                  {
                      //Then game over.
                      GameOver();
                      return;
                  }
              }
              playerUnit.Draw();
  
              foreach (Unit u in enemyUnits)
              {
                  u.Draw();
              }
  
  
              //Draw the score.
              Console.SetCursorPosition(0, Console.WindowHeight - 1);
              Console.Write("SCORE: " + Score.ToString() );
  
              //Lets just do a tiny sleep to avoid running at too high of fps.
              Thread.Sleep( 5 );
  
          }
  
          //PROGRAM END.
      }
  
      void GameOver()
          {
          Console.Clear();
          Console.WriteLine("Game Over. Your Score was: " + Score);
          Console.WriteLine("Insert Name to LeaderBoard:");
          //TODO: Make a local leaderboard?
  
          if(Console.KeyAvailable == true)
          {
              ConsoleKeyInfo cki = Console.ReadKey(true);
              while(cki.Key != ConsoleKey.Escape)
              {
                  if(cki.Key == ConsoleKey.Spacebar) Game();
                  cki = Console.ReadKey(true);
              }
  
  
          Console.SetCursorPosition(0,Console.WindowHeight - 1);
  
  
          }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I want to restart my game without closing the window.</p>
  
  <p>Sorry if this isnt enough info to help.</p>