// 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"));
    }
Example #2
0
 // dependiendo de si la casilla destino está ocupada o no, y qué ficha la ocupa, pintaremos de verde o rojo la casilla
 void PintaCasilla(GameObject casilla)
 {
     if (casilla.GetComponent <numCasillaTablero>().GetEstaOcupada() == 0)
     {
         CambiaObjeto.PintaVerde(casilla);
         casilla.GetComponent <numCasillaTablero>().SetEstaIluminada(1);
     }
     if (casilla.GetComponent <numCasillaTablero>().GetEstaOcupada() == 1 && casilla.GetComponent <numCasillaTablero>().GetJugadorOcupa() == 0 && ControlTurno.GetTurnoJugador() == 1)
     {
         GameObject[] fichas = null;
         fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
         foreach (GameObject ficha in fichas)
         {
             if (PuedoTomar(this.gameObject, ficha) == 1 && ficha.GetComponent <MoverFicha>().GetCasillaFicha() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla())
             {
                 CambiaObjeto.PintaRojo(casilla);
                 casilla.GetComponent <numCasillaTablero>().SetEstaIluminada(2);
             }
         }
     }
     if (casilla.GetComponent <numCasillaTablero>().GetEstaOcupada() == 1 && casilla.GetComponent <numCasillaTablero>().GetJugadorOcupa() == 1 && ControlTurno.GetTurnoJugador() == 0)
     {
         GameObject[] fichas = null;
         fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
         foreach (GameObject ficha in fichas)
         {
             if (PuedoTomar(this.gameObject, ficha) == 1 && ficha.GetComponent <MoverFicha>().GetCasillaFicha() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla())
             {
                 CambiaObjeto.PintaRojo(casilla);
                 casilla.GetComponent <numCasillaTablero>().SetEstaIluminada(2);
             }
         }
     }
 }
Example #3
0
    //
    // 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);
        }
    }
    // Al iniciar pone las fichas con los elementos correspondientes si ya se habían seleccionado
    void Start()
    {
        GameObject[] fichas = null;
        int[,,] datosFichas = null;
        // Añadimos al array todas las fichas del jugador 1
        if (FichaSeleccionada.GetJugador() == 0)
        {
            fichas      = GameObject.FindGameObjectsWithTag("FichasJugador1");
            datosFichas = FichaSeleccionada.GetFichasJugadores();
            foreach (GameObject ficha in fichas)
            {
                // recorremos todas las fichas asignando el elemento y añadiendo a las fichas seleccionadas
                if (datosFichas[FichaSeleccionada.GetJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 1)
                {
                    CambiaObjeto.AsignaFuegoBlanco(ficha);
                }

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

                if (datosFichas[FichaSeleccionada.GetJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 3)
                {
                    CambiaObjeto.AsignaMaderaBlanca(ficha);
                }
            }
        }
        // Añadimos al array todas las fichas del jugador 2
        if (FichaSeleccionada.GetJugador() == 1)
        {
            fichas      = GameObject.FindGameObjectsWithTag("FichasJugador2");
            datosFichas = FichaSeleccionada.GetFichasJugadores();
            foreach (GameObject ficha in fichas)
            {
                // recorremos todas las fichas asignando el elemento y añadiendo a las fichas seleccionadas
                if (datosFichas[FichaSeleccionada.GetJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 1)
                {
                    CambiaObjeto.AsignaFuegoNegro(ficha);
                }

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

                if (datosFichas[FichaSeleccionada.GetJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 3)
                {
                    CambiaObjeto.AsignaMaderaNegra(ficha);
                }
            }
        }
    }
Example #5
0
 // Poner elemento negro en ficha
 public void PonerElementoNegro(GameObject ficha)
 {
     if (ficha.GetComponent <MoverFicha>().GetElementoActivo() == 1)
     {
         CambiaObjeto.AsignaFuegoNegro(ficha);
     }
     if (ficha.GetComponent <MoverFicha>().GetElementoActivo() == 2)
     {
         CambiaObjeto.AsignaAguaNegra(ficha);
     }
     if (ficha.GetComponent <MoverFicha>().GetElementoActivo() == 3)
     {
         CambiaObjeto.AsignaMaderaNegra(ficha);
     }
 }
Example #6
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);
     }
 }
Example #7
0
 // Al seleccionar una ficha, la iluminamos en verde, activamos el giro y pintamos las casillas donde se puede mover
 private void SeleccionFicha()
 {
     CambiaObjeto.PintaVerde(this.gameObject);
     this.SetSeleccionada(1);
     MoverFicha.ActivarGiro();
     if (this.GetTieneBandera() == 1)
     {
         // si la ficha seleccionada tiene la bandera se marcará solo la casilla frente a la ficha si está libre
         this.IluminarCasillasFichaBandera();
     }
     else
     {
         // si la ficha no tiene la bandera marcaremos los posibles destinos de la ficha distinguiendo si es solo moviemiento o si puede comer
         this.IluminarCasillas();
     }
 }
Example #8
0
 // Indicamos las casillas a las que la ficha con la bandera se puede mover
 private void IluminarCasillasFichaBandera()
 {
     MoverFicha.DesmarcarCasillas();
     GameObject[] casillas = null;
     casillas = GameObject.FindGameObjectsWithTag("Casilla");
     foreach (GameObject casilla in casillas)
     {
         if ((this.GetCasillaFicha() + 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() && ControlTurno.GetTurnoJugador() == 0) ||
             (this.GetCasillaFicha() - 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() && ControlTurno.GetTurnoJugador() == 1))
         {
             if (casilla.GetComponent <numCasillaTablero>().GetEstaOcupada() == 0)
             {
                 CambiaObjeto.PintaVerde(casilla);
                 casilla.GetComponent <numCasillaTablero>().SetEstaIluminada(1);
             }
         }
     }
 }
Example #9
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"));
    }
Example #10
0
    // Al iniciar pone las fichas y banderas con los elementos correspondientes si ya se habían seleccionado
    void Start()
    {
        // Desactivamos el panel de victoria
        IniciaPartida.panelVictoria = GameObject.Find("Fondo");
        IniciaPartida.panelVictoria.SetActive(false);
        IniciaPartida.estaPausado = 0;

        // Desactivamos el panel de Salir
        IniciaPartida.panelSalir = GameObject.Find("FondoSalir");
        IniciaPartida.panelSalir.SetActive(false);

        GameObject bandera = null;

        GameObject[] fichas = null;
        int[,,] datosFichas = new int[2, 9, 2];
        // Añadimos al array todas las fichas y la bandera del jugador 1

        datosFichas = FichaSeleccionada.GetFichasJugadores();
        FichaSeleccionada.SetCara(0);
        ControlTurno.SetTurnoJugador(0);
        fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
        foreach (GameObject ficha in fichas)
        {
            // recorremos todas las fichas asignando el elemento y añadiendo a las fichas seleccionadas
            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 1)
            {
                CambiaObjeto.AsignaFuegoBlanco(ficha);
            }

            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 2)
            {
                CambiaObjeto.AsignaAguaBlanca(ficha);
            }

            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 3)
            {
                CambiaObjeto.AsignaMaderaBlanca(ficha);
            }
            this.InicializaFicha(ficha, datosFichas);
        }
        bandera = GameObject.FindGameObjectWithTag("BanderaJugador1");
        bandera.GetComponent <MoverBandera>().SetCasillaBandera(5);

        // Añadimos al array todas las fichas y la bandera del jugador 2
        ControlTurno.SetTurnoJugador(1);
        fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
        //datosFichas = FichaSeleccionada.GetFichasJugadores();
        foreach (GameObject ficha in fichas)
        {
            // recorremos todas las fichas asignando el elemento y añadiendo a las fichas seleccionadas
            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 1)
            {
                CambiaObjeto.AsignaFuegoNegro(ficha);
            }

            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 2)
            {
                CambiaObjeto.AsignaAguaNegra(ficha);
            }

            if (datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, FichaSeleccionada.GetCara()] == 3)
            {
                CambiaObjeto.AsignaMaderaNegra(ficha);
            }
            this.InicializaFicha(ficha, datosFichas);
        }
        bandera = GameObject.FindGameObjectWithTag("BanderaJugador2");
        bandera.GetComponent <MoverBandera>().SetCasillaBandera(20);

        // Preparamos el tueno y el botón de giro
        ControlTurno.SetTurnoJugador(0);
        MoverFicha.DesactivarGiro();
    }
Example #11
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();
        }
    }
Example #12
0
    // Iluminamos las fichas a las que podemos pasar la bandera
    private void IluminarFichas()
    {
        int fila = 0;

        GameObject[] casillas = null;
        casillas = GameObject.FindGameObjectsWithTag("Casilla");
        foreach (GameObject casilla in casillas)
        {
            if (this.GetCasillaBandera() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla())
            {
                fila = casilla.GetComponent <numCasillaTablero>().GetFilaCasilla();
            }
        }

        if (ControlTurno.GetTurnoJugador() == 0)
        {
            GameObject[] fichas = null;
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador1");
            foreach (GameObject ficha in fichas)
            {
                if (fila == 1)
                {
                    if (this.GetCasillaBandera() + 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 4 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
                if (fila == 2)
                {
                    if (this.GetCasillaBandera() - 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 2 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 4 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
                if (fila == 3)
                {
                    if (this.GetCasillaBandera() - 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 2 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
            }
        }

        if (ControlTurno.GetTurnoJugador() == 1)
        {
            GameObject[] fichas = null;
            fichas = GameObject.FindGameObjectsWithTag("FichasJugador2");
            foreach (GameObject ficha in fichas)
            {
                if (fila == 1)
                {
                    if (this.GetCasillaBandera() + 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 2 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha);
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
                if (fila == 2)
                {
                    if (this.GetCasillaBandera() - 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() + 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 2 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 4 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha);
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
                if (fila == 3)
                {
                    if (this.GetCasillaBandera() - 3 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 4 == ficha.GetComponent <MoverFicha>().GetCasillaFicha() ||
                        this.GetCasillaBandera() - 1 == ficha.GetComponent <MoverFicha>().GetCasillaFicha())
                    {
                        ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha);
                        CambiaObjeto.PintaVerde(ficha);
                        ficha.GetComponent <MoverFicha>().SetSeleccionada(1);
                    }
                }
            }
        }
    }
Example #13
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();
        }
    }
Example #14
0
    // 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);
            }
        }
    }
Example #15
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);
            }
        }
    }