コード例 #1
0
        /// <summary>
        /// Create a new instance of the game by initilizing all game components
        /// </summary>
        public void NewGame()
        {
            // Clear the list of all game components
            this.Components.Clear();

            // Stop all musics
            SoundManager.Instance.StopMusic();
            SoundManager.Instance.StopInvincible();

            // Create new instances of game components
            menu   = new Menu(this, pacDied ? MenuType.GAMEOVER : MenuType.START);
            maze   = new Maze(this);
            blinky = new Blinky(this);
            pinky  = new Pinky(this);
            inky   = new Inky(this);
            clyde  = new Clyde(this);

            pac = new Pac(this, maze);

            // If there was a previous level before this new game, do not reset pac's life
            if (lastPacLife > 0)
            {
                pac.Life = lastPacLife;
            }

            // (Re)-initialize GhostManager
            GhostManager.Instance.Initialize(maze, pac, blinky, new Ghost[] { pinky, inky, clyde });

            // Initialize all game components
            menu.Initialize();
            maze.Initialize();
            blinky.Initialize();
            pinky.Initialize();
            inky.Initialize();
            clyde.Initialize();
            pac.Initialize();

            // Reset pacDied attribute
            pacDied = false;
        }