static void Main(string[] args)
        {
            StageApp app = new StageApp();

            app.SharedSetting = 5;

            StageApp anotherApp = new StageApp();

            anotherApp.SharedSetting = 6;

            // actor is added to the stage automatically after instantiation
            Actor a1 = new Actor(app);
            Actor a2 = new Actor(app);
            Actor a3 = new Actor(anotherApp);

            Console.WriteLine("Actors in anotherApp before moving actor:");
            Console.WriteLine(anotherApp.TotalActorsCount);

            // or by calling method from StageApp class
            anotherApp.AddActor(a1);

            Console.WriteLine("Actors in anotherApp after calling method (should be 2):");
            Console.WriteLine(anotherApp.TotalActorsCount);

            // or by setting Stage through property
            a2.Stage = anotherApp;

            Console.WriteLine("Actors in anotherApp after setting property of Actor instance (should be 3):");
            Console.WriteLine(anotherApp.TotalActorsCount);

            Console.WriteLine("Actors count in app (should be empty):");
            Console.WriteLine(app.TotalActorsCount);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            StageApp app = new StageApp();

            app.CreateActor();
            app.SharedSetting = 5;
            foreach (var actor in app.Actors)
            {
                Console.WriteLine(actor.Execute());
            }
        }
 /// <summary>
 /// An actor that needs to refer to stage to know what behavior to execute
 /// </summary>
 /// <param name="stage"></param>
 public Actor(StageApp stage)
 {
     Stage      = stage;
     m_Property = new Random().Next();
 }