// Borra la selección de fichas y elementos del jugador 2
    public void BorraSeleccionJugador2()
    {
        GameObject[] fichas;

        // Sonido botón menú
        this.GetComponent <SonidoMenu>().SonidoSeleccionMenu();
        // Pone a 0 los valores de las fichas del jugador 2 de la cara acual
        FichaSeleccionada.InicializaFichasJugador2();
        // Indica como desmarcadas todas las fichas del jugador 2
        FichaSeleccionada.InicializaFichasSeleccionadas();

        // Añadimos al array todas las fichas del jugador 2
        fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");

        foreach (GameObject ficha in fichas)
        {
            // recorremos todas las fichas quitando el elemento y la selección
            CambiaObjeto.QuitaMaterial(ficha);
            CambiaObjeto.PintaGris(ficha);
        }

        // Inicializamos el elemento seleccionado
        ElementoSeleccionado.SetElementoSeleccionado(0);
        // Limpiamos la selección de elemento
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Fuego"));
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Agua"));
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Madera"));
    }
    //
    // Desmarcar las casillas activadas
    //

    public static void DesmarcarCasillas()
    {
        GameObject[] casillas = null;
        casillas = GameObject.FindGameObjectsWithTag("Casilla");
        foreach (GameObject casilla in casillas)
        {
            CambiaObjeto.PintaBlanco(casilla);
            casilla.GetComponent <numCasillaTablero>().SetEstaIluminada(0);
        }
    }
Exemple #3
0
 // Set Seleccionado
 public void SetSeleccionada(int valor)
 {
     this.seleccionada = valor;
     if (valor == 1)
     {
         CambiaObjeto.PintaVerde(this.gameObject);
     }
     if (valor == 0 && ControlTurno.GetTurnoJugador() == 0)
     {
         CambiaObjeto.PintaNegro(this.gameObject);
     }
     if (valor == 0 && ControlTurno.GetTurnoJugador() == 1)
     {
         CambiaObjeto.PintaBlanco(this.gameObject);
     }
 }
Exemple #4
0
    // Borra la selección de fichas y elementos del jugador 2
    public void GuardaFichasJugador2()
    {
        GameObject[] fichas;

        // Indica como desmarcadas todas las fichas del jugador 1
        FichaSeleccionada.InicializaFichasSeleccionadas();

        // Añadimos al array todas las fichas del jugador 1
        fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");

        foreach (GameObject ficha in fichas)
        {
            // recorremos todas las fichas quitando el elemento y la selección
            CambiaObjeto.QuitaMaterial(ficha);
            CambiaObjeto.PintaGris(ficha);
        }

        // Inicializamos el elemento seleccionado
        ElementoSeleccionado.SetElementoSeleccionado(0);
        // Limpiamos la selección de elemento
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Fuego"));
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Agua"));
        CambiaObjeto.PintaBlanco(GameObject.FindGameObjectWithTag("Madera"));
    }
Exemple #5
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();
        }
    }
