Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 public bool Equals(Posicion other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other._fila == _fila && other._columna == _columna;
 }
Exemplo n.º 4
0
 public Fichas? GetFicha(Posicion posicion)
 {
     return _tablero[posicion.Columna,posicion.Fila];
 }
Exemplo n.º 5
0
 public void En(Posicion posicion)
 {
     AddFicha(_ficha, posicion);
 }
Exemplo n.º 6
0
 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));
         }
 }
Exemplo n.º 7
0
        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;
            }
        }