예제 #1
0
        public void ALLHostilesAttack_ShipUndocked_WithShields()
        {
            //todo:  verify that Regions are set up correctly.
            //todo: This test does not run alone.  what do the other tests set up that this needs?  why don't thea other tests tear down their stuff?

            //todo: will we need to mock out the Console.write process just so that we can test the output?  I'm thinking so..
            _setup.SetupMapWith2Hostiles();

            Assert.AreEqual(_setup.TestMap.Playership.Energy, (new StarTrekKGSettings()).GetSetting <int>("energy"), "Ship energy not at expected amount");

            //raise shields
            Shields.For(_setup.TestMap.Playership).SetEnergy(2500);                                                 //hopefully a single hit wont be harder than this!
            Assert.AreEqual(2500, Shields.For(_setup.TestMap.Playership).Energy, "Unexpected shield energy level"); //shields charged correctly // todo: do more tests on this in ShieldTests

            //Assert.AreEqual((new StarTrekKGSettings()).GetSetting<int>("energy"), _testMap.Playership.Energy, "Ship energy not at maximum"); //ship has no damage

            Assert.AreEqual(_setup.TestMap.Playership.Energy, (new StarTrekKGSettings()).GetSetting <int>("energy"), "Ship energy not at expected amount");

            (new Game((new StarTrekKGSettings()))).ALLHostilesAttack(_setup.TestMap);

            Assert.IsFalse(_setup.TestMap.Playership.Destroyed);
            Assert.Less(Shields.For(_setup.TestMap.Playership).Energy, 2500);
            Assert.AreEqual((new StarTrekKGSettings()).GetSetting <int>("energy"), _setup.TestMap.Playership.Energy, "expected no change to ship energy. Ship should have been protected by shields.");

            //Assert that ship has taken 2 hits.
            //todo: use a mock to determine that Ship.AbsorbHitFrom() was called twice.
        }
예제 #2
0
        private void ShieldMenu(IShip playerShip)
        {
            if (Shields.For(playerShip).Damaged())
            {
                return;
            }

            Shields.SHIELD_PANEL = new List <string>();
            Shields.SHIELD_PANEL.Add(Environment.NewLine);

            var currentShieldEnergy = Shields.For(playerShip).Energy;

            if (currentShieldEnergy > 0)
            {
                Shields.SHIELD_PANEL.Add("─── Shield Control: ── <CURRENTLY AT: " + currentShieldEnergy + "> ──");
                Shields.SHIELD_PANEL.Add("add = Add energy to shields.");
                Shields.SHIELD_PANEL.Add("sub = Subtract energy from shields.");
            }
            else
            {
                Shields.SHIELD_PANEL.Add("─── Shield Control: ── <DOWN> ──");
                Shields.SHIELD_PANEL.Add("add = Add energy to shields.");
            }

            this.Strings(Shields.SHIELD_PANEL);

            this.WithNoEndCR("Enter shield control command: ");
            var shieldsCommand = Console.ReadLine().Trim().ToLower();

            Shields.For(playerShip).MaxTransfer = playerShip.Energy; //todo: this does nothing!
            Shields.For(playerShip).Controls(shieldsCommand);
        }
예제 #3
0
        ///interesting..  one could take a hit from another map.. Wait for the multidimensional version of this game.  (now in 3D!) :D
        /// returns true if ship was destroyed. (hence, ship could not absorb all energy)
        public void AbsorbHitFrom(IShip attacker, int attackingEnergy)
        {
            var shields = Shields.For(this);

            if (attackingEnergy > 0)
            {
                string hitMessage = Write.ShipHitMessage(attacker);
                this.Map.Write.Line(hitMessage);

                shields.Energy -= attackingEnergy;
            }
            else
            {
                string message = Write.MisfireMessage(attacker);
                this.Map.Write.Line(message);
            }

            bool shieldsWorking = (this.GetRegion().Type != RegionType.Nebulae);

            if (!shieldsWorking)
            {
                this.Map.Write.Line("Shields ineffective due to interference from Nebula");
            }

            if ((shields.Energy < 0) || !shieldsWorking)
            {
                this.TakeDamageOrDestroyShip(attackingEnergy, shields);
            }
            else
            {
                this.Map.Write.Line("No Damage.");
            }
        }
