public void Seleccionar(Celda c) { _grupoCeldasSeleccionadas.Add(c); List <Celda> lista = ObtenerCeldasVecinas(c); if (lista.Count == 0) { return; } for (int i = 0; i < lista.Count; i++) { if ((lista[i].IndiceColor == c.IndiceColor) && !this._grupoCeldasSeleccionadas.Contains(lista[i])) { Seleccionar(lista[i]); } } } //--------------------------------------------------
} //------------------------------------------- public void Form1_MouseMove(Object sender, MouseEventArgs e) { if (e.X < 0 || e.X >= TAM * _columnas || e.Y < 0 || e.Y >= TAM * _filas) { return; } int fila = (int)e.Y / TAM; int columna = (int)e.X / TAM; Celda celdaActual = _tablero.Matriz[fila, columna]; if (celdaActual != null) { _tablero.GrupoCeldasSeleccionadas.Clear(); _tablero.Seleccionar(celdaActual); } DibujarTablero(); }//--------------------------------------------
} //--------------------------------------------------------------- public void DibujarTablero() //------------------------------ { int x = 0; int y = 0; List <Celda> celdas = _tablero.GrupoCeldasSeleccionadas; for (int i = 0; i < _filas; i++) { for (int j = 0; j < _columnas; j++) { Celda celda = _tablero.Matriz[i, j]; Rectangle rect = new Rectangle(x, y, TAM - 2, TAM - 2); // if (celda != null) //{ if (celdas.Contains(celda)) { DibujarCuadrado(rect, celda, true); } else { DibujarCuadrado(rect, celda, false); } //} // else //{ // DibujarCuadrado(rect, 0, false, true); // DibujarCuadrado(rect, celda, false); //} x += TAM; } y += TAM; x = 0; } } //-------------------------------------------
public void DibujarCuadrado(Rectangle rect, Celda celda, bool estaSeleccionado) { Color color = Color.Black; Graphics gr = this.CreateGraphics(); if (celda != null) { if (!estaSeleccionado) { color = _coloresNormales[celda.IndiceColor]; } else { color = _coloresSeleccionados[celda.IndiceColor]; } } SolidBrush pincel = new SolidBrush(color); gr.FillRectangle(pincel, rect); pincel.Dispose(); gr.Dispose(); } //---------------------------------------------------------------