static void Main(string[] args) { if (args.Length != 0) { gameX = Convert.ToInt32(args[0]); gameY = Convert.ToInt32(args[1]); } oldWX = Console.WindowWidth; oldWY = Console.WindowHeight; SnakeGameField game = new SnakeGameField(gameX, gameY); Console.SetWindowSize(gameX * 2, gameY); Thread keyReaderThread = new Thread(new ThreadStart(KeyReader)); keyReaderThread.Name = "KeyRegister"; keyReaderThread.Start(); DirectionEvent += game.SetDirection; game.GameOverEvent += (gameSender, score) => { Console.SetWindowSize(oldWX, oldWY); Console.Clear(); Console.WriteLine("Game over! Your final score is {0}.", score); play = false; }; Console.Clear(); game.DrawGame(); while (game.Continues) { Tick(game, delay); } }
static void Tick(SnakeGameField game, int miliseconds) { game.MoveSnake(); Thread.Sleep(miliseconds); }