/// <summary> /// Increases the trade count for a player, starts an animation for the button /// Gets new letters and replaces the old letters /// </summary> /// <param name="timesTraded"></param> private void TradeLetters(int timesTraded) { if (GameInstance.instance.IsMultiplayer) { Hashtable hash = new Hashtable { { "TimesTraded", ++timesTraded } }; PhotonNetwork.LocalPlayer.SetCustomProperties(hash); } else { Player.TimesTraded++; } RemoveAllLetters(); var buttonImage = TradeBtn.GetComponentsInChildren <RectTransform>().Where(img => img.name == "TradeBtnImg").ToList()[0]; StartCoroutine(RotateTradeButton(buttonImage, 1)); List <LetterPosition> letterPositions = GetPlayerLetters(); char[] newLetters = TheLetterManager.GetLetters(letterPositions.Count()); for (int i = 0; i < letterPositions.Count; i++) { LetterPosition letterPos = letterPositions[i]; if (!letterPos.LetterBlock.IsFirstLetter && !letterPos.LetterBlock.IsSecondLetter) { letterPos.LetterBlock.GetComponentInChildren <Text>().text = newLetters[i].ToString().ToUpper(); } } }
/// <summary> /// Gets called when the trade button is touched /// First there is a check to see if the player can move /// Then the points will be deducted if it is not the first trade /// </summary> private void TradeLetterBtnTouch() { int timesTraded; if (GameInstance.instance.IsMultiplayer) { if (PhotonNetwork.LocalPlayer.CustomProperties["TimesTraded"] != null) { timesTraded = (int)PhotonNetwork.LocalPlayer.CustomProperties["TimesTraded"]; } else { timesTraded = 0; } } else { timesTraded = Player.TimesTraded; } switch (timesTraded) { case 0: TradeLetters(timesTraded); TradeBtn.GetComponentInChildren <Text>().text = I2.Loc.LocalizationManager.GetTranslation("10_points"); break; case 1: if (Player.EarnedPoints < 10) { Player.InfoText = I2.Loc.LocalizationManager.GetTranslation("trade_10_points"); } else { TradeLetters(timesTraded); TradeBtn.GetComponentInChildren <Text>().text = I2.Loc.LocalizationManager.GetTranslation("20_points"); Player.EarnedPoints -= 10; } break; case 2: if (Player.EarnedPoints < 20) { Player.InfoText = I2.Loc.LocalizationManager.GetTranslation("trade_20_points"); } else { var subtractColor = new Color(0, 0, 0, 0.5f); TradeLetters(timesTraded); Button trade = TradeBtn.GetComponent <Button>(); trade.image.color -= subtractColor; TradeBtn.GetComponentInChildren <Text>().color -= subtractColor; TradeBtn.GetComponentInChildren <Image>().color -= subtractColor; Player.EarnedPoints -= 20; } break; default: Player.InfoText = I2.Loc.LocalizationManager.GetTranslation("trade_used_all"); break; } }