public IEnumerator MoveDoble(GameObject nextTile, float a) { TileBots tile = nextTile.GetComponent <TileBots>(); tile.inverse = !tile.inverse; if (a == 180) { a = 0; } if (a == 0) { a = 180; } if (classMatch.tileLeft == nextTile && colliderWall1 || classMatch.tileRight == nextTile && colliderWall1) { pos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1.9f); } if (classMatch.tileLeft == nextTile && colliderWall2 || classMatch.tileRight == nextTile && colliderWall2) { pos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.9f); } var angl = nextTile.transform.rotation.eulerAngles; angl.z = a; angl.x = 90; nextTile.transform.rotation = Quaternion.Euler(angl); float normalizedTime = 0.0f; classMatch.putTile.Play(); while (normalizedTime < 1) { tile.transform.position = Vector3.Lerp(tile.transform.position, pos, normalizedTime); normalizedTime += Time.deltaTime / duration; yield return(null); } tile.transform.position = pos; if (classMatch.PlayerInTurn == 1) { classMatch.ChangeTilesToNormal(); } yield return(new WaitForSeconds(1f)); classMatch.noPlay = false; MatchDates.Instance.selectedFicha = null; classMatch.ValidateEnd(); classMatch.ChangeTurn(); }
public void AuxPlayBot(List <GameObject> fichasList, GameObject panel) { GameObject tileOut = null; int max = 0; for (int i = 0; i < fichasList.Count; i++) { TileBots ficha = fichasList[i].GetComponent <TileBots>(); if (!ficha.onTable) { if (ficha.pointDown == countLeft || ficha.pointDown == countRight || ficha.pointUp == countLeft || ficha.pointUp == countRight) { if (ficha.countpoints >= max) { tileOut = fichasList[i]; max = ficha.countpoints; } } } } if (tileOut == null) { msg.text = "El jugador " + PlayerInTurn + " se ha pasado"; tocToc.Play(); countPase++; ValidateEnd(); Invoke(nameof(ChangeTurn), 2); } else { panel.transform.GetComponent <PanelPlayerController>().ChangeCountTiles(); tileOut.transform.SetParent(table.transform); if (tileOut.GetComponent <TileBots>().pointDown == countLeft || tileOut.GetComponent <TileBots>().pointUp == countLeft) { tileLeft.GetComponent <TileBots>().MovNexTile(tileOut); return; } if (tileOut.GetComponent <TileBots>().pointDown == countRight || tileOut.GetComponent <TileBots>().pointUp == countRight) { tileRight.GetComponent <TileBots>().MovNexTile(tileOut); } } }
public void ThenChangeTurn() { panelsBot1.GetComponent <PanelPlayerController>().Change(PlayerInTurn); panelsBot2.GetComponent <PanelPlayerController>().Change(PlayerInTurn); panelsBot3.GetComponent <PanelPlayerController>().Change(PlayerInTurn); if (PlayerInTurn == 1) { msg.text = "Coloque una ficha"; int countTiletoPut = 0; for (int i = 0; i < fichasPlayerList.Count; i++) { TileBots ficha = fichasPlayerList[i].GetComponent <TileBots>(); if (!ficha.onTable) { if (ficha.pointDown == countLeft || ficha.pointDown == countRight || ficha.pointUp == countLeft || ficha.pointUp == countRight) { GameObject childTile = fichasPlayerList[i].transform.GetChild(0).gameObject; childTile.GetComponent <SpriteRenderer>().sprite = fichasPlayerList[i].GetComponent <TileBots>().backsTile[1]; countTiletoPut++; } else { fichasPlayerList[i].GetComponent <SpriteRenderer>().sprite = ficha.backsTile[0]; } } } if (countTiletoPut == 0) { msg.text = "No tienes fichas para jugar"; tocToc.Play(); countPase++; ValidateEnd(); Invoke(nameof(ChangeTurn), 2); } } else { msg.text = "Espere su turno"; Invoke(nameof(PlayBots), 2); } }
public void FindTile(List <GameObject> fichasList) { GameObject tileOut = null; int max = 0; for (int i = 0; i < fichasList.Count; i++) { TileBots ficha = fichasList[i].GetComponent <TileBots>(); if (ficha.countpoints >= max) { tileOut = fichasList[i]; max = ficha.countpoints; } } StartCoroutine(tileOut.GetComponent <TileBots>().StartMov()); }
public IEnumerator Move(GameObject ficha, int a, float mov) { TileBots tile = ficha.GetComponent <TileBots>(); if (a == 180) { tile.inverse = true; } tile.onTable = true; classMatch.countPase = 0; ficha.transform.SetParent(classMatch.table.transform); ficha.transform.localScale = new Vector3(0.7f, 0.7f, 1); var angles = ficha.transform.rotation.eulerAngles; angles.y = a; angles.x = 90; ficha.transform.rotation = Quaternion.Euler(angles); pos = new Vector3(transform.position.x, transform.position.y, transform.position.z + mov); if (colliderWall1 && nocollider == false || colliderWall2 && nocollider == false) { tile.nocollider = true; tile.moved = true; if (colliderWall1) { tile.colliderWall1 = true; } if (colliderWall2) { tile.colliderWall2 = true; } MovedTile(ficha); yield break; } if (moved) { if (colliderWall1) { tile.colliderWall1 = true; } if (colliderWall2) { tile.colliderWall2 = true; } tile.nocollider = true; if (tile.doble) { tile.movedDoble = true; } StartCoroutine(TurnTile(ficha, a)); yield break; } if (movedDoble) { if (colliderWall1) { tile.colliderWall1 = true; } if (colliderWall2) { tile.colliderWall2 = true; } tile.nocollider = true; StartCoroutine(MoveDoble(ficha, a));; yield break; } float normalizedTime = 0.0f; classMatch.putTile.Play(); while (normalizedTime < 1) { ficha.transform.position = Vector3.Lerp(ficha.transform.position, pos, normalizedTime); normalizedTime += Time.deltaTime / duration; yield return(null); } ficha.transform.position = pos; if (classMatch.PlayerInTurn == 1) { classMatch.ChangeTilesToNormal(); } yield return(new WaitForSeconds(1f)); classMatch.noPlay = false; MatchDates.Instance.selectedFicha = null; classMatch.ValidateEnd(); classMatch.ChangeTurn(); }
public void MovNexTile(GameObject nextTile) { TileBots tile = nextTile.GetComponent <TileBots>(); if (transform.gameObject == classMatch.firstTile) { if (!closedUp && pointUp == tile.pointDown) { closedUp = true; tile.closedDown = true; classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; if (tile.doble && !doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } if (!tile.doble && !doble) { StartCoroutine(Move(nextTile, 0, 1.9f)); } if (!tile.doble && doble) { StartCoroutine(Move(nextTile, 0, 1.45f)); } return; } if (!closedUp && pointUp == tile.pointUp) { closedUp = true; tile.closedUp = true; classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; if (tile.doble && !doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } if (!tile.doble && !doble) { StartCoroutine(Move(nextTile, 180, 1.9f)); } if (!tile.doble && doble) { StartCoroutine(Move(nextTile, 180, 1.45f)); } return; } if (!closedDown && pointDown == tile.pointUp) { closedDown = true; tile.closedUp = true; classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; if (tile.doble && !doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } if (!tile.doble && !doble) { StartCoroutine(Move(nextTile, 0, -1.9f)); } if (!tile.doble && doble) { StartCoroutine(Move(nextTile, 0, -1.45f)); } return; } if (!closedDown && pointDown == tile.pointDown) { closedDown = true; tile.closedDown = true; classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; if (tile.doble && !doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } if (!tile.doble && !doble) { StartCoroutine(Move(nextTile, 180, -1.9f)); } if (!tile.doble && doble) { StartCoroutine(Move(nextTile, 180, -1.45f)); } } } else { if (!closedUp && !inverse && !doble && pointUp == tile.pointDown) { closedUp = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } else { StartCoroutine(Move(nextTile, 0, 1.9f)); } return; } if (!closedDown && inverse && !doble && pointDown == tile.pointDown) { closedDown = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } else { StartCoroutine(Move(nextTile, 0, 1.9f)); } return; } if (!closedDown && !inverse && !doble && pointDown == tile.pointUp) { closedDown = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } else { StartCoroutine(Move(nextTile, 0, -1.9f)); } return; } if (!closedUp && inverse && !doble && pointUp == tile.pointUp) { closedUp = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } else { StartCoroutine(Move(nextTile, 0, -1.9f)); } return; } if (!closedUp && !inverse && !doble && pointUp == tile.pointUp) { closedUp = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } else { StartCoroutine(Move(nextTile, 180, 1.9f)); } return; } if (!closedDown && inverse && !doble && pointDown == tile.pointUp) { closedDown = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, 1.45f)); } else { StartCoroutine(Move(nextTile, 180, 1.9f)); } return; } if (!closedDown && !inverse && !doble && pointDown == tile.pointDown) { closedDown = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } else { StartCoroutine(Move(nextTile, 180, -1.9f)); } return; } if (!closedUp && inverse && !doble && pointUp == tile.pointDown) { closedUp = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } if (tile.doble) { StartCoroutine(Move(nextTile, 90, -1.45f)); } else { StartCoroutine(Move(nextTile, 180, -1.9f)); } return; } if (!closedUp && doble && pointUp == tile.pointDown) { closedUp = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } StartCoroutine(Move(nextTile, 0, 1.45f)); return; } if (!closedDown && doble && pointDown == tile.pointUp) { closedDown = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } StartCoroutine(Move(nextTile, 0, -1.45f)); return; } if (!closedUp && doble && pointUp == tile.pointUp) { closedUp = true; tile.closedUp = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointDown; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointDown; } StartCoroutine(Move(nextTile, 180, 1.45f)); return; } if (!closedDown && doble && pointDown == tile.pointDown) { closedDown = true; tile.closedDown = true; if (classMatch.tileLeft == transform.gameObject) { classMatch.countLeft = tile.pointUp; classMatch.tileLeft = nextTile; } else { classMatch.tileRight = nextTile; classMatch.countRight = tile.pointUp; } StartCoroutine(Move(nextTile, 180, -1.45f)); } } }
private void OnMouseUpAsButton() { if (!onTable && classMatch.PlayerInTurn == 1 && !classMatch.noPlay && !classMatch.pause) { if (classMatch.startPlayer) { classMatch.noPlay = true; classMatch.startPlayer = false; StartCoroutine(StartMov()); } else { GameObject childTileRight = classMatch.tileRight.transform.GetChild(0).gameObject; childTileRight.GetComponent <SpriteRenderer>().sprite = classMatch.tileRight.GetComponent <TileBots>().backsTile[0]; GameObject childTileLeft = classMatch.tileLeft.transform.GetChild(0).gameObject; childTileLeft.GetComponent <SpriteRenderer>().sprite = classMatch.tileLeft.GetComponent <TileBots>().backsTile[0]; bool left = false; bool right = false; if (pointDown == classMatch.countLeft || pointUp == classMatch.countLeft) { GameObject tileLeft = classMatch.tileLeft.transform.GetChild(0).gameObject; tileLeft.GetComponent <SpriteRenderer>().sprite = classMatch.tileLeft.GetComponent <TileBots>().backsTile[1]; left = true; } if (pointDown == classMatch.countRight || pointUp == classMatch.countRight) { GameObject tileRight = classMatch.tileRight.transform.GetChild(0).gameObject; tileRight.GetComponent <SpriteRenderer>().sprite = classMatch.tileRight.GetComponent <TileBots>().backsTile[1]; right = true; } if (!right && left || right && !left) { classMatch.noPlay = true; classMatch.countTilesPlayer--; classMatch.capicua = false; GameObject childTileRight1 = classMatch.tileRight.transform.GetChild(0).gameObject; childTileRight1.GetComponent <SpriteRenderer>().sprite = classMatch.tileRight.GetComponent <TileBots>().backsTile[0]; GameObject childTileLeft2 = classMatch.tileLeft.transform.GetChild(0).gameObject; childTileLeft2.GetComponent <SpriteRenderer>().sprite = classMatch.tileLeft.GetComponent <TileBots>().backsTile[0]; MatchDates.Instance.selectedFicha = transform.gameObject; if (left) { classMatch.tileLeft.GetComponent <TileBots>().MovNexTile(transform.gameObject); } else { classMatch.tileRight.GetComponent <TileBots>().MovNexTile(transform.gameObject); } } if (classMatch.countLeft == classMatch.countRight && left && right && classMatch.tileLeft != classMatch.tileRight) { classMatch.noPlay = true; classMatch.countTilesPlayer--; classMatch.capicua = false; GameObject childTileRight1 = classMatch.tileRight.transform.GetChild(0).gameObject; childTileRight1.GetComponent <SpriteRenderer>().sprite = classMatch.tileRight.GetComponent <TileBots>().backsTile[0]; GameObject childTileLeft2 = classMatch.tileLeft.transform.GetChild(0).gameObject; childTileLeft2.GetComponent <SpriteRenderer>().sprite = classMatch.tileLeft.GetComponent <TileBots>().backsTile[0]; MatchDates.Instance.selectedFicha = transform.gameObject; classMatch.tileRight.GetComponent <TileBots>().MovNexTile(transform.gameObject); } if (left || right) { if (classMatch.tileLeft == classMatch.tileRight) { classMatch.noPlay = true; classMatch.countTilesPlayer--; classMatch.capicua = false; GameObject childFirstTile = classMatch.firstTile.transform.GetChild(0).gameObject; childFirstTile.GetComponent <SpriteRenderer>().sprite = classMatch.firstTile.GetComponent <TileBots>().backsTile[0]; MatchDates.Instance.selectedFicha = transform.gameObject; classMatch.firstTile.GetComponent <TileBots>().MovNexTile(transform.gameObject); } } if (MatchDates.Instance.selectedFicha == null && left && right) { MatchDates.Instance.selectedFicha = transform.gameObject; } } } else if (onTable && classMatch.PlayerInTurn == 1 && MatchDates.Instance.selectedFicha != null) { if (transform.gameObject == classMatch.tileLeft || transform.gameObject == classMatch.tileRight) { classMatch.putTile.Play(); classMatch.noPlay = true; GameObject childTileRight = classMatch.tileRight.transform.GetChild(0).gameObject; childTileRight.GetComponent <SpriteRenderer>().sprite = classMatch.tileRight.GetComponent <TileBots>().backsTile[0]; GameObject childTileLeft = classMatch.tileLeft.transform.GetChild(0).gameObject; childTileLeft.GetComponent <SpriteRenderer>().sprite = classMatch.tileLeft.GetComponent <TileBots>().backsTile[0]; TileBots selectedFicha = MatchDates.Instance.selectedFicha.GetComponent <TileBots>(); classMatch.capicua = false; if (selectedFicha.pointDown == classMatch.countLeft && selectedFicha.pointUp == classMatch.countRight || selectedFicha.pointDown == classMatch.countRight && selectedFicha.pointUp == classMatch.countLeft) { classMatch.capicua = true; } classMatch.countTilesPlayer--; MovNexTile(MatchDates.Instance.selectedFicha); } } }