private static void Main() { var behaviour = new Behavior() .Say("Привет мир!") .UntilKeyPressed(b => b .Say("Ля-ля-ля!") .Say("Тру-лю-лю")) .Jump(JumpHeight.High) .UntilKeyPressed(b => b .Say("Aa-a-a-a-aaaaaa!!!") .Say("[набирает воздух в легкие]")) .Say("Ой!") .Delay(TimeSpan.FromSeconds(1)) .Say("Кто здесь?!") .Delay(TimeSpan.FromMilliseconds(2000)); behaviour.Execute(); behaviour.Execute(); // повторное выполнение сценария }
public Behavior UntilKeyPressed(Action<Behavior> toDo) { var copy = new Behavior(); toDo(copy); Tasks.Add(() => { while (!Console.KeyAvailable) { copy.Execute(); Thread.Sleep(500); } Console.ReadKey(false); }); return this; }
public Behavior UntilKeyPressed(Func<Behavior, Behavior> configurate) { act.Add(() => { var beh = new Behavior(); beh = configurate(beh); while (true) { if (Console.KeyAvailable) { Console.ReadKey(intercept:false); break; } beh.Execute(); } }); return this; }
public void Execute() { var behavior = new Behavior(); SomeAction(behavior); while (!Console.KeyAvailable) { behavior.Execute(); } while (Console.KeyAvailable) Console.ReadKey(true); }
private static void Main() { var behaviour = new Behavior() .Say("Привет мир!") .UntilKeyPressed(b => b .Say("Ля-ля-ля!") .Delay(TimeSpan.FromMilliseconds(200)) .Say("Тру-лю-лю") .Delay(TimeSpan.FromMilliseconds(200))) .Jump(JumpHeight.Low) .UntilKeyPressed(b => b .Say("Aa-a-a-a-aaaaaa!!!") .Delay(TimeSpan.FromMilliseconds(200)) .Say("[набирает воздух в легкие]")) .Delay(TimeSpan.FromMilliseconds(200)) .Say("Ой!") .Delay(TimeSpan.FromSeconds(1)) .SayInColor("Кто здесь?!", ConsoleColor.Cyan) .Delay(TimeSpan.FromMilliseconds(2000)); behaviour.Execute(); }