// Движение автомобиля к базе private void MovePicture(object _) { var x = picture.Location.X; var y = picture.Location.Y; if (x < destination.X) { x++; } if (x > destination.X) { x--; } if (y < destination.Y) { y++; } if (y > destination.Y) { y--; } picture.BeginInvoke((Action)(() => picture.Location = new Point(x, y))); if (x == destination.X && y == destination.Y) { timer.Change(Timeout.Infinite, Timeout.Infinite); timer.Dispose(); timer = null; StartWorking(); } }
protected void drawTurn() { if (actualTurn == null) { return; } int width = PICTURE_BOX.Width; int height = PICTURE_BOX.Height; if (width == 0 || height == 0) { return; } Bitmap drawingBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(drawingBitmap)) { g.ScaleTransform(drawingBitmap.Width / 1000f, drawingBitmap.Height / 1000f); HISTORIC_EXPLODED_BULLETS[0] = actualTurn.BULLETS.Where(bullet => bullet.EXPLODED).ToArray(); HISTORIC_EXPLODED_MINES[0] = actualTurn.MINES.Where(mine => mine.EXPLODED).ToArray(); HISTORIC_REPAIRS[0] = actualTurn.REPAIRS; HISTORIC_SCANS[0] = actualTurn.SCANS; DRAWER.DrawTurn(actualTurn, g); drawHistory(HISTORIC_EXPLODED_BULLETS, BULLET_DELEGATE, g); drawHistory(HISTORIC_EXPLODED_MINES, MINE_DELEGATE, g); drawHistory(HISTORIC_REPAIRS, REPAIR_DELEGATE, g); drawHistory(HISTORIC_SCANS, SCAN_DELEGATE, g); } if (PICTURE_BOX.Visible) { try { PICTURE_BOX.BeginInvoke(new InvokeDelegate(() => { PICTURE_BOX.Image = drawingBitmap; })); } catch (InvalidOperationException) { // someone close window form } } moveHistory(HISTORIC_EXPLODED_BULLETS); moveHistory(HISTORIC_EXPLODED_MINES); moveHistory(HISTORIC_REPAIRS); moveHistory(HISTORIC_SCANS); }
// private void OnConnectionLost(Object sender, EventArgs e) { if (pbx_Image == null) { } else { if (pbx_Image.InvokeRequired) { // If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. pbx_Image.BeginInvoke(new EventHandler <EventArgs>(OnConnectionLost), sender, e); return; } } // Close the camera object. DestroyCamera(); // Because one device is gone, the list needs to be updated. //UpdateDeviceList(); }