// Selección de la bandera private void MarcaBandera() { // Marcamos y pintamos la ficha como seleccionada this.SetSeleccionada(1); MoverFicha.DesactivarGiro(); MoverFicha.DesmarcarCasillas(); // Para desmarcar las casillas que hubieran podido estar marcadas por una selección previa //Desmarcamos la fichas que pudieran haberse seleccionado previamente 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) { if (ControlTurno.GetTurnoJugador() == 0) { ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha); } if (ControlTurno.GetTurnoJugador() == 1) { ficha.GetComponent <MoverFicha>().PonerElementoNegro(ficha); } ficha.GetComponent <MoverFicha>().SetSeleccionada(0); } } }
// Asignamos a la ficha los valores almacenados en el array durante la selección void InicializaFicha(GameObject ficha, int[,,] datosFichas) { // Inicializamos los datos de las fichas ficha.GetComponent <MoverFicha>().SetCaraActiva(FichaSeleccionada.GetCara()); ficha.GetComponent <MoverFicha>().SetElemento0(datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, 0]); ficha.GetComponent <MoverFicha>().SetElemento1(datosFichas[ControlTurno.GetTurnoJugador(), (ficha.GetComponent <numFichaJugador>().idFicha) - 1, 1]); if (ControlTurno.GetTurnoJugador() == 0) { // Inicializamos los datos de las casillas del jugador 1 ficha.GetComponent <MoverFicha>().SetCasillaFicha(ficha.GetComponent <numFichaJugador>().idFicha); this.InicializarCasillas(ficha.GetComponent <numFichaJugador>().idFicha, ControlTurno.GetTurnoJugador()); } else { // Inicializamos los datos de las casillas del jugador 2 ficha.GetComponent <MoverFicha>().SetCasillaFicha(25 - ficha.GetComponent <numFichaJugador>().idFicha); this.InicializarCasillas(25 - ficha.GetComponent <numFichaJugador>().idFicha, ControlTurno.GetTurnoJugador()); } // Indicamos qué fichas tiene la bandera if (ficha.GetComponent <numFichaJugador>().idFicha == 5) { ficha.GetComponent <MoverFicha>().SetTieneBandera(1); } else { ficha.GetComponent <MoverFicha>().SetTieneBandera(0); } }
// Actualizamos el texto del canvas según el jugador que tiene el turno void Update() { if (ControlTurno.GetTurnoJugador() == 0) { this.SetTurnotexto("Turno Jugador 1"); } else { this.SetTurnotexto("Turno Jugador 2"); } }
// al seleccionar la bandera, se selecciona y se iluminan las fichas correspondientes private void OnMouseUp() { if (IniciaPartida.estaPausado == 0 && (ControlTurno.GetTurnoJugador() == 0 && this.tag == "BanderaJugador1") || (ControlTurno.GetTurnoJugador() == 1 && this.tag == "BanderaJugador2")) { // Sonido selección bandera this.SonidoSeleccionBandera(); this.MarcaBandera(); this.IluminarFichas(); } }
// 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); } }
// 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); } }
// Gira la ficha seleccionada dependiendo del jugador y cambia el turno public void GirarPiezaSeleccionada() { GameObject[] fichas = null; // Sonido botón menú this.GetComponent <SonidoMenu>().SonidoSeleccionMenu(); if (ControlTurno.GetTurnoJugador() == 0) { fichas = GameObject.FindGameObjectsWithTag("FichasJugador1"); foreach (GameObject ficha in fichas) { if (ficha.GetComponent <MoverFicha>().GetSeleccionada() == 1) { ficha.GetComponent <MoverFicha>().CambiarCaraActiva(); ficha.GetComponent <MoverFicha>().PonerElementoBlanco(ficha); ficha.GetComponent <MoverFicha>().SetSeleccionada(0); // Sonido giro ficha ficha.GetComponent <MoverFicha>().SonidoFicha(ficha.GetComponent <MoverFicha>().girarFicha); } } } else { fichas = GameObject.FindGameObjectsWithTag("FichasJugador2"); foreach (GameObject ficha in fichas) { if (ficha.GetComponent <MoverFicha>().GetSeleccionada() == 1) { ficha.GetComponent <MoverFicha>().CambiarCaraActiva(); ficha.GetComponent <MoverFicha>().PonerElementoNegro(ficha); ficha.GetComponent <MoverFicha>().SetSeleccionada(0); // Sonido giro ficha ficha.GetComponent <MoverFicha>().SonidoFicha(ficha.GetComponent <MoverFicha>().girarFicha); } } } GameObject controlTurno; controlTurno = GameObject.Find("InfoJugador"); controlTurno.GetComponent <ControlTurno>().CambioTurno(); }
// Para que el jugador vea los efectos de su movimiento antes del cambio de cámara // hacemos una pausa y movemos la cámara IEnumerator Pausa() { Quaternion rotacion; yield return(new WaitForSeconds(0.4f)); if (ControlTurno.GetTurnoJugador() == 0) { ControlTurno.SetTurnoJugador(1); rotacion = Quaternion.Euler(130, 0, 180); GameObject.Find("Main Camera").transform.position = new Vector3(0, 7, 7); GameObject.Find("Main Camera").transform.rotation = rotacion; } else { ControlTurno.SetTurnoJugador(0); rotacion = Quaternion.Euler(50, 0, 0); GameObject.Find("Main Camera").transform.position = new Vector3(0, 7, -6); GameObject.Find("Main Camera").transform.rotation = rotacion; } }
// Al seleccionar una ficha controlamos tres posibilidades, pintamos los posibles destinos de su movimiento, le pasamos la bandera, o la vamos a tomar private void OnMouseUp() { if (IniciaPartida.estaPausado == 0) { if ((ControlTurno.GetTurnoJugador() == 0 && this.tag == "FichasJugador1") || (ControlTurno.GetTurnoJugador() == 1 && this.tag == "FichasJugador2")) { GameObject bandera = null; if (ControlTurno.GetTurnoJugador() == 0) { bandera = GameObject.FindGameObjectWithTag("BanderaJugador1"); } if (ControlTurno.GetTurnoJugador() == 1) { bandera = GameObject.FindGameObjectWithTag("BanderaJugador2"); } if (this.GetSeleccionada() == 1 && bandera.GetComponent <MoverBandera>().GetSeleccionada() == 1) { // Movemos la bandera this.MueveBandera(bandera); } else { // Sonido movimiento bandera this.GetComponent <MoverFicha>().SonidoFicha(seleccionFicha); // Marcamnos los posibles destinos this.MarcaFicha(); } } if (((ControlTurno.GetTurnoJugador() == 0 && this.tag == "FichasJugador2") || (ControlTurno.GetTurnoJugador() == 1 && this.tag == "FichasJugador1")) && (this.GetComponent <MoverFicha>().GetTieneBandera() == 0)) { // Tomamos la ficha this.TomarFicha(); } } }
// Seleccionamos una ficha e indicamos sus posibles destinos void MarcaFicha() { GameObject[] fichas = null; GameObject bandera = null; // Desmarcamos todas las fichas y marcmos la seleccionada if (ControlTurno.GetTurnoJugador() == 0 && this.tag == "FichasJugador1") { fichas = GameObject.FindGameObjectsWithTag("FichasJugador1"); foreach (GameObject ficha in fichas) { this.PonerElementoBlanco(ficha); ficha.GetComponent <MoverFicha>().SetSeleccionada(0); } // Deseleccionamos la bandera por si estaba seleccionada previamente bandera = GameObject.FindGameObjectWithTag("BanderaJugador1"); bandera.GetComponent <MoverBandera>().SetSeleccionada(0); this.SeleccionFicha(); } // Desmarcamos todas las fichas y marcmos la seleccionada if (ControlTurno.GetTurnoJugador() == 1 && this.tag == "FichasJugador2") { fichas = GameObject.FindGameObjectsWithTag("FichasJugador2"); foreach (GameObject ficha in fichas) { this.PonerElementoNegro(ficha); ficha.GetComponent <MoverFicha>().SetSeleccionada(0); } // Deseleccionamos la bandera por si estaba seleccionada previamente bandera = GameObject.FindGameObjectWithTag("BanderaJugador2"); bandera.GetComponent <MoverBandera>().SetSeleccionada(0); this.PonerElementoBlanco(this.gameObject); this.SeleccionFicha(); } }
// Actualizamos el texto del vencedor en base al tugador que tenía el turno al darse la condición de victoria private void Update() { textoVictoria.text = "Victoria del Juagador "; textoVictoria.text += ControlTurno.GetTurnoJugador() + 1; }
// 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(); }
// 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(); } }
// 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); } } } } }
// 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); } } } }
// Recorremos las casillas a pintar según el jugador y la ficha en la que está la ficha private void IluminarCasillas() { MoverFicha.DesmarcarCasillas(); int fila = 0; GameObject[] casillas = null; casillas = GameObject.FindGameObjectsWithTag("Casilla"); foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { fila = casilla.GetComponent <numCasillaTablero>().GetFilaCasilla(); } } if (fila == 1 && ControlTurno.GetTurnoJugador() == 0) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() + 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 4 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } if (fila == 2 && ControlTurno.GetTurnoJugador() == 0) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() - 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 2 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 4 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } if (fila == 3 && ControlTurno.GetTurnoJugador() == 0) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() - 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 2 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } if (fila == 1 && ControlTurno.GetTurnoJugador() == 1) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() - 2 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } if (fila == 2 && ControlTurno.GetTurnoJugador() == 1) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() - 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() + 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 2 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 4 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } if (fila == 3 && ControlTurno.GetTurnoJugador() == 1) { foreach (GameObject casilla in casillas) { if (this.GetCasillaFicha() - 1 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 4 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla() || this.GetCasillaFicha() - 3 == casilla.GetComponent <numCasillaTablero>().GetIdCasilla()) { this.PintaCasilla(casilla); } } } }
// 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); } } }
// 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); } } } }