static void Main(string[] args)
        {
            UnitFactory factory = new UnitFactory();

            var axeman1 = new Target();

            axeman1.ID       = Guid.NewGuid();
            axeman1.UnitData = factory.GetUnit("Axeman");

            var axeman2 = new Target();

            axeman2.ID       = Guid.NewGuid();
            axeman2.UnitData = factory.GetUnit("Axeman");
            Console.WriteLine("Number of axeman: {0}", Infantry.NumberOfInstances);

            var cavalry1 = new Target();

            cavalry1.ID       = Guid.NewGuid();
            cavalry1.UnitData = factory.GetUnit("Cavalry");

            cavalry1.UnitData.FireAt(axeman1);

            var cavalry2 = new Target();

            cavalry2.ID       = Guid.NewGuid();
            cavalry2.UnitData = factory.GetUnit("Chariot");
            var cavalry3 = new Target();

            cavalry3.ID       = Guid.NewGuid();
            cavalry3.UnitData = factory.GetUnit("Cavalry");
            Console.WriteLine("Number of cavalry: {0}", Stable.NumberOfInstances);

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            UnitFactory factory = new UnitFactory();

            Target tank1 = new Target();

            tank1.ID       = Guid.NewGuid();
            tank1.UnitData = factory.GetUnit("Tank");

            Target tank2 = new Target();

            tank2.ID       = Guid.NewGuid();
            tank2.UnitData = factory.GetUnit("Tank");

            bool result    = tank1.UnitData == tank2.UnitData;  // result = true
            int  firepower = tank1.UnitData.FirePower;

            Console.WriteLine("Tank Instances: " + Tank.NumberOfInstances);

            Target soldier1 = new Target();

            soldier1.ID       = Guid.NewGuid();
            soldier1.UnitData = factory.GetUnit("Marine");

            var soldier2 = new Target();

            soldier2.UnitData = factory.GetUnit("Infantry");
            soldier2.ID       = Guid.NewGuid();

            var soldier3 = new Target();

            soldier3.UnitData = factory.GetUnit("Infantry");
            soldier3.ID       = Guid.NewGuid();

            Console.WriteLine("Soldier Instances: " + Soldier.NumberOfInstances);
        }