// Movemos la bandera a la ficha destino
    void MueveBandera(GameObject bandera)
    {
        GameObject[] fichas = null;
        if (ControlTurno.GetTurnoJugador() == 0)
        {
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
        }
        if (ControlTurno.GetTurnoJugador() == 1)
        {
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
        }
        foreach (GameObject ficha in fichas)
        {
            if (ficha.GetComponent <MoverFicha>().GetTieneBandera() == 1)
            {
                ficha.GetComponent <MoverFicha>().SetTieneBandera(0);
            }
            if (ControlTurno.GetTurnoJugador() == 0)
            {
                ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha);
            }
            if (ControlTurno.GetTurnoJugador() == 1)
            {
                ficha.GetComponent <MoverFicha>().PonerElementoNegro(ficha);
            }
        }

        bandera.transform.position = this.transform.position;
        bandera.GetComponent <MoverBandera>().SetSeleccionada(0);
        bandera.GetComponent <MoverBandera>().SetCasillaBandera(this.GetCasillaFicha());
        this.SetTieneBandera(1);

        if (bandera.GetComponent <MoverBandera>().GetCasillaBandera() < 4 || bandera.GetComponent <MoverBandera>().GetCasillaBandera() > 21)
        {
            // Control de victoria si la bandera se ha movido a la última línea del jugador contrario
            IniciaPartida.ActivarPanelVictoria();
        }
        else
        {
            // Tras mover la bandera se pasa el turno
            GameObject controlTurno;
            controlTurno = GameObject.Find("InfoJugador");
            controlTurno.GetComponent <ControlTurno>().CambioTurno();

            // Sonido movimiento bandera
            this.GetComponent <MoverFicha>().SonidoFicha(moverBandera);
        }
    }
Exemple #2
0
    // Movemos la ficha y la su bandera si la lleva y actualizamos la información de las casillas origen y destino, y la información de la ficha
    private void MueveFicha()
    {
        GameObject bandera = null;

        GameObject[] fichas = null;
        if (ControlTurno.GetTurnoJugador() == 0)
        {
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
        }
        if (ControlTurno.GetTurnoJugador() == 1)
        {
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
        }
        foreach (GameObject ficha in fichas)
        {
            if (ficha.GetComponent <MoverFicha>().GetSeleccionada() == 1)
            {
                // movemos la ficha
                ficha.transform.position = this.gameObject.transform.position;
                if (ficha.GetComponent <MoverFicha>().GetTieneBandera() == 1)
                {
                    if (ControlTurno.GetTurnoJugador() == 0)
                    {
                        bandera = GameObject.FindGameObjectWithTag("BanderaJugador1");
                    }
                    else
                    {
                        bandera = GameObject.FindGameObjectWithTag("BanderaJugador2");
                    }
                    // Movemos la bandera
                    bandera.transform.position = this.gameObject.transform.position;
                    bandera.GetComponent <MoverBandera>().SetCasillaBandera(this.GetIdCasilla());
                }

                GameObject[] casillas = null;
                casillas = GameObject.FindGameObjectsWithTag("Casilla");
                foreach (GameObject casilla in casillas)
                {
                    if (casilla.GetComponent <numCasillaTablero>().GetIdCasilla() == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        // Actualizamos información de la casilla origen
                        casilla.GetComponent <numCasillaTablero>().SetEstaOcupada(0);
                        casilla.GetComponent <numCasillaTablero>().SetJugadorOcupa(-1);
                    }
                }

                // Actualizamos información de las fichas
                ficha.GetComponent <MoverFicha>().SetCasillaFicha(this.GetIdCasilla());
                ficha.GetComponent <MoverFicha>().SetSeleccionada(0);
                if (ControlTurno.GetTurnoJugador() == 1)
                {
                    ficha.GetComponent <MoverFicha>().PonerElementoNegro(ficha);
                }
                else
                {
                    CambiaObjeto.PintaBlanco(ficha);
                }
                // Actualizamos insformación de la casilla destino
                this.SetEstaOcupada(1);
                this.SetJugadorOcupa(ControlTurno.GetTurnoJugador());

                // Sonido movimiento ficha
                ficha.GetComponent <MoverFicha>().SonidoFicha(ficha.GetComponent <MoverFicha>().moverFicha);
            }
        }
        if (bandera != null && (bandera.GetComponent <MoverBandera>().GetCasillaBandera() < 4 || bandera.GetComponent <MoverBandera>().GetCasillaBandera() > 21))
        {
            // si al mover la ficha se lleva una ficha con la bandera al final del tablero contrario se gana la partida
            IniciaPartida.ActivarPanelVictoria();
        }
        else
        {
            // Tras mover la ficha se pasa el turno
            GameObject controlTurno;
            controlTurno = GameObject.Find("InfoJugador");
            controlTurno.GetComponent <ControlTurno>().CambioTurno();
        }
    }