예제 #4
0
        public static bool Auto_Raise_Shields(IMap map, IRegion Region)
        {
            bool shieldsRaised = false;

            if (Region.Type != RegionType.Nebulae)
            {
                var thisShip        = map.Playership;
                var thisShipEnergy  = thisShip.Energy;
                var thisShipShields = Shields.For(thisShip);

                if (thisShipShields.Energy == 0)      //todo: resource this out
                {
                    if (thisShipEnergy > 500)         //todo: resource this out
                    {
                        thisShipShields.Energy = 500; //todo: resource this out
                        thisShip.Energy       -= 500;

                        shieldsRaised = true;
                    }
                    else if (thisShipEnergy > 1)
                    {
                        var energyLeft = thisShipEnergy / 2; //todo: resource this out

                        thisShipShields.Energy = Convert.ToInt32(energyLeft);
                        thisShip.Energy        = energyLeft;
                        shieldsRaised          = true;
                    }
                }
            }

            return(shieldsRaised);
        }
예제 #5
0
        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);
        }
예제 #6
0
        public void ALLHostilesAttack_ShipUndocked_WithNoShields()
        {
            //todo:  verify that Regions are set up correctly.
            //todo: This test does not run alone.  what do the other tests set up that this needs?  why don't thea other tests tear down their stuff?

            //todo: will we need to mock out the Console.write process just so that we can test the output?  I'm thinking so..
            _setup.SetupMapWith1Hostile();

            Assert.AreEqual(_setup.TestMap.Playership.Energy, (new StarTrekKGSettings()).GetSetting <int>("energy"), "Ship energy not at expected amount");

            Shields.For(_setup.TestMap.Playership).SetEnergy(0);

            Assert.AreEqual(_setup.TestMap.Playership.Energy, (new StarTrekKGSettings()).GetSetting <int>("energy"), "Ship energy not at expected amount");

            const int expectedHitsTilldestruction = 4;

            for (int i = 0; i < 100; i++)
            {
                var testGame = (new Game((new StarTrekKGSettings())));

                TakeShots(testGame, expectedHitsTilldestruction);
            }

            //todo: use a mock to determine that Ship.AbsorbHitFrom() was called twice.
        }
예제 #7
0
        public void Test_AbsorbHit_NoDamage()
        {
            _mockSettings.Setup(u => u.GetSetting <string>("Hostile")).Returns("blah Blah Blah!!!");

            var shipToTest = new Ship(FactionName.Klingon, "TestShip", _mockSector.Object, _mockMap.Object, _mockMap.Object.Game);

            Shields.For(shipToTest).Energy = 100;  //this is syntactic sugar for: ship.Subsystems.Single(s => s.Type == SubsystemType.Shields);

            Assert.AreEqual(100, Shields.For(shipToTest).Energy);

            _mockWrite.Setup(w => w.Line(It.IsAny <string>()));

            _mockMap.Object.Write = _mockWrite.Object;
            _mockSector.Setup(s => s.X).Returns(-2);
            _mockSector.Setup(s => s.Y).Returns(-3);

            var attacker = new Ship(FactionName.Klingon, "The attacking Ship", _mockSector.Object, _mockMap.Object, _mockMap.Object.Game);

            shipToTest.AbsorbHitFrom(attacker, 50);

            Assert.AreEqual(50, Shields.For(shipToTest).Energy);

            //Verifications of Output to User
            _mockSector.Verify(s => s.X, Times.Exactly(1));
            _mockSector.Verify(s => s.Y, Times.Exactly(1));

            _mockWrite.Verify(w => w.Line(It.IsAny <string>()), Times.Exactly(2));
            _mockWrite.Verify(w => w.Line("Your Ship has been hit by The attacking Ship at sector [-2,-3]."), Times.AtLeastOnce());
            _mockWrite.Verify(w => w.Line("No Damage."), Times.Once());
        }
