Пример #1
0
        /*
         * Check for end of game conditions
         * and make sure we only process one
         * end game condition
         *
         */
        private void endGameCheck()
        {
            Debug("Endgame check");
            int endGameAction = 0;

            if (GameBoard.getKlingonCount() < 1)
            {
                Debug("YOU WON!");
                endGameAction = (GameEnd.ForTheWin() ? 1 : 2);
            }
            else if (GameBoard.TimeLeft() <= 0.0)
            {
                Debug("Out of Time");
                endGameAction = (GameEnd.OutOfTime() ? 1 : 2);
            }
            else if (this.energyLevel < .1)
            {
                Debug("Out of Energy");
                endGameAction = (GameEnd.OutOfEnergy() ? 1 : 2);
            }
            else if (this.alertLevel == REDALERT &&
                     (!(Impulse.IsHealthy() || Warp.IsHealthy() || Phasers.IsHealthy() ||
                        (Torpedoes.IsHealthy() && Torpedoes.getCurrentCount() > 0))))
            {
                Debug("No longer able to fight");
                endGameAction = (GameEnd.Destroyed() ? 1 : 2);
            }

            // take end game action if > 0
            switch (endGameAction)
            {
            case 1:
                Debug("Starting new game");
                // TODO - add 16 grid support.  If I decide to add multiplayer
                // player support (not likely) then I'll also add 24 & 32 grid sizes
                NewGame(8);
                break;

            case 2:
                Debug("Normal exit to game");
                System.Windows.Forms.Application.ExitThread();
                this.Close();
                break;
            }
        }