static void Main(string[] args) { Context context = new Context(new StateA()); context.Request(); context.Request(); context.Request(); }
public int MoveDown(Context con) { if (con.Counter < Context.LIMIT) { con.State = new NormalState(); } con.Counter -= 5; return con.Counter; }
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))); } }
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))); } }
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; }
static void Main(string[] args) { Context context = new Context(new ConcreateStateA()); for (int i = 0; i < 10 ; i++) { context.Request(); } Console.ReadKey(); }
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(); }
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"); }
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; }
public abstract void Handle(Context context);
public override void Change(Context context) { context.State = new StateA(); Console.WriteLine("State chenged from C to A"); }
public override void Handle(Context context) { context.State = new ConcreateStateA(); Console.WriteLine("Change on A"); }
public static void Main (string[] args) { Context c = new Context (new StateB ()); for (int i = 0; i < 10; i++) { c.Show (); c.Request (); } }
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"); }
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"); }
public override void Change(Context context) { context.State = new StateC(); Console.WriteLine("State changet from B to C!"); }
public override void Change(Context context) { context.State = new StateB(); Console.WriteLine("Changed state from A to B!"); }
public int MoveUp(Context con) { con.Counter += 2; return con.Counter; }