예제 #8
0
        public void SetupPlayershipShields()
        {
            var starshipShields = Shields.For(this.Playership);

            //starshipShields.ShipConnectedTo = this.Playership;
            starshipShields.Energy = 0;
            //starshipShields.Damage = 0;
        }
예제 #9
0
        private void AddHostileFederale(IRegion Region, ISector sector, Stack <string> federaleNames)
        {
            var newPissedOffFederale = new Ship(FactionName.Federation, federaleNames.Pop(), sector, this, this.Game);

            Shields.For(newPissedOffFederale).Energy = Utility.Utility.Random.Next(100, 500); //todo: resource those numbers out

            Region.AddShip(newPissedOffFederale, sector);

            this.Write.Line("Comm Reports a Federation starship has warped into Region: " + Region.Name);
        }
예제 #10
0
        public void OutputScanWarnings(IRegion Region, IMap map, bool shieldsAutoRaised)
        {
            if (Region.GetHostiles().Count > 0)
            {
                this.SRSScanHostile(Region);
            }

            this.Write.OutputConditionAndWarnings(map.Playership, this.Config.GetSetting <int>("ShieldsDownLevel"));

            if (shieldsAutoRaised)
            {
                map.Write.Line("Shields automatically raised to " + Shields.For(map.Playership).Energy);
            }
        }
예제 #11
0
        public void ALLHostilesAttack_ShipDocked()
        {
            _setup.SetupMapWith2Hostiles();

            //cheating so we can cover this line
            Navigation.For(_setup.TestMap.Playership).Docked = true;

            this.Game.ALLHostilesAttack(_setup.TestMap);

            //Ship has taken no damage.
            Assert.IsFalse(_setup.TestMap.Playership.Destroyed);
            Assert.AreEqual(Shields.For(_setup.TestMap.Playership).Energy, 0); //never even needed to raise shields!
            Assert.AreEqual(_setup.TestMap.Playership.Energy, (new StarTrekKGSettings()).GetSetting <int>("energy"));
        }
예제 #12
0
        //todo: move this to a report object?
        public void ReportShieldsStatus(IMap map, int shieldsValueBeforeHit)
        {
            var shieldsValueAfterHit = Shields.For(map.Playership).Energy;

            if (shieldsValueAfterHit <= shieldsValueBeforeHit)
            {
                if (shieldsValueAfterHit == 0)
                {
                    this.Write.SingleLine("** Shields are Down **");
                }
                else
                {
                    this.Write.SingleLine(String.Format("Shields dropped to {0}.", Shields.For(map.Playership).Energy));
                }
            }
        }
예제 #13
0
        public void VerifyFiringShipIntegrity(IShip firingShip, double startingEnergy, int testBoltEnergy, int expectedFiringShipAfterEnergy)
        {
            //Verifies energy subtracted from firing ship.  (greater, because of auto-salvage operation)
            //Assert.GreaterOrEqual(startingEnergy - testBoltEnergy, firingShip.Energy);

            //todo: calculate distance and damage that will be dealt

            //int seedEnergyToPowerWeapon = this.Config.GetSetting<int>("DisruptorShotSeed") * (Game.RandomFactorForTesting).Next();

            //var attackingEnergy = (int)StarTrek_KG.Utility.Utility.ShootBeamWeapon(seedEnergyToPowerWeapon, distance, "DisruptorShotDeprecationLevel", "DisruptorEnergyAdjustment", inNebula);

            var firingShipEnergy = firingShip.Energy;

            Assert.AreEqual(firingShipEnergy, expectedFiringShipAfterEnergy, " Firing Ship: " + firingShip.Name + " expected energy: " + expectedFiringShipAfterEnergy + ". but was " + firingShipEnergy);

            //todo: verify that firing ship was not hit.
            Assert.Greater(Shields.For(firingShip).Energy, -1);
        }
