private void timerCleaner_Tick(object sender, EventArgs e) { if (Cleaner.IsValid(cleaner)) { //MoveCleaner(random.Next(100) < 50 ? Direction.LEFT : Direction.RIGHT); } }
void MoveCleanerTo(int x, int y) { if (Cleaner.IsValid(cleaner)) { while (cleaner.RowIndex != x || cleaner.ColumnIndex != y) { if (y >= cleaner.ColumnIndex) { MoveCleaner(Direction.LEFT); } else { MoveCleaner(Direction.RIGHT); } if (x >= cleaner.RowIndex) { MoveCleaner(Direction.RIGHT); } else { MoveCleaner(Direction.LEFT); } Thread.Sleep(500); } } }
private void btnMoveTo_Click(object sender, EventArgs e) { if (Cleaner.IsValid(cleaner)) { int x = random.Next(cleaner.ColumnIndex.Value, COLUMNS), y = random.Next(cleaner.RowIndex.Value, ROWS); Debug.WriteLine("El cleaner se moverá a: " + x + ", " + y + "."); MoveCleanerTo(x, y); } }
void MoveCleaner(Direction direction) { if (Cleaner.IsValid(cleaner)) { int oldRowIndex = cleaner.RowIndex.Value, oldColumnIndex = cleaner.ColumnIndex.Value; bsEnvironment.EndEdit(); int posibilidad = random.Next(100); cleaner.Move(direction); int newRowIndex = cleaner.RowIndex.Value, newColumnIndex = cleaner.ColumnIndex.Value; UpdateCleaner(oldRowIndex, newRowIndex); } }
void UpdateDGVRow(int row) { try { foreach (DataGridViewImageCell item in dgvEnvironment.Rows[row].Cells) { Place place = (bsEnvironment[item.RowIndex] as PlaceRow).Places[item.ColumnIndex]; if (Cleaner.IsValid(cleaner)) { if (item.ColumnIndex == cleaner.ColumnIndex.Value && item.RowIndex == cleaner.RowIndex.Value) { item.Value = Images.RotateImage(Resources.cleaner, 90 * Convert.ToInt32(cleaner.Orientation), true, true, Color.Transparent); item.ImageLayout = DataGridViewImageCellLayout.Zoom; place.State = PlaceState.CLEAN; bsEnvironment.EndEdit(); } else { switch (place.State) { case PlaceState.DIRTY: item.Value = Images.RotateImage(Resources.Mugre2, new Random().Next(0, 360), true, true, Color.Transparent); item.ImageLayout = DataGridViewImageCellLayout.Zoom; break; default: item.Value = null; break; } } } else { switch (place.State) { case PlaceState.DIRTY: item.Value = Images.RotateImage(Resources.Mugre2, new Random().Next(0, 360), true, true, Color.Transparent); item.ImageLayout = DataGridViewImageCellLayout.Zoom; break; default: item.Value = null; break; } } } } catch (Exception) { } }