Example #1
0
        static void Main(string[] args)
        {
            Context context = new Context(new StateA());

            context.Request();
            context.Request();
            context.Request();
        }
Example #2
0
 public int MoveDown(Context con)
 {
     if (con.Counter < Context.LIMIT)
     {
         con.State = new NormalState();
     }
     con.Counter -= 5;
     return con.Counter;
 }
Example #3
0
 public int MoveDown(Context con)
 {
     if (con.Counter < Context.LIMIT)
     {
         con.State = new FastForwardState();
     }
     con.Counter -= 2;
     return con.Counter;
 }
 public static void Run()
 {
     Context context = new Context();
     Random rnd = new Random();
     for (int i = 0; i < Context.LIMIT; i++)
     {
         Console.Write(context.ResultState(rnd.Next(0, 3)));
     }
 }
Example #5
0
 public static void RunMain()
 {
     Context con = new Context();
     con.State = new NormalState();
     Random r = new Random();
     for (int i = 0; i < 25; i++)
     {
         Console.Write(con.Request(r.Next(3)));
     }
 }
Example #6
0
        static void Main(string[] args)
        {
            Context context = new Context(new ConcreteStateA());
            context.Request();
            context.Request();
            context.Request();
            context.Request();

            Console.ReadKey();
        }
 public int MoveDown(Context context)
 {
     if (context.counter < Context.LIMIT)
     {
         context.State = new FastForwardState();
         Console.Write("||");
     }
     context.counter -= 2;
     return context.counter;
 }
 public int MoveDown(Context context)
 {
     if (context.counter < Context.LIMIT)
     {
         context.State = new NormalState();
         Console.Write("||");
     }
     context.counter -= 5;
     return context.counter;
 }
Example #9
0
        static void Main(string[] args)
        {
            Context context = new Context(new ConcreateStateA());

            for (int i = 0; i < 10 ; i++)
            {
                context.Request();
            }

            Console.ReadKey();
        }
Example #10
0
        static void StatePattern()
        {
            Console.WriteLine("\n\nState Pattern");
            var context = new StatePattern.Context();

            context.SetState(new ConcreteStateA());
            context.GetCurrentState().Handle();

            context.SetState(new ConcreteStateB());
            context.GetCurrentState().Handle();
        }
 public static void RunMain()
 {
     Context context = new Context();
     context.State = new NormalState();
     Random r = new Random();
     for (int i = 0; i < 25; i++)
     {
         int command = r.Next(3);
         context.Request(command);
     }
 }
        static void Main(string[] args)
        {
            // Use Context to see changes in behaviour when changing state.
            Context context = new Context();

            ConcreteStateA stateA = new ConcreteStateA();
            stateA.handle(context);

            Console.WriteLine(context.getState().response());

            ConcreteStateB stateB = new ConcreteStateB();
            stateB.handle(context);

            Console.WriteLine(context.getState().response());

            Console.WriteLine("Press enter to close...");
            Console.ReadLine();
        }
Example #13
0
			void StateBase.Change(Context context)
			{
				context.State = new StateB (); // change to stateB if current state is A
				Console.WriteLine ("change state from A to B");
			}
Example #14
0
 public abstract void Change(Context context);
 public int MoveUp(Context context)
 {
     return context.counter  = context.counter + 5;
 }
 public void handle(Context context)
 {
     Console.WriteLine("State B");
     context.setState(this);
 }
 public int MoveUp(Context context)
 {
     context.Counter += 5;
     return context.Counter;
 }
Example #18
0
 public abstract void Handle(Context context);
Example #19
0
 public override void Change(Context context)
 {
     context.State = new StateA();
     Console.WriteLine("State chenged from C to A");
 }
Example #20
0
 public override void Handle(Context context)
 {
     context.State = new ConcreateStateA();
     Console.WriteLine("Change on A");
 }
Example #21
0
		public static void Main (string[] args)
		{
			Context c = new Context (new StateB ());
			for (int i = 0; i < 10; i++) {
				c.Show ();
				c.Request ();
			}
		}
Example #22
0
			void StateBase.Change(Context context)
			{ 
				context.State = new StateA (); //change to stateA if current state is C
				Console.WriteLine ("change state from C to A");
			}
Example #23
0
			void StateBase.Change(Context context)
			{
				context.State = new StateC (); //change to stateC if current state is B
				Console.WriteLine ("change state from B to C");
			}
Example #24
0
 public override void Change(Context context)
 {
     context.State = new StateC();
     Console.WriteLine("State changet from B to C!");
 }
Example #25
0
 public override void Change(Context context)
 {
     context.State = new StateB();
     Console.WriteLine("Changed state from A to B!");
 }
Example #26
0
 public int MoveUp(Context con)
 {
     con.Counter += 2;
     return con.Counter;
 }