Example #1
0
        public void TestCloning()
        {
            // GameEngine uses a "cheat" and routes its clone method through a serialize/deserialize operation:
            GameState ge = new GameState()
            {
                Id       = 99,
                Exchange = 99,
                Volley   = 99,
                Turn     = 99
            };
            GameState newGE = GameStateStreamUtilities.CloneGameState(ge);

            newGE.Id     = 0;
            newGE.Volley = 0;

            Assert.AreNotEqual(newGE.Id, ge.Id);
            Assert.AreNotEqual(newGE.Volley, ge.Volley);
            Assert.AreEqual(newGE.Exchange, ge.Exchange);
            Assert.AreEqual(newGE.Turn, ge.Turn);

            BeamBatterySystem b1 = new BeamBatterySystem()
            {
                Arcs = "FP,F,FS", Rating = 2
            };
            ScreenSystem d1 = new ScreenSystem()
            {
                StatusString = "Operational"
            };
            HullSystem h1 = new HullSystem()
            {
                HullType = HullTypeProperty.Average
            };

            var b2 = b1.Clone() as ArcWeaponSystem;
            var d2 = d1.Clone() as DefenseSystem;
            var h2 = h1.Clone() as HullSystem;

            h1.HullType = HullTypeProperty.Strong;
            var h1a = h1.Clone() as HullSystem;

            h1a.HullType = HullTypeProperty.Super;
            var h2a = h2.Clone() as HullSystem;
            var a1  = new ArmorSystem()
            {
                TotalArmor = "4,5", RemainingArmor = "4,5"
            };
            DefenseSystem a2 = (DefenseSystem)a1.Clone();

            ((ArmorSystem)a2).TotalArmor     = "5,5";
            ((ArmorSystem)a2).RemainingArmor = "4,4";
            var a2a = a1.Clone() as DefenseSystem;

            b2.Arcs         = "AP, P, FP";
            d2.StatusString = "Damaged";

            Console.WriteLine($"B1 is a {b1.GetType().FullName} and its clone B2 is a {b2.GetType().FullName}");
            Assert.AreEqual(b1.GetType(), b2.GetType());
            Console.WriteLine($"D1 is a {d1.GetType().FullName} and its clone D2 is a {d2.GetType().FullName}");
            Console.WriteLine($"H1 is a {h1.GetType().FullName} and its clone H2 is a {h2.GetType().FullName}");
            Console.WriteLine($"A1 is a {a1.GetType().FullName} and its clone A2 is a {a2.GetType().FullName}");
            Console.WriteLine($"Changing H1's HullType and then making a clone H1a, which is also a {h1a.GetType().FullName}");
            Console.WriteLine($"Making a clone of H2 H2a, which is also a {h2a.GetType().FullName}");
            Console.WriteLine($"B1 arcs  : [{b1.Arcs}]");
            Console.WriteLine($"B2 arcs  : [{b2.Arcs}]");
            Console.WriteLine($"D1 status: [{d1.StatusString}]");
            Console.WriteLine($"D2 status: [{d2.StatusString}]");
            Console.WriteLine($"H1 type  : [{h1.HullType}]");
            Console.WriteLine($"H1a type : [{h1a.HullType}]");
            Console.WriteLine($"H2 type  : [{h2.HullType}]");
            Console.WriteLine($"H2a type : [{h2a.HullType}]");
            Console.WriteLine($"A1 totalArmor : [{a1.TotalArmor}]");
            Console.WriteLine($"A2 totalArmor : [{((ArmorSystem)a2).TotalArmor}] (Cloned as DefenseSystem, cast to ArmorSystem)");

            // Ensure cloning results in no type changes
            Assert.AreEqual(d1.GetType(), d2.GetType());
            Assert.AreEqual(h1.GetType(), h2.GetType());
            Assert.AreEqual(a1.GetType(), a2.GetType());

            // Ensure cloning results in separate references
            Assert.AreNotEqual(h1.HullType, h1a.HullType);
            Assert.AreNotEqual(h1.HullType, h2.HullType);
            Assert.AreNotEqual(b1.Arcs, b2.Arcs);
            Assert.AreNotEqual(a1.TotalArmor, ((ArmorSystem)a2).TotalArmor);

            // Ensure cloning results in identical values unless changed
            Assert.AreEqual(h2.HullType, h2a.HullType);
        }
 public DecisionIsDistanceLessThan(DefenseSystem ds, float r)
 {
     defenseSystem = ds;
     radius        = r;
 }
Example #3
0
 public DecisionIsAirplane(DefenseSystem ds)
 {
     defenseSystem = ds;
 }
Example #4
0
 public DecisionIsVehicle(DefenseSystem ds)
 {
     defenseSystem = ds;
 }
Example #5
0
 public ActionFireLaser(DefenseSystem ds)
 {
     defenseSystem = ds;
 }
 public DecisionIsEnemy(DefenseSystem ds)
 {
     defenseSystem = ds;
 }
 public ActionFireCannon(DefenseSystem ds)
 {
     defenseSystem = ds;
 }
Example #8
0
 public ActionFireMissile(DefenseSystem ds)
 {
     defenseSystem = ds;
 }