示例#1
0
        static void Main(string[] args)
        {
            Division fc = new Division("Joy Division");

            fc.AddFightComponent(new HornetFabric().CreatePlain("Plain 1"));
            fc.AddFightComponent(new HornetFabric().CreatePlain("Plain 2"));
            fc.AddFightComponent(new EagleFabric().CreatePlain("Plain 3"));

            Hangar.GetInstance().AddDivision(fc);
            Plane plane = new EagleFabric().CreatePlain("Plain 1");

            fc.AddFightComponent(plane);
            Hangar.GetInstance().AddDivision(fc);
            Hangar.GetInstance().RemovePlane(fc, plane);
            Hangar.GetInstance().SendToWar(fc);

            FightComponentMemento fcm = Hangar.GetInstance().SaveFightComponent(plane);

            Hangar.GetInstance().SendToWar(plane);
            Console.WriteLine(plane.GetStateStatus());
            plane = (Plane)Hangar.GetInstance().RestoreFightComponent(fcm);
            Console.WriteLine(plane.GetStateStatus());


            String s = "Mykulyak chmo";

            SerDes.serialize(s);
            s = (String)SerDes.deserialize();
            Console.WriteLine(s);


            Plane plane1 = new HornetFabric().CreatePlain("M");
            Plane plane2 = new EagleFabric().CreatePlain("B");

            Attacker attacker = new Attacker(new MisslesStrategy(plane1));

            attacker.Attac();
            attacker = new Attacker(new BombsStrategy(plane2));
            attacker.Attac();

            RadioStation radioStation = new RadioStation(new List <float> {
                (float)120.3, (float)100.9, (float)100.4
            });
            Iterator iterator = radioStation.CreateIterator();
            float    item     = iterator.First();

            while (!iterator.IsDone())
            {
                Console.WriteLine(item);
                item = iterator.Next();
            }
        }
示例#2
0
文件: Iterator.cs 项目: chuprov/NET
        public void Main()
        {
            Aggregate a = new ConcreteAggregate();

            Iterator i = a.CreateIterator();

            object item = i.First();

            while (!i.IsDone())
            {
                item = i.Next();
            }
        }
示例#3
0
        /// <summary>
        /// Iterator pattern
        /// </summary>
        private static void IteratorRun()
        {
            Aggregate aggregate = new ConcreteAggregate();

            aggregate[0] = "1";
            aggregate[1] = "2";
            aggregate[2] = "3";

            Console.ForegroundColor = ConsoleColor.Cyan;
            Iterator iterator = aggregate.CreateIterator();
            object   item     = iterator.First();

            Console.WriteLine(item.ToString());
            while (!iterator.IsDone())
            {
                Console.WriteLine(iterator.Next().ToString());
            }
        }
        static void Main()
        {
            Collection collection = new Collection();

            collection[0] = new Item("Item 0");
            collection[1] = new Item("Item 1");
            collection[2] = new Item("Item 2");
            collection[3] = new Item("Item 3");
            collection[4] = new Item("Item 4");
            collection[5] = new Item("Item 5");
            collection[6] = new Item("Item 6");
            collection[7] = new Item("Item 7");
            collection[8] = new Item("Item 8");

            Iterator iterator = collection.CreateIterator();

            iterator.Step = 2;
            Console.WriteLine("Iterating over collection:");
            for (Item item = iterator.First(); !iterator.IsDone; item = iterator.Next())
            {
                Console.WriteLine(item.Name);
            }
        }