public TestField(TestFieldModel model) { InitializeComponent(); _model = model; _model.ModelChanged += () => { try { Invoke(new Action(() => { if (!drawingBox.IsDisposed) { drawingBox.Refresh(); } })); } catch (ObjectDisposedException e) { Console.WriteLine(e); } }; var stephandler = new MonteCarloStepHandler(); _looper = new GameLooper(_model, stephandler, 50); _looper.Start(); drawingBox.Paint += OnPaintDrawingBox; drawingBox.Focus(); KeyDown += stephandler.OnKeyDown; KeyUp += stephandler.OnKeyUp; }
public GameLooper(TestFieldModel model, IGameLooperStepHandler stephandler, int loopInterval) { _model = model; _stepHandler = stephandler; LoopInterval = loopInterval; _gameTimer = new Timer(LoopInterval); _gameTimer.Elapsed += OnLoopFinished; }
static void Main() { AllocConsole(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var testFieldModel = new TestFieldModel() { Width = TestFieldWidth, Height = TestFieldHeight, GameObjects = new List <GameObject>() { new Beacon(40, 40, Brushes.Coral), new Beacon(40, TestFieldHeight - 40, Brushes.DarkMagenta), new Beacon(TestFieldWidth - 40, 40, Brushes.MediumVioletRed), new Beacon(TestFieldWidth - 40, TestFieldHeight - 40, Brushes.Green), new Robot(TestFieldWidth / 2, TestFieldHeight / 2) } }; var testField = new TestField(testFieldModel); Application.Run(testField); }