예제 #14
0
        public void OutputConditionAndWarnings(Ship ship, int shieldsDownLevel)
        {
            var condition = ship.GetConditionAndSetIcon();

            if (ship.AtLowEnergyLevel())
            {
                this.ResourceLine("LowEnergyLevel");
            }

            if (ship.GetRegion().Type == RegionType.Nebulae)
            {
                this.SingleLine("");
                this.ResourceLine("NebulaWarning");
            }

            if (Shields.For(ship).Energy == shieldsDownLevel && !Navigation.For(ship).Docked)
            {
                this.ResourceLine("ShieldsDown");
            }
        }
예제 #15
0
        private string GetSRSRowIndicator(int row, IMap map, Location location)
        {
            string retVal = " ";

            switch (row)
            {
            case 0:
                retVal += String.Format(this.Config.GetText("SRSRegionIndicator"), Convert.ToString(location.Region.X), Convert.ToString(location.Region.Y));
                break;

            case 1:
                retVal += String.Format(this.Config.GetText("SRSSectorIndicator"), Convert.ToString(location.Sector.X), Convert.ToString(location.Sector.Y));
                break;

            case 2:
                retVal += String.Format(this.Config.GetText("SRSStardateIndicator"), map.Stardate);
                break;

            case 3:
                retVal += String.Format(this.Config.GetText("SRSTimeRemainingIndicator"), map.timeRemaining);
                break;

            case 4:
                retVal += String.Format(this.Config.GetText("SRSConditionIndicator"), map.Playership.GetConditionAndSetIcon());
                break;

            case 5:
                retVal += String.Format(this.Config.GetText("SRSEnergyIndicator"), map.Playership.Energy);
                break;

            case 6:
                retVal += String.Format(this.Config.GetText("SRSShieldsIndicator"), Shields.For(map.Playership).Energy);
                break;

            case 7:
                retVal += String.Format(this.Config.GetText("SRSTorpedoesIndicator"), Torpedoes.For(map.Playership).Count);
                break;
            }

            return(retVal);
        }
예제 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="position"></param>
        /// <param name="listOfBaddies"></param>
        /// <param name="stockBaddieFaction"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public Ship CreateHostileShip(ISector position, Stack <string> listOfBaddies, FactionName stockBaddieFaction, Game game)
        {
            //todo: modify this to populate more than a single baddie faction

            //todo: this should be a random baddie, from the list of baddies in app.config
            var hostileShip = new Ship(stockBaddieFaction, listOfBaddies.Pop(), position, this.Map, game)
            {
                //yes.  This code can be misused.  There will be repeats of ship names if the stack isn't managed properly
                Sector = { X = position.X, Y = position.Y }
            };

            var hostileShipShields = Shields.For(hostileShip);
            //var testinghostileShipShields = hostileShipShields.Game.RandomFactorForTesting;
            int hostileShipShieldsRandom = Utility.Utility.TestableRandom(hostileShipShields.Game); //testinghostileShipShields == 0 ? Utility.Utility.Random.Next(200) : testinghostileShipShields;

            hostileShipShields.Energy = 300 + hostileShipShieldsRandom;

            this.Map.Write.DebugLine("Created Ship: " + hostileShip.Name);

            return(hostileShip);
        }
