public ProgramDefinition() { //new Thread(ToWindow) { ApartmentState = ApartmentState.STA, IsBackground = true }.Start(); #region act upon events this.AtUserInput = (sender, c) => { // lets mutate our world if (c == 'w') { Console.ForegroundColor = ConsoleColor.White; } else if (c == 'y') { Console.ForegroundColor = ConsoleColor.Yellow; } Console.WriteLine("#" + this.Identity.Frame + " key: " + c); }; this.AtMove = (sender, x, y) => { Console.WriteLine("#" + this.Identity.Frame + " move x: " + x + ", y: " + y); }; this.AtMessage = (Sender, MessageIndex) => { if (MessageIndex == 1) { Console.WriteLine("hello world!"); return; } Console.WriteLine("how is network programming going?"); }; this.AtArguments = (Sender, Arguments) => Arguments.ApplyToWorld(Sender, this); #endregion #region translate user input to events this.ConsoleKeyPressed += c => { if (c.Key == ConsoleKey.LeftArrow) { this.AtMove(null, -1, 0); return; } if (c.Key == ConsoleKey.RightArrow) { this.AtMove(null, 1, 0); return; } if (c.Key == ConsoleKey.UpArrow) { this.AtMove(null, 0, -1); return; } if (c.Key == ConsoleKey.DownArrow) { this.AtMove(null, 0, 1); return; } if (c.Key == ConsoleKey.PageUp) { this.AtMessage(null, 1); return; } if (c.Key == ConsoleKey.PageDown) { this.AtMessage(null, 2); return; } if (c.Key == ConsoleKey.Home) { this.AtArguments(null, new AtArgumentsTuple { X = 45, Z = 678, Y = 45435, Next = null }); return; } if (c.Key == ConsoleKey.End) { this.AtArguments(null, new AtArgumentsTuple { X = 45, Z = 678, Y = 45435, Note = 666, Next = new AtArgumentsTuple { X = 3, Y = 4, Z = 5 } }); return; } // we are calling this delegate // to allow frame sync as the implementation // will not be called before it's time in the future this.AtUserInput(null, c.KeyChar); }; #endregion }