public void PacmanNotGoDown_NotStarPlus_NotStarClearInField() { Field field = new Field(); Pacman.Pacman pacman = new Pacman.Pacman(field); pacman.RealtimeCoordinate = new Coordinate(1, 4); field.NewField[1, 4] = "C"; Assert.IsFalse(pacman.GoDown()); Assert.AreEqual("C", field.NewField[1, 4]); Assert.AreEqual(0, pacman.stars); }
public void PacmanGoDown_StarPlus_StarClearInField() { Field field = new Field(); Pacman.Pacman pacman = new Pacman.Pacman(field); pacman.RealtimeCoordinate = new Coordinate(7, 1); field.NewField[7, 1] = "C"; Assert.IsTrue(pacman.GoDown()); Assert.AreEqual(" ", field.NewField[7, 1]); Assert.AreEqual(1, pacman.stars); }
//Запуск игры public void Start() { int timer = 0; int counter = 0; ConsoleKeyInfo keyInfo2, keyTemp; Console.Clear(); gameField.Print(score, lives); do { keyInfo2 = Console.ReadKey(true); } while (keyInfo2.Key != ConsoleKey.LeftArrow && keyInfo2.Key != ConsoleKey.DownArrow && keyInfo2.Key != ConsoleKey.RightArrow && keyInfo2.Key != ConsoleKey.UpArrow); keyTemp = keyInfo2; do { if (timer++ % 20 == 0) { if (counter < ghosts.Count) { StartGhost(ghosts[counter++], pacman.RealtimeCoordinate); } } switch (keyInfo2.Key) { case ConsoleKey.DownArrow: do { keyTemp = keyInfo2; Thread.Sleep(250); GameStatus(counter); for (int i = 0; i < counter; i++) { ghosts[i].DetermRoute(pacman.RealtimeCoordinate); if (!ghosts[i].Go()) { ghosts[i].BreakDeadLock(pacman.RealtimeCoordinate); } } Console.Clear(); gameField.Print(score, lives); if (Console.KeyAvailable) { keyInfo2 = Console.ReadKey(true); break; } } while (pacman.GoDown()); break; case ConsoleKey.LeftArrow: do { keyTemp = keyInfo2; Thread.Sleep(250); GameStatus(counter); for (int i = 0; i < counter; i++) { ghosts[i].DetermRoute(pacman.RealtimeCoordinate); if (!ghosts[i].Go()) { ghosts[i].BreakDeadLock(pacman.RealtimeCoordinate); } } Console.Clear(); gameField.Print(score, lives); if (Console.KeyAvailable) { keyInfo2 = Console.ReadKey(true); break; } } while (pacman.GoLeft()); break; case ConsoleKey.RightArrow: do { keyTemp = keyInfo2; Thread.Sleep(250); GameStatus(counter); for (int i = 0; i < counter; i++) { ghosts[i].DetermRoute(pacman.RealtimeCoordinate); if (!ghosts[i].Go()) { ghosts[i].BreakDeadLock(pacman.RealtimeCoordinate); } } Console.Clear(); gameField.Print(score, lives); if (Console.KeyAvailable) { keyInfo2 = Console.ReadKey(true); break; } } while (pacman.GoRight()); break; case ConsoleKey.UpArrow: do { keyTemp = keyInfo2; Thread.Sleep(250); GameStatus(counter); for (int i = 0; i < counter; i++) { ghosts[i].DetermRoute(pacman.RealtimeCoordinate); if (!ghosts[i].Go()) { ghosts[i].BreakDeadLock(pacman.RealtimeCoordinate); } } Console.Clear(); gameField.Print(score, lives); if (Console.KeyAvailable) { keyInfo2 = Console.ReadKey(true); break; } } while (pacman.GoUp()); break; case ConsoleKey.F5: try { FileStream fs = new FileStream("Saved_game.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); fs.Close(); using (StreamWriter sw = new StreamWriter("Saved_game.txt", false)) { sw.WriteLine("SCORE: {0}, LIVES {1}", score, lives); for (int i = 0; i < gameField.NewField.GetLength(0); i++) { for (int j = 0; j < gameField.NewField.GetLength(1); j++) { sw.Write(gameField.NewField[i, j]); sw.Write(" "); } sw.WriteLine(""); } } } catch (Exception e) { Console.WriteLine(e.Message); } keyInfo2 = keyTemp; break; default: keyInfo2 = keyTemp; break; } } while (keyInfo2.Key != ConsoleKey.Escape); }