static void Main(string[] args) { Nextlvl.Deserialize(); GameState game = new GameState(); if (Returnlvl.count == 1) { Butter.username = Returnlvl.login; Butter.score = Returnlvl.score; Savescore.Deserialize(); Console.Clear(); game.Run2(); while (true) { if (Butter.gameOver) { GameState.gameover(); } game.DrawScore(); ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); game.ProcessKeyEvent(consoleKeyInfo); } } else { Console.WriteLine("Champions:"); Savescore.Deserialize(); DesOutput.PrintScore(); Console.WriteLine("Enter username:"); Butter.username = Console.ReadLine(); Console.Clear(); game.Run(); while (true) { if (Butter.gameOver) { GameState.gameover(); } ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); game.ProcessKeyEvent(consoleKeyInfo); game.DrawScore(); } } }
public void ProcessKeyEvent(ConsoleKeyInfo consoleKeyInfo) { switch (consoleKeyInfo.Key) { case ConsoleKey.UpArrow: worm.dx = 0; worm.dy = -1; break; case ConsoleKey.DownArrow: worm.dx = 0; worm.dy = 1; break; case ConsoleKey.RightArrow: worm.dx = 1; worm.dy = 0; break; case ConsoleKey.LeftArrow: worm.dx = -1; worm.dy = 0; break; case ConsoleKey.Escape: timer.Enabled = !timer.Enabled; Savescore.Serialize(); Nextlvl.Serialize(1, "n", 20, 20, 0, -1); Environment.Exit(0); break; case ConsoleKey.R: System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName); Environment.Exit(0); break; } }