Ejemplo n.º 1
0
        /*
         * Routine to set everything up for a new game
         */
        public void NewGame(int gridSize)
        {
            WriteToLog.write("---- Game Start ----");

            // initialize the other classes
            GameBoard.NewGame(gridSize);
            GameMap.NewGame();
            SRS.NewGame();
            LRS.NewGame();
            Warp.NewGame();
            Torpedoes.NewGame();
            Phasers.NewGame();
            Shields.NewGame();
            Impulse.NewGame();
            DamageControl.NewGame();
            StarBases.NewGame();
            Probes.NewGame();

            ComsClear();

            // Register starbases
            for (int i = 0; i < GameBoard.GetSize() * GameBoard.GetSize(); i++)
            {
                if (GameBoard.GetGameBoard(i) > 99)
                {
                    // Register this starbase
                    StarBases.AddStarbase(i);
                    WriteToLog.write("Added starbase to loc " + i.ToString());
                }
            }

            // locate the enterprise and play the game
            GameBoard.RandomEnterpriseLocation();
            WriteToLog.write("Enteprise is in sector " + GameBoard.GetLocation());

            SRS.Execute();
            SetCondition();
        }
Ejemplo n.º 2
0
        private void SetConditionExecute()
        {
            WriteToLog.write("SetCondition - starDate=" + GameBoard.CurrentStarDate() + "  energy=" + this.energyLevel);

            // set the alert level
            if (GameBoard.GetGameBoard() % 100 / 10 > 0)
            {
                this.alertLevel = REDALERT;
            }
            else
            {
                //energy <15% or or shields up is yellow alert
                if (this.energyLevel < 15 || Shields.AreUp())
                {
                    this.alertLevel = YELLOWALERT;
                }
                else
                {
                    this.alertLevel = GREENALERT;
                }
            }

            Debug("Alert Level = " + alertLevel);

            // update the form
            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                Debug("Updating Status");

                switch (this.alertLevel)
                {
                case REDALERT:
                    lblAlert.Content = "RED";
                    break;

                case YELLOWALERT:
                    this.lblAlert.Content = "YELLOW";
                    break;

                default:
                    this.lblAlert.Content = "GREEN";
                    break;
                }

                // update labels - the updatecontent method sends
                // the info to the log file when in debug mode
                UpdateContent(lblStarDate, String.Format("{0:0.0} ({1:0.0})", this.GameBoard.CurrentStarDate(), GameBoard.TimeLeft()));
                UpdateContent(lblEnergy, String.Format("{0:0.0}%", this.energyLevel));
                UpdateContent(lblKlingons, GameBoard.getKlingonCount().ToString());

                lblImpulse.Content = Impulse.HealthPercent() + "%";
                lblWarp.Content = Warp.HealthPercent() + "%";
                lblPhasers.Content = Phasers.HealthPercent() + "%";
                lblTorpedoes.Content = Torpedoes.HealthPercent() + "%";
                lblTorpedoCount.Content = "(" + Torpedoes.getCurrentCount() + " Remaining)";
                lblShields.Content = Shields.HealthPercent() + "%";
                lblLRS.Content = LRS.HealthPercent() + "%";
                lblShieldPowerRemaining.Content = Shields.levelPercent() + "%";

                string[] loc = GameBoard.GetLocationInfo();
                lblQuadrant.Content = loc[0];
                lblSector.Content = loc[1];
            }));


            // set button colors
            Debug("Set buttons");
            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                // update button background
                btnImpulse.Background = ((Impulse.IsHealthy() ? LTGREEN : REDISH));
                btnWarp.Background = ((Warp.IsHealthy() ? LTGREEN : REDISH));
                btnTorpedoes.Background = ((Torpedoes.IsHealthy() ? (Torpedoes.getCurrentCount() > 2 ? LTGREEN : LTYELLOW) : REDISH));
                btnPhasers.Background = ((Phasers.IsHealthy() ? LTGREEN : REDISH));
                btnLRS.Background = ((LRS.IsHealthy() ? GREENISH : REDISH));
                btnRepairs.Background = (DamageControl.HealthPercent() > 50 ? GREENISH : (DamageControl.IsHealthy() ? LTYELLOW : REDISH));
                btnDivert.Background = (Shields.levelPercent() > 80 ? GREENISH : (Shields.levelPercent() < 40 ? REDISH : LTYELLOW));

                btnDivert.IsEnabled = !IsDocked();
                btnShields.IsEnabled = !IsDocked();

                if (this.alertLevel == REDALERT)
                {
                    if (Shields.HealthPercent() > 60)
                    {
                        btnShields.Background = (Shields.AreUp() ? GREENISH : REDISH);
                    }
                    else
                    {
                        btnShields.Background = ((Shields.IsHealthy() && Shields.AreUp() ? LTYELLOW : REDISH));
                    }
                }
                else
                {
                    if (Shields.HealthPercent() > 30)
                    {
                        btnShields.Background = (Shields.AreUp() ? GREENISH : LTGREEN);
                    }
                    else
                    {
                        btnShields.Background = ((Shields.IsHealthy() ? (Shields.AreUp() ? LTGREEN : LTYELLOW) : REDISH));
                    }
                }
            }));


            // are we docked?
            Debug("Docked");
            SetDocked(SRS.AreWeDocked());

            // look for starbase updates
            Debug("Starbases");
            StarBases.Execute();

            // execute damage control and LRS updates
            Debug("DC");
            DamageControl.Execute();

            // update the Long range sensors
            Debug("LRS");
            LRS.Execute();

            Debug("Exiting setcondition");
        }