예제 #17
0
        private void AttackNonDockedPlayership(IMap map, IShip badGuy, int randomFactor)
        {
            var playerShipLocation = map.Playership.GetLocation();
            var distance           = Utility.Utility.Distance(playerShipLocation.Sector.X,
                                                              playerShipLocation.Sector.Y,
                                                              badGuy.Sector.X,
                                                              badGuy.Sector.Y);

            int seedEnergyToPowerWeapon = this.Config.GetSetting <int>("DisruptorShotSeed") * randomFactor;

            var inNebula = badGuy.GetRegion().Type == RegionType.Nebulae;

            //Todo: this should be Disruptors.For(this.ShipConnectedTo).Shoot()
            //todo: the -1 should be the ship energy you want to allocate
            var attackingEnergy = (int)Utility.Utility.ShootBeamWeapon(seedEnergyToPowerWeapon, distance, "DisruptorShotDeprecationLevel", "DisruptorEnergyAdjustment", inNebula);

            var shieldsValueBeforeHit = Shields.For(map.Playership).Energy;

            map.Playership.AbsorbHitFrom(badGuy, attackingEnergy);

            this.ReportShieldsStatus(map, shieldsValueBeforeHit);
        }
예제 #18
0
        public void RenderSectors(SectorScanType scanType, ISubsystem subsystem)
        {
            var    location          = subsystem.ShipConnectedTo.GetLocation();
            Region Region            = Regions.Get(subsystem.Game.Map, location.Region);
            var    shieldsAutoRaised = Shields.For(subsystem.ShipConnectedTo).AutoRaiseShieldsIfNeeded(Region);
            var    printSector       = (new Render(this, subsystem.Game.Config));

            int    totalHostiles           = subsystem.Game.Map.Regions.GetHostileCount();
            var    isNebula                = (Region.Type == RegionType.Nebulae);
            string RegionDisplayName       = Region.Name;
            var    sectorScanStringBuilder = new StringBuilder();

            if (isNebula)
            {
                RegionDisplayName += " Nebula"; //todo: resource out.
            }

            this.Line("");

            switch (scanType)
            {
            case SectorScanType.CombinedRange:
                printSector.CreateCRSViewScreen(Region, subsystem.Game.Map, location, totalHostiles, RegionDisplayName, isNebula, sectorScanStringBuilder);
                break;

            case SectorScanType.ShortRange:
                printSector.CreateSRSViewScreen(Region, subsystem.Game.Map, location, totalHostiles, RegionDisplayName, isNebula, sectorScanStringBuilder);
                break;

            default:
                throw new NotImplementedException();
            }

            printSector.OutputScanWarnings(Region, subsystem.Game.Map, shieldsAutoRaised);

            Region.ClearSectorsWithItem(SectorItem.Debug); //Clears any debug Markers that might have been set
            Region.Scanned = true;
        }
예제 #19
0
        public void CreateCRSViewScreen(IRegion Region, IMap map, Location shipLocation, int totalHostiles, string RegionDisplayName, bool isNebula, StringBuilder sectorScanStringBuilder)
        {
            List <string> lrsResults = LongRangeScan.For(map.Playership).RunLRSScan(shipLocation);

            var topBorder = this.Config.GetText("CRSTopBorder");

            this.CRS_Region_ScanLine(RegionDisplayName, topBorder, shipLocation);
            this.ScanLine(topBorder, String.Format(" Energy: {0}   Shields: {1}", map.Playership.Energy, Shields.For(map.Playership).Energy));

            int crsRows = Convert.ToInt32(this.Config.GetText("CRSRows"));

            for (int i = 0; i < crsRows; i++)
            {
                var rowIndicator = this.GetCRSRightTextLine(i, map, lrsResults, totalHostiles);
                this.ShowSectorRow(sectorScanStringBuilder, i, rowIndicator, Region.Sectors, totalHostiles, isNebula);
            }

            string lrsBottom = null;

            if (lrsResults.Count() == 7)
            {
                lrsBottom = " " + lrsResults[6];
            }

            this.ScanLine(this.Config.GetText("CRSBottomBorder"), lrsBottom + this.Config.GetText("AppVersion"));
        }
예제 #20
0
        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);
        }