예제 #1
0
파일: Game.cs 프로젝트: xShadoWalkeR/PacMan
        /// <summary>
        /// Loops the game
        /// </summary>
        private void GameLoop()
        {
            while (pacMan.Health != 0)   // Runs the loop untill PacMan is out of lives

            {
                pacMan.Plot(); // "Plot" Draws PacMan into the game
                ghost1.Plot(); // "Plot" Draws the first Ghost into the game
                ghost2.Plot(); // "Plot" Draws the second Ghost into the game
                ghost3.Plot(); // "Plot" Draws the third Ghost into the game
                ghost4.Plot(); // "Plot" Draws the fourt Ghost into the game

                // Calls the Update method in Level
                level.Update(pacMan.Points, pacMan.Health, pacMan.NLevel);

                // Reads the input from the user to attribute a direction to PacMan
                ReadInput();

                Thread.Sleep(25); // Suspends the thread for 25 milliseconds

                pacMan.UnPlot();  // "UnPlot" Clear PacMan from the game
                ghost1.UnPlot();  // "UnPlot" Clear the first Ghost from the game
                ghost2.UnPlot();  // "UnPlot" Clear the second Ghost from the game
                ghost3.UnPlot();  // "UnPlot" Clear the third Ghost from the game
                ghost4.UnPlot();  // "UnPlot" Clear the fourth Ghost from the game

                pacMan.Update();  // Calls the Update method in PackMan
                ghost1.Update();  // Calls the Update method in Ghost
                ghost2.Update();  // Calls the Update method in Ghost
                ghost3.Update();  // Calls the Update method in Ghost
                ghost4.Update();  // Calls the Update method in Ghost


                if (pacMan.WinCondition())   // If PacMan wins...

                // ...reset Ghosts' position...
                {
                    ghost1.Reboot();
                    ghost2.Reboot();
                    ghost3.Reboot();
                    ghost4.Reboot();

                    // ...and reset PacMan position...
                    pacMan.Respawn();

                    // ...and reset eatable points
                    level.GetCollider();
                }
            }
            Console.Clear(); // Clears the console
        }
예제 #2
0
 /// <summary>
 /// Check for collisions againts PacMan
 /// </summary>
 private void CheckCollision()
 {
     if ((x >= pacman.X && x <= pacman.X + 4 && y == pacman.Y) ||
         (x + 4 >= pacman.X && x + 4 <= pacman.X + 4 && y == pacman.Y) ||
         (x == pacman.X && y <= pacman.Y && y >= pacman.Y + 2) ||
         (x == pacman.X && y + 2 >= pacman.Y && y <= pacman.Y + 2))
     {
         if (isVulnerable)
         {
             timer          = 0;
             isVulnerable   = false;
             pacman.Points += 1500;
             IsDead         = true;
             state          = GhostState.ReturnToSpawn;
         }
         else
         {
             pacman.IsDead = true;
             pacman.Respawn();
         }
     }
 }