public static Worm Load(string title) { Worm res = null; using (FileStream fs = new FileStream(title + ".xml", FileMode.Open, FileAccess.Read)) { XmlSerializer xs = new XmlSerializer(typeof(Worm)); res = xs.Deserialize(fs) as Worm; } return(res); }
public void KeyPressed(ConsoleKeyInfo pressedKey) { switch (pressedKey.Key) { case ConsoleKey.UpArrow: w.ChangeDirection(0, -1); break; case ConsoleKey.DownArrow: w.ChangeDirection(0, 1); break; case ConsoleKey.LeftArrow: w.ChangeDirection(-1, 0); break; case ConsoleKey.RightArrow: w.ChangeDirection(1, 0); break; case ConsoleKey.S: w.Save("worm"); break; case ConsoleKey.L: wormTimer.Stop(); w.Clear(); f = new Food('$', ConsoleColor.Yellow); wall = new Wall('#', ConsoleColor.DarkYellow, @"Levels/Level2.txt"); w = Worm.Load("worm"); wormTimer.Start(); break; case ConsoleKey.Escape: IsRunning = false; // wormTimer.Stop(); break; case ConsoleKey.Spacebar: if (!pause) { wormTimer.Stop(); pause = true; } else { wormTimer.Start(); pause = false; } break; } }