Exemple #6
0
    // Control de la seleccion de elementos
    private void OnMouseUp()
    {
        int numFichasSeleccionadas = FichaSeleccionada.GetTotalFichasSeleccionadas();

        ////foreach (int i in FichaSeleccionada.GetFichasSeleccionadas())
        // Sonido botón menú
        this.GetComponent <Elementos>().SonidoSeleccion();

        // si no hay fichas del jugador seleccionadas marcaremos y/o desmarcaremos el elemento seleccionado. solo puede haber uno
        if (numFichasSeleccionadas == 0)
        {
            if (elementoSeleccionado == this.GetComponent <Elementos>().idElemento)
            {
                CambiaObjeto.PintaBlanco(this.gameObject);
                ElementoSeleccionado.SetElementoSeleccionado(0);
            }
            else
            {
                if (elementoSeleccionado == 1)
                {
                    CambiaObjeto.PintaBlanco(fuego.gameObject);
                }
                if (elementoSeleccionado == 2)
                {
                    CambiaObjeto.PintaBlanco(agua.gameObject);
                }
                if (elementoSeleccionado == 3)
                {
                    CambiaObjeto.PintaBlanco(madera.gameObject);
                }
                CambiaObjeto.PintaVerde(this.gameObject);
                ElementoSeleccionado.SetElementoSeleccionado(this.GetComponent <Elementos>().idElemento);
            }
        }
        else
        // Si hay fichas del jugador seleccionadas, las pondremos del material correspondiente al elemento y quitaremos todas las selecciones
        {
            GameObject[] fichas = null;
            // Añadimos al array todas las fichas del jugador
            if (FichaSeleccionada.GetJugador() == 0)
            {
                fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
            }
            if (FichaSeleccionada.GetJugador() == 1)
            {
                fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
            }

            elementoSeleccionado = this.GetComponent <Elementos>().idElemento;
            foreach (GameObject ficha in fichas)
            {
                if (FichaSeleccionada.GetFichasSeleccionadas()[ficha.GetComponent <numFichaJugador>().idFicha - 1] == 1)
                {
                    // recorremos todas las fichas asignando el elemento y añadiendo a las fichs seleccionadas
                    if (FichaSeleccionada.GetJugador() == 0)
                    {
                        if (ElementoSeleccionado.GetElementoSeleccionado() == 1)
                        {
                            CambiaObjeto.AsignaFuegoBlanco(ficha);
                        }

                        if (ElementoSeleccionado.GetElementoSeleccionado() == 2)
                        {
                            CambiaObjeto.AsignaAguaBlanca(ficha);
                        }

                        if (ElementoSeleccionado.GetElementoSeleccionado() == 3)
                        {
                            CambiaObjeto.AsignaMaderaBlanca(ficha);
                        }
                    }
                    if (FichaSeleccionada.GetJugador() == 1)
                    {
                        if (ElementoSeleccionado.GetElementoSeleccionado() == 1)
                        {
                            CambiaObjeto.AsignaFuegoNegro(ficha);
                        }

                        if (ElementoSeleccionado.GetElementoSeleccionado() == 2)
                        {
                            CambiaObjeto.AsignaAguaNegra(ficha);
                        }

                        if (ElementoSeleccionado.GetElementoSeleccionado() == 3)
                        {
                            CambiaObjeto.AsignaMaderaNegra(ficha);
                        }
                    }
                    FichaSeleccionada.SetFichaJugador(ficha);
                }
            }
            ElementoSeleccionado.SetElementoSeleccionado(0);
            FichaSeleccionada.InicializaFichasSeleccionadas();
        }
    }
    // Tomar una ficha del otro jugador
    void TomarFicha()
    {
        GameObject[] casillas = null;
        casillas = GameObject.FindGameObjectsWithTag("Casilla");
        foreach (GameObject casilla in casillas)
        {
            // Solo si la casilla está marcada indicando que la pieza que tiene pieza es posible tomarla
            if (this.GetCasillaFicha() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() && casilla.GetComponent <numCasillaTablero>().GetEstaIluminada() == 2)
            {
                GameObject[] fichas   = null;
                GameObject   marcador = null;
                if (ControlTurno.GetTurnoJugador() == 0)
                {
                    fichas   = GameObject.FindGameObjectsWithTag("FichasJugador1");
                    marcador = GameObject.Find("Marcador Jugador 1");
                }
                if (ControlTurno.GetTurnoJugador() == 1)
                {
                    fichas   = GameObject.FindGameObjectsWithTag("FichasJugador2");
                    marcador = GameObject.Find("Marcador Jugador 2");
                }
                foreach (GameObject ficha in fichas)
                {
                    // Si la ficha no tiene la bandera y puedo tomar la ficha, realizamos los movimientos de fichas
                    if (ficha.GetComponent <MoverFicha>().GetSeleccionada() == 1 && ficha.GetComponent <MoverFicha>().GetTieneBandera() == 0 && this.PuedoTomar(ficha, this.gameObject) == 1)
                    {
                        ficha.transform.position = this.gameObject.transform.position;

                        GameObject[] casillasOrigen = null;
                        casillasOrigen = GameObject.FindGameObjectsWithTag("Casilla");
                        foreach (GameObject casillaOrigen in casillasOrigen)
                        {
                            if (casillaOrigen.GetComponent <numCasillaTablero>().GetIdCasilla() == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                            {
                                casillaOrigen.GetComponent <numCasillaTablero>().SetEstaOcupada(0);
                                casillaOrigen.GetComponent <numCasillaTablero>().SetJugadorOcupa(-1);
                            }
                        }

                        ficha.GetComponent <MoverFicha>().SetCasillaFicha(this.GetCasillaFicha());
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(0);
                        if (ControlTurno.GetTurnoJugador() == 1)
                        {
                            ficha.GetComponent <MoverFicha>().PonerElementoNegro(ficha);
                        }
                        else
                        {
                            CambiaObjeto.PintaBlanco(ficha);
                        }
                        casilla.GetComponent <numCasillaTablero>().SetEstaOcupada(1);
                        casilla.GetComponent <numCasillaTablero>().SetJugadorOcupa(ControlTurno.GetTurnoJugador());

                        // Sonido tomar ficha
                        this.GetComponent <MoverFicha>().SonidoFicha(tomarFicha);

                        // Tras tomar la ficha cambiamos el turno y destruimos la ficha tomada
                        GameObject controlTurno;
                        controlTurno = GameObject.Find("InfoJugador");
                        controlTurno.GetComponent <ControlTurno>().CambioTurno();

                        StartCoroutine(DestruirFicha(marcador));
                    }
                }
            }
            if (this.GetCasillaFicha() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() && casilla.GetComponent <numCasillaTablero>().GetEstaIluminada() != 2)
            {
                // Sonido movimiento incorrecto
                this.GetComponent <MoverFicha>().SonidoFicha(movimientoIncorrecto);
            }
        }
    }
Exemple #8
0
    static protected int jugador;                                // 0 o 1

    // Comportamiento al pinchar
    private void OnMouseUp()
    {
        this.GetComponent <numFichaJugador>().SonidoSeleccion();
        // Si no hay elemento seleccionado permitiremos ir seleccionando o deseleccinando varias fichas del jugador1
        if (ElementoSeleccionado.GetElementoSeleccionado() == 0)
        {
            // Si la ficha no estaba seleccionada la marcamos de verde, si ya estaba seleccionada la ponemos blanca
            if (fichasSeleccionadas[this.GetComponent <numFichaJugador>().idFicha - 1] == 0)
            {
                if (FichaSeleccionada.GetJugador() == 1 && FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] > 0)
                {
                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 1)
                    {
                        CambiaObjeto.AsignaFuegoBlanco(this.gameObject);
                    }

                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 2)
                    {
                        CambiaObjeto.AsignaAguaBlanca(this.gameObject);
                    }

                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 3)
                    {
                        CambiaObjeto.AsignaMaderaBlanca(this.gameObject);
                    }
                }

                CambiaObjeto.PintaVerde(this.gameObject);
                fichasSeleccionadas[this.GetComponent <numFichaJugador>().idFicha - 1] = 1;
                totalFichasSeleccionadas++;
            }
            else
            {
                if (FichaSeleccionada.GetJugador() == 0)
                {
                    CambiaObjeto.PintaBlanco(this.gameObject);
                }
                if (FichaSeleccionada.GetJugador() == 1 && FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.cara] == 0)
                {
                    CambiaObjeto.PintaGris(this.gameObject);
                }
                if (FichaSeleccionada.GetJugador() == 1 && FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.cara] > 0)
                {
                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 1)
                    {
                        CambiaObjeto.AsignaFuegoNegro(this.gameObject);
                    }

                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 2)
                    {
                        CambiaObjeto.AsignaAguaNegra(this.gameObject);
                    }

                    if (FichaSeleccionada.fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] == 3)
                    {
                        CambiaObjeto.AsignaMaderaNegra(this.gameObject);
                    }
                }

                fichasSeleccionadas[this.GetComponent <numFichaJugador>().idFicha - 1] = 0;
                totalFichasSeleccionadas--;
            }
        }
        else
        // Si hay un elemento seleccionado, cambiaremos el material de la ficha
        {
            // Si la ficha ya tiene ese elemento se lo quitaremos
            if (ElementoSeleccionado.GetElementoSeleccionado() == fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()])
            {
                CambiaObjeto.QuitaMaterial(this.gameObject);
                fichasJugadores[FichaSeleccionada.GetJugador(), this.GetComponent <numFichaJugador>().idFicha - 1, FichaSeleccionada.GetCara()] = 0;
            }
            else // Si la ficha no tiene ese elemento, le asignaremos el elemento seleccionado independientemente del elemento que tuviera la ficha anteriormente
            {
                if (FichaSeleccionada.GetJugador() == 0)
                {
                    if (ElementoSeleccionado.GetElementoSeleccionado() == 1)
                    {
                        CambiaObjeto.AsignaFuegoBlanco(this.gameObject);
                    }

                    if (ElementoSeleccionado.GetElementoSeleccionado() == 2)
                    {
                        CambiaObjeto.AsignaAguaBlanca(this.gameObject);
                    }

                    if (ElementoSeleccionado.GetElementoSeleccionado() == 3)
                    {
                        CambiaObjeto.AsignaMaderaBlanca(this.gameObject);
                    }
                }
                if (FichaSeleccionada.GetJugador() == 1)
                {
                    if (ElementoSeleccionado.GetElementoSeleccionado() == 1)
                    {
                        CambiaObjeto.AsignaFuegoNegro(this.gameObject);
                    }

                    if (ElementoSeleccionado.GetElementoSeleccionado() == 2)
                    {
                        CambiaObjeto.AsignaAguaNegra(this.gameObject);
                    }

                    if (ElementoSeleccionado.GetElementoSeleccionado() == 3)
                    {
                        CambiaObjeto.AsignaMaderaNegra(this.gameObject);
                    }
                }
                FichaSeleccionada.SetFichaJugador(this.gameObject);
            }
        }
    }