// This is ran whenever the user clicks the box public void DoClick() { // We check to see if the player has chosen their box yet if (boxContainer.playerBox == null) { boxContainer.playerBox = this.gameObject; // We give the player this box boxContainer.boxValues.Remove(boxContainer.boxValuesCache[boxNumber]); // We remove the player box from the game GetComponent <Button>().interactable = false; // We make it so the player can't click this box transform.position = new Vector2(-2.85f, -1.3f); // We move the box boxContainer.EndRound(); // We tell the player how many boxes they can choose bankerScript.bankerText.text = "Please choose " + boxContainer.boxesToChoose + " boxes"; } else if (boxContainer.boxesToChoose > 0 && boxContainer.playerBox != this.gameObject) { RevealBox(); // We open the box boxContainer.boxesToChoose -= 1; // We tell the player they can choose one fewer box boxContainer.boxValues.Remove(boxContainer.boxValuesCache[boxNumber]); // We remove the current box from the game GetComponent <Button>().interactable = false; // We make it so the player can't click this box anymore GameObject[] sidePanelValues = GameObject.FindGameObjectsWithTag("panel value"); // We find all side panel values // This checks through all side panel values for (int i = 0; i < sidePanelValues.Length; i += 1) { // We check if the current side panel is equal to the box which was just removed if (sidePanelValues[i].name == "" + boxContainer.boxValuesCache[boxNumber]) { Destroy(sidePanelValues[i]); // We remove the value from the side of the screen } } // We check if the player can choose no more boxes if (boxContainer.boxesToChoose == 0) { bankerScript.MakeOffer(); // We tell the banker to make an offer dondPanel.transform.localScale = new Vector2(1.0f, 1.0f); // Make the deal or no deal panel visible } else { // We tell the player how many boxes they can choose bankerScript.bankerText.text = "Please choose " + boxContainer.boxesToChoose + " boxes"; } } }
// This is when the player clicks the No Deal button public void DoNoDeal() { // We check if the player has been offered a box swap if (isBoxSwap) { GameObject[] remainingBoxes = GameObject.FindGameObjectsWithTag("box"); // This is an array with all boxes // We loop through every box, even the ones which have already been removed for (int i = 0; i < remainingBoxes.Length; i += 1) { // We search for the last box if (remainingBoxes[i].GetComponent <Button>().interactable&& remainingBoxes[i] != boxContainer.playerBox) { // We open both boxes remainingBoxes[i].GetComponent <box>().RevealBox(); boxContainer.playerBox.GetComponent <box>().RevealBox(); // We tell the player what they have won bankerText.text = "Congratulations!\n You win: £" + boxContainer.boxValuesCache[boxContainer.playerBox.GetComponent <box>().boxNumber]; dondPanel.transform.localScale = new Vector2(0.0f, 0.0f); // We hide the deal or no deal panel } } } else { // We check if we are on the last round if (boxContainer.currentRound + 1 == boxContainer.rounds.Length) { bankerText.text = "I would like to offer you a box swap\nDeal or No Deal?"; // Offer the player a box swap isBoxSwap = true; } else { dondPanel.transform.localScale = new Vector2(0.0f, 0.0f); // We hide the deal or no deal panel boxContainer.EndRound(); // We end the round if it isn't the last // We tell the player how many boxes they can choose bankerText.text = "Please choose " + boxContainer.boxesToChoose + " boxes"; } } }