IEnumerator Wait() { yield return(new WaitForSeconds(3f)); int startGame = gameManager.GetPlayerStartGame(gameManager.dices[0].diceCount, gameManager.dices[1].diceCount); if (GameManger.PlayerTurn == null) { switch (startGame) { case 0: startGame = -1; TextToShow = "תיקו! הגרל קובייה מחדש"; RollBtn.gameObject.SetActive(true); break; case 1: startGame = -1; GameManger.PlayerTurn = "Black"; TextToShow = "שחקן 1 - שחור מתחיל את המשחק, הגרל קוביה"; foreach (Dice d in gameManager.dices) { d.isDiceLand = true; } RollBtn.gameObject.SetActive(false); break; case 2: startGame = -1; GameManger.PlayerTurn = "White"; TextToShow = "שחקן 2 - לבן מתחיל את המשחק, הגרל קובייה"; foreach (Dice d in gameManager.dices) { d.isDiceLand = true; } RollBtn.gameObject.SetActive(false); break; } Instruction.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = TextToShow; LeanTween.moveY(Instruction.gameObject, 900f, 1f); foreach (GameObject text in gameManager.textBlackWhite) { text.SetActive(true); } } ShowVisibleDiceUI(); if (GameManger.PlayerTurn != null) { if (gameManager.IsBothDicesLandAndRoll()) { if (!gameManager.SumMovements.IsPlayerDidAllSteps()) { // after rolling check if there is an option to move a stone, while we don't have anything onPlayerTrapped Array. if (gameManager.CantMove()) { if (!gameManager.isAllPlayersCanRemoved(gameManager.BoardGame, GameManger.PlayerTurn)) { gameManager.ShowErrorPassTurn("אין ביכולתך להזיז אבנים לפי הקוביות הנתונות ולכן התור עובר ליריב"); } else { int[] indexDices = { 0, 0, 0, 0 }; int index = 0; foreach (int diceCount in gameManager.dicesCount) { if (diceCount > 0) { indexDices[index] = gameManager.GetIndexCountOnRemovingStones(GameManger.PlayerTurn, index); if (gameManager.BoardGame[indexDices[index]].Count > 0) { if (gameManager.BoardGame[indexDices[index]].Peek().PlayerType == GameManger.PlayerTurn) { gameManager.ShowMessagePassTurn = false; break; } else { gameManager.TakeCareOnNotOnStackAsDice(indexDice, OnSelected.SelectedPlayer.PlayerType, OnSelected.SelectedPlayer); if (gameManager.RectanglesShowTakeOut[0].activeInHierarchy || gameManager.RectanglesShowTakeOut[1].activeInHierarchy) { break; } } } else { gameManager.TakeCareOnNotOnStackAsDice(indexDice, OnSelected.SelectedPlayer.PlayerType, OnSelected.SelectedPlayer); if (gameManager.RectanglesShowTakeOut[0].activeInHierarchy || gameManager.RectanglesShowTakeOut[1].activeInHierarchy) { break; } } } index++; } if (gameManager.ShowMessagePassTurn) { gameManager.ShowErrorPassTurn("אין ביכולתך להזיז אף אבן ולכן התור עובר ליריב"); } } } } } } }
//This function is responsible for removing stones public void PlayerRemoveStones() { currentList = (PlayerType == "Black") ? gameManager.onPlayerBlack : gameManager.onPlayerWhite; int IndexCheck = 0; if (PlayerType == GameManger.PlayerTurn) { // check if stones be removed from board if (gameManager.isAllPlayersCanRemoved(gameManager.BoardGame, GameManger.PlayerTurn) && currentList.Count == 0) { // can't use foreach , beacuse break doesn't work there. for (int i = 0; i < gameManager.dicesCount.Length; i++) { if (gameManager.dicesCount[i] >= 1) // if pass turn happen - then all dices will reset and we will get an error whie trying to do gameManager.dices[i].diceCount - 1; // if you didn't did this dice yet { if (!gameManager.DoneMove[i]) { IndexCheck = gameManager.GetIndexCountOnRemovingStones(GameManger.PlayerTurn, i); // update IndexCheck of triangle for checking an optional move to remove stone at this location // if the stack according dice has one stone at least. if so, if TriangleIndex selected is equal to dice or 24-dice+ 1 then show option for removing if (gameManager.BoardGame[IndexCheck].Count > 0) { if (gameManager.BoardGame[IndexCheck].Peek().PlayerType == PlayerType) { // if you have at least one stone on the stack of countDice from playerType if (indexTriangle == gameManager.dicesCount[i] || GameManger.BOARD_TRIANGLES - indexTriangle + 1 == gameManager.dicesCount[i]) { if ((!gameManager.DoneMove[i] && !gameManager.SumMovements.IsDouble) || gameManager.SumMovements.IsDouble) { indexDiceToRemove = i; if (gameManager.DoneMove[i]) { if (i == 1) { indexDiceToRemove = 0; } else { indexDiceToRemove = 1; } } gameManager.ToggleHideShowRectangle(true); break; } } else { indexDiceToRemove = -1; gameManager.ToggleHideShowRectangle(false); } } else { gameManager.TakeCareOnNotOnStackAsDice(i, PlayerType, this); if (gameManager.RectanglesShowTakeOut[0].activeInHierarchy || gameManager.RectanglesShowTakeOut[1].activeInHierarchy) { break; } } } // if we don't have anything from 6 to diceIndex than have to take from the last stack that exist else { gameManager.TakeCareOnNotOnStackAsDice(i, PlayerType, this); if (gameManager.RectanglesShowTakeOut[0].activeInHierarchy || gameManager.RectanglesShowTakeOut[1].activeInHierarchy) { break; } } } } } } } }