public void AddFicha(Fichas ficha, Posicion posicion) { if (ficha == _ultimaFicha) { throw new InvalidOperationException("No se pueden añadir dos fichas seguidas."); } if (_tablero[posicion.Columna, posicion.Fila] != null) throw new InvalidOperationException("Ya existe una ficha en esa posición."); _tablero[posicion.Columna, posicion.Fila] = ficha; _ultimaFicha = ficha; }
private void AñadirBotones() { for (byte i = 0; i < 3; i++) for (byte j = 0; j < 3; j++) { var posicion = new Posicion(i, j); tablero.AddFicha(TurnoFicha, posicion); ButtonFicha bf = CrearBoton(i, j, 139 + (150 * i), 78 + 127 * j, tablero.GetFicha(posicion)); buttonFicha[i, j] = bf; this.Controls.Add(bf); } if (tablero.GetGanador()!=null) { btnFin.Visible = true; pictureBoxLineasDivisorias.Enabled = false; } }
public bool Equals(Posicion other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._fila == _fila && other._columna == _columna; }
public Fichas? GetFicha(Posicion posicion) { return _tablero[posicion.Columna,posicion.Fila]; }
public void En(Posicion posicion) { AddFicha(_ficha, posicion); }
private void refreshTablero() { for (byte i = 0; i < 3; i++) for (byte j = 0; j < 3; j++) { var posicion = new Posicion(i, j); buttonFicha[i, j].Text = GetStringFicha(tablero.GetFicha(posicion)); } }
private void ButtonFichaClick(object sender, EventArgs e) { var bf = (ButtonFicha)sender; var posicion = new Posicion((byte) bf.Posicion.Fila, (byte) bf.Posicion.Columna); tablero.AddFicha(TurnoFicha, posicion); refreshTablero(); if (tablero.GetGanador() != null) { btnFin.Visible = true; pictureBoxLineasDivisorias.Enabled = false; } }