/// <summary> /// Game Loop /// </summary> public Game() { Console.OutputEncoding = System.Text.Encoding.UTF8; Console.WriteLine("Hello, welcome to Pacman"); bool aPlayAgain = true; while (aPlayAgain) { itsMap = new LevelMap(); PromptChooseLevel(); // Initialize Pacman at position (1, 1) itsPacman = new Pacman(new Point(1, 1)); // Initialize a Ghost at position (1, 5) Ghost.Ghosts = new List <Ghost>() { new Ghost(new Point(1, 5)) }; // Draw the map itsMap.PrintMap(); // Draw Pacman onto the map itsPacman.Draw(); // Draw the ghost onto the map foreach (Ghost aGhost in Ghost.Ghosts) { aGhost.Draw(); } // Play the starting sound Sounds.Intro(); // Hide the cursor Console.CursorVisible = false; bool theGameOver = false; while (!theGameOver) { // Move Pacman itsPacman.PlayerInput(); // Move Ghosts and see if any touch Pacman for (int i = Ghost.Ghosts.Count - 1; i >= 0; i--) { Ghost.Ghosts[i].Move(); if (Ghost.Ghosts[i].Location == itsPacman.Location) { itsPacman.TryToEat(Ghost.Ghosts[i]); } } // If all of the dots are eaten, end the game if (Dot.NumDots <= 0) { Console.Clear(); theGameOver = true; } else if (!itsPacman.Alive) { Console.Clear(); theGameOver = true; } } Console.ForegroundColor = ConsoleColor.White; if (itsPacman.Alive) { Console.WriteLine("You Win.\n\n"); } else { Console.WriteLine("You Lose.\n\n"); } // Ask if playing again aPlayAgain = PromptPlayAgain(); } }
public LevelMap() { CurrentMap = this; }