Beispiel #1
0
        static void Main(string[] args)
        {
            const string Terrorist = "terrorist";
            const string Cop       = "cop";

            List <Soldier> terroristArmy = new List <Soldier>();
            List <Soldier> copArmy       = new List <Soldier>();

            var soldierFactory = new SoldierFactory();

            for (int i = 0; i < 5; i++)
            {
                terroristArmy.Add(soldierFactory.GetSoldier(Terrorist));
                copArmy.Add(soldierFactory.GetSoldier(Cop));
            }

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(terroristArmy[i].SoldierInfo(i));
                Console.WriteLine(copArmy[i].SoldierInfo(i));
            }

            Console.WriteLine(new string('/', 60));
            Console.WriteLine("Total objects created: {0}", soldierFactory.NumberOfObjects);
            Console.WriteLine(new string('/', 60));
        }
        static void Main(string[] args)
        {
            SoldierType[] soldiers = { SoldierType.Private, SoldierType.Private, SoldierType.Sergeant, SoldierType.Private, SoldierType.Sergeant };

            SoldierFactory factory = new SoldierFactory();

            int localtionX = 10;
            int locationY  = 10;

            foreach (SoldierType soldier in soldiers)
            {
                localtionX += 10;
                locationY  += 5;
                Soldier sld = factory.GetSoldier(soldier);
                sld.MoveTo(localtionX, locationY);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            SoldierFactory factory = new SoldierFactory();
            AK47           ak47    = new AK47();

            for (int i = 0; i < 100; i++)
            {
                Soldier soldier = null;
                if (i <= 20)
                {
                    soldier = factory.GetSoldier("士兵" + (i + 1), ak47, SoldierType.Normal);
                }
                else
                {
                    soldier = factory.GetSoldier("士兵" + (i + 1), ak47, SoldierType.Water);
                }
                soldier.Fight();
            }
            Console.Read();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("--------------------FlyweightPattern--------------------");
            Console.WriteLine();
            var factory = new SoldierFactory();
            var ak47    = new AK47();

            for (int i = 0; i < 10000; i++)
            {
                Soldier soldier = null;
                if (i < 5000)
                {
                    soldier = factory.GetSoldier($"士兵A", ak47, SoldierType.Normal);
                }
                else
                {
                    soldier = factory.GetSoldier($"士兵B", ak47, SoldierType.Water);
                }
                soldier.Fight();
            }
            Console.WriteLine("complete!");
            Console.ReadKey();
        }