/* * Set the docked status of the ship */ public void SetDocked(bool docked) { if (!this.docked && docked) { this.energyLevel = 100; ComsChatter("Commander Scot reports reports, 'Docking is complete, Captain.'"); } if (this.docked && !docked) { ComsChatter("Lt Sulu reports, 'We're clear for maneuvering, Captain.'"); } DamageControl.Docked(docked); Impulse.Docked(docked); LRS.Docked(docked); Phasers.Docked(docked); Probes.Docked(docked); Shields.Docked(docked); SRS.Docked(docked); Torpedoes.Docked(docked); Warp.Docked(docked); this.docked = docked; }
public void PhasersWontFireWhenToldTooMuchEnergy() { _setup.SetupMapWith1FriendlyAtSector(new Coordinate(2, 1)); var ship = _setup.TestMap.Playership; var startingEnergy = (new StarTrekKGSettings()).GetSetting <int>("energy"); Assert.AreEqual(startingEnergy, ship.Energy); const int testBoltEnergy = 4000; var beforeEnergy = ship.Energy; //This action will hit every single hostile in the Region. In this case, it will hit no one :D Phasers.For(_setup.TestMap.Playership).Fire(testBoltEnergy); Assert.AreEqual(ship.Energy, beforeEnergy); //verify that no energy xfer happened. Assert.Greater(Shields.For(ship).Energy, -1); //Todo: Mock up Output so we can see the text result //Without a mock for Output, we can't see the output, but the conclusion we can draw here is that the phasers didn't fire, and no energy was expended Assert.AreEqual(startingEnergy, _setup.TestMap.Playership.Energy); }
public void HitThatWounds() { //_testMap.Regions.GetHostile(0).Shields = 20 //todo: ensure that baddie has less than 50 (from config?) Phasers.For(_setup.TestMap.Playership).Fire(50); }
/* * 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; } }
public void PhaserFireSubtractsEnergyFromShip() { _setup.SetupMapWith1FriendlyAtSector(new Coordinate(2, 1)); var startingEnergy = (new StarTrekKGSettings()).GetSetting <double>("energy");; Assert.AreEqual(startingEnergy, _setup.TestMap.Playership.Energy); const int testBoltEnergy = 89; //This action will hit every single hostile in the Region. In this case, it will hit no one :D Phasers.For(_setup.TestMap.Playership).Fire(testBoltEnergy); this.VerifyFiringShipIntegrity(_setup.TestMap.Playership, startingEnergy, testBoltEnergy, 1911); //Verifies energy subtracted from firing ship. Assert.AreEqual(startingEnergy - testBoltEnergy, _setup.TestMap.Playership.Energy); }
public void PhasersWontFireWhenToldNotEnoughEnergy() { _setup.SetupMapWith1FriendlyAtSector(new Coordinate(2, 1)); var startingEnergy = (new StarTrekKGSettings()).GetSetting <int>("energy");; Assert.AreEqual(startingEnergy, _setup.TestMap.Playership.Energy); const int testBoltEnergy = -1; //This action will hit every single hostile in the Region. In this case, it will hit no one :D Phasers.For(_setup.TestMap.Playership).Fire(testBoltEnergy); this.VerifyFiringShipIntegrity(_setup.TestMap.Playership, startingEnergy, testBoltEnergy, startingEnergy); //Todo: Mock up Output so we can see the text result //Without a mock for Output, we can't see the output, but the conclusion we can draw here is that the phasers didn't fire, and no energy was expended Assert.AreEqual(startingEnergy, _setup.TestMap.Playership.Energy); }
/* * 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(); }
public void FirePhasers1() { Phasers.FirePhasers1(Program.Main); }
/* * Button execution was broken out of the button handler so the * short cut keys can access it in a straight forward way */ private void ButtonCommand(string btn) { bool executed = false; // prevent button hot keys during timer execution if (timerStep == 0) { Debug(btn + " pressed"); switch (btn.ToUpper()) { case "IMPL": executed = Impulse.Execute(); break; case "WARP": executed = Warp.Execute(); if (executed) { SRS.Execute(); } break; case "SHLD": Shields.Execute(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; case "POWER": Shields.divertPower(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; case "TORP": executed = Torpedoes.Execute(); break; case "PHAS": executed = Phasers.Execute(); break; case "DMG": DamageControl.FixAllDamage(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; } if (executed) { // update status before animation starts SetCondition(); if (IsUsingAnimation()) { timerStep = 1; timer.Enabled = true; } else { Debug("No Animation Executing"); GameObjects.MoveWithNoAnimation(); GameObjects.TakingFire(); GameObjects.MoveWithNoAnimation(); } } } }
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"); }
//This needs to be a command method that the UI passes values into. //Readline is done in UI public void Prompt(Ship playerShip, string mapText, Game game) { this.Console.Write(mapText); var readLine = this.Console.ReadLine(); if (readLine == null) { return; } var command = readLine.Trim().ToLower(); switch (command) { case "wrp": case "imp": case "nto": Navigation.For(playerShip).Controls(command); break; case "irs": ImmediateRangeScan.For(playerShip).Controls(); break; case "srs": ShortRangeScan.For(playerShip).Controls(); break; case "lrs": LongRangeScan.For(playerShip).Controls(); break; case "crs": CombinedRangeScan.For(playerShip).Controls(); break; case "pha": Phasers.For(playerShip).Controls(playerShip); break; case "tor": Torpedoes.For(playerShip).Controls(); break; case "she": this.ShieldMenu(playerShip); break; case "com": this.ComputerMenu(playerShip); break; case "toq": Computer.For(playerShip).Controls(command); break; case "dmg": this.DamageControlMenu(playerShip); break; //Utility Commands case "dbg": this.DebugMenu(playerShip); break; case "ver": this.Console.WriteLine(this.Config.GetText("AppVersion").TrimStart(' ')); break; case "cls": this.Console.Clear(); break; default: //case "?": this.CreateCommandPanel(); this.Panel(this.GetPanelHead(playerShip.Name), ACTIVITY_PANEL); break; } }
public void HitThatDestroys_Nebula() { //TestClass_Base called before this, doing some initialization a second time _setup.SetupMapWith1HostileAtSector(new Coordinate(2, 1), new Coordinate(2, 6), true); Game.RandomFactorForTesting = 123; //todo: why active? are hostiles in the same sector? var activeRegion = _setup.TestMap.Regions.GetActive(); activeRegion.Type = RegionType.Nebulae; // for testing purposes. var beforeHostiles = activeRegion.GetHostiles(); var countOfHostiles = beforeHostiles.Count; Assert.AreEqual(1, countOfHostiles); //Verify ship's location Assert.AreEqual(2, beforeHostiles[0].Sector.X); Assert.AreEqual(6, beforeHostiles[0].Sector.Y); //verify position on map. Assert.AreEqual(SectorItem.HostileShip, activeRegion.Sectors[22].Item); //set badguy energy var badGuyShields = Shields.For(beforeHostiles[0]); badGuyShields.Energy = 50; //todo: verify firing ship's starting energy. var startingEnergy = (new StarTrekKGSettings()).GetSetting <int>("energy"); var playershipBefore = _setup.TestMap.Playership; Assert.AreEqual(startingEnergy, playershipBefore.Energy); const int testBoltEnergy = 444; //Random numbers that are used in this operation: var phasers = Phasers.For(playershipBefore); phasers.Game.RandomFactorForTesting = 3; playershipBefore.Game = phasers.Game; Torpedoes.For(playershipBefore).Game.RandomFactorForTesting = 2; badGuyShields.Game.RandomFactorForTesting = 200; //This action will hit every single hostile in the Region phasers.Fire(testBoltEnergy); //due to the distance between the 2 ships, this is how much power it takes to knock the hostile's shield level of 50 down to nothing. var playershipAfter = _setup.TestMap.Playership; this.VerifyFiringShipIntegrity(playershipAfter, startingEnergy, testBoltEnergy, 1489); var afterHostiles = activeRegion.GetHostiles(); var afterHostilesCount = afterHostiles.Count; //in space. no one can hear you scream. Assert.AreEqual(0, afterHostilesCount); Assert.AreEqual(null, activeRegion.Sectors[22].Object); Assert.AreEqual(SectorItem.Empty, activeRegion.Sectors[22].Item); }