private void UpdateGame(UseableItem playerChoice) { UpdateGameLoader updateGameLoader = new UpdateGameLoader(playerChoice); updateGameLoader.OnLoaded += OnGameUpdated; updateGameLoader.Load(); }
public void RefteshItem() { UseableItem item = Player.instance.GetItem(); if (item != null) { itemText.text = item.itemName; itemSlot.sprite = null; if (item.isActive == true) { itemAnimator.runtimeAnimatorController = item.uiAnimator; } else { itemAnimator.runtimeAnimatorController = null; } if (item.icon != null) { itemSlot.sprite = item.icon; } SetImage(itemSlot); } else { itemAnimator.runtimeAnimatorController = null; itemSlot.sprite = null; itemText.text = ""; SetImage(itemSlot); } RefreshItemSlider(null, null); }
public void HandlePlayerInput(int item) { // To play you need to bet if (_bet == 0) { _resultLabel.text = "Make a bet to play!"; return; } UseableItem playerChoice = UseableItem.None; switch (item) { case 1: playerChoice = UseableItem.Rock; break; case 2: playerChoice = UseableItem.Paper; break; case 3: playerChoice = UseableItem.Scissors; break; } UpdateGame(playerChoice); }
private void UpdateGame(UseableItem playerChoice, UseableItem opponentChoice, int bet) { UpdateGameLoader updateGameLoader = new UpdateGameLoader(playerChoice, opponentChoice, bet); updateGameLoader.OnLoaded += OnGameUpdated; updateGameLoader.load(); }
private void UpdateGame(UseableItem playerChoice) { // Restore the game to its initial state _resultLabel.text = "Make your Bet!!"; _playerHand.text = string.Empty; _enemyHand.text = string.Empty; _updateGameLoader.Load(playerChoice, _bet); }
public void AddChargeToItem(int charge) { UseableItem item = GetItem(); if (item != null) { item.charge += charge; } RefreshItem(); }
public void load() { UseableItem opponentHand = (UseableItem)Enum.GetValues(typeof(UseableItem)).GetValue(UnityEngine.Random.Range(0, 4)); Hashtable mockGameUpdate = new Hashtable(); mockGameUpdate["resultPlayer"] = _choice; mockGameUpdate["resultOpponent"] = opponentHand; mockGameUpdate["coinsAmountChange"] = GetCoinsAmount(_choice, opponentHand); OnLoaded(mockGameUpdate); }
public void Load() { UseableItem opponentHand = (UseableItem)Enum.GetValues(typeof(UseableItem)).GetValue(UnityEngine.Random.Range(1, 4)); Hashtable mockGameUpdate = new Hashtable(); mockGameUpdate[GameConstants.resultPlayer] = _choice; mockGameUpdate[GameConstants.resultOpponent] = opponentHand; //mockGameUpdate[GameConstants.coinsAmountChange] = GetCoinsAmount(_choice, opponentHand); mockGameUpdate[GameConstants.gameResult] = ResultAnalyzer.GetResultState(_choice, opponentHand); OnLoaded(mockGameUpdate); }
public void RefreshItemSlider(object sender, EventArgs e) { UseableItem item = Player.instance.GetItem(); if (item != null) { itemSlider.maxValue = item.chargeMax; itemSlider.value = item.charge; } else { itemSlider.maxValue = 1; itemSlider.value = 0; } }
public static Result GetResultState(UseableItem playerHand, UseableItem enemyHand) { if (isStronger(playerHand, enemyHand)) { return(Result.Won); } else if (isStronger(enemyHand, playerHand)) { return(Result.Lost); } else { return(Result.Draw); } }
public void UseItem() { if (items[itemIndex] != null) { items[itemIndex].GetComponent <UseableItem>().Use(); UseableItem item = GetItem(); if (item != null) { if (item.isActive) { actionBar.GetItemUpdates(item); } } } }
private string DisplayResultAsText(UseableItem result) { switch (result) { case UseableItem.Rock: return("Rock"); case UseableItem.Paper: return("Paper"); case UseableItem.Scissors: return("Scissors"); } return("Nothing"); }
private int GetCoinsAmount(UseableItem playerHand, UseableItem opponentHand) { Result drawResult = ResultAnalyzer.GetResultState(playerHand, opponentHand); if (drawResult.Equals(Result.Won)) { return(10); } else if (drawResult.Equals(Result.Lost)) { return(-10); } else { return(0); } }
private static bool isStronger(UseableItem firstHand, UseableItem secondHand) { switch (firstHand) { case UseableItem.Rock: { switch (secondHand) { case UseableItem.Scissors: return(true); case UseableItem.Paper: return(false); } break; } case UseableItem.Paper: { switch (secondHand) { case UseableItem.Rock: return(true); case UseableItem.Scissors: return(false); } break; } case UseableItem.Scissors: { switch (secondHand) { case UseableItem.Paper: return(true); case UseableItem.Rock: return(false); } break; } } return(false); }
public void AddMove(UseableItem move) { _lastMove = move; switch (move) { case UseableItem.Rock: _rocks++; break; case UseableItem.Paper: _papers++; break; case UseableItem.Scissors: _scissors++; break; } }
public void UnUseItem(object sender, EventArgs e) { UseableItem item = (UseableItem)sender; if (item != null) { RefteshItem(); item.unUseItem -= UnUseItem; item.updateItem -= RefreshItemSlider; } else { itemAnimator.runtimeAnimatorController = null; itemSlot.sprite = null; SetImage(itemSlot); } }
public bool IsDoneAfterResult(Result r) { if (_stage == 0) { if (r == Result.Lose) { _favourite = (UseableItem)((AIFunctions.GetLastPlayerMove() + Constants.WINNING_OFFSET) % 3); _specialTauntReady = true; _specialTaunt = "I played " + _favourite + ". I won. It was the best win! No one thought I could do it. None of them played " + _favourite + ". Only Trump!"; _stage = 1; } } else { _stage += r == Result.Win ? 1 : 0; } return(_stage > 9); }
public void Load(UseableItem playerChoice, int bet) { ///FIX - Because the first option from the <see cref="UseableItem"/> is none the random range should be from 1 to 4. Not starting from 0 UseableItem opponentHand = (UseableItem)Enum.GetValues(typeof(UseableItem)).GetValue(UnityEngine.Random.Range(1, 4)); // I replace the strings with the constants. Hashtable mockGameUpdate = new Hashtable(); mockGameUpdate[GAME_DATA_KEY_PLAYER_RESULT] = playerChoice; mockGameUpdate[GAME_DATA_KEY_OPPONENT_RESULT] = opponentHand; Result drawResult = ResultAnalyzer.GetResultState(playerChoice, opponentHand); mockGameUpdate[GAME_DATA_KEY_COINS_AMOUNT_CHANGE] = GetCoinsAmount(drawResult, bet); // Add a result entry to the Hashtable mockGameUpdate[GAME_DATA_KEY_RESULT] = drawResult.ToString(); OnLoaded(mockGameUpdate); }
// its a good behaviour to have only one return in a function private int GetCoinsAmount(UseableItem playerHand, UseableItem opponentHand) { Result drawResult = ResultAnalyzer.GetResultState(playerHand, opponentHand); int amountToReturn = 0; if (drawResult.Equals(Result.Won)) { amountToReturn = 10; } else if (drawResult.Equals(Result.Lost)) { amountToReturn = -10; } else { amountToReturn = 0; } return(amountToReturn); }
public void HandlePlayerInput(int item) { UseableItem playerChoice = UseableItem.Rock; switch (item) { case 0: playerChoice = UseableItem.Rock; break; case 1: playerChoice = UseableItem.Paper; break; case 2: playerChoice = UseableItem.Scissors; break; } UpdateGame(playerChoice, _opponentManager.GetHand(), _betController.GetBet()); }
public void HandlePlayerInput(int item) { UseableItem playerChoice = UseableItem.None; switch (item) { case 1: playerChoice = UseableItem.Rock; break; case 2: playerChoice = UseableItem.Paper; break; case 3: playerChoice = UseableItem.Scissors; break; } UpdateGame(playerChoice); }
private GameUpdate HandleDraw(UseableItem playerHand, UseableItem _opponentChoice) { GameUpdate gameUpdate = new GameUpdate(); gameUpdate.resultPlayer = _playerChoice; gameUpdate.resultOpponent = _opponentChoice; gameUpdate.drawResult = ResultAnalyzer.GetResultState(playerHand, _opponentChoice); if (gameUpdate.drawResult.Equals(Result.Win)) { gameUpdate.coinsAmountChange = SessionData.Instance.GetMoney() + _bet < Constants.MAX_MONEY ? _bet : Constants.MAX_MONEY - SessionData.Instance.GetMoney(); } else if (gameUpdate.drawResult.Equals(Result.Lose)) { gameUpdate.coinsAmountChange = SessionData.Instance.GetMoney() - _bet > -Constants.MAX_MONEY ? -_bet : -Constants.MAX_MONEY - SessionData.Instance.GetMoney(); } else { gameUpdate.coinsAmountChange = 0; } return(gameUpdate); }
public void GetItemUpdates(UseableItem item) { item.updateItem += RefreshItemSlider; item.unUseItem += UnUseItem; itemAnimator.runtimeAnimatorController = item.uiAnimator; }
public UpdateGameLoader(UseableItem playerChoice) { _choice = playerChoice; }
public UpdateGameLoader(UseableItem playerChoice, UseableItem opponentChoice, int playerBet) { _playerChoice = playerChoice; _opponentChoice = opponentChoice; _bet = playerBet; }
public void Attack() { if (Time.time >= attackCoolDown) { //Detect hittables in range Collider[] gotHit = Physics.OverlapSphere(attackPoint.position, attackRange, hittableLayers); //Apply damage to each hit object foreach (Collider hit in gotHit) { Resource hitResource = hit.GetComponent <Resource>(); TreeScript hitTree = hit.GetComponent <TreeScript>(); BuildingGhost buildingGhost = hit.GetComponent <BuildingGhost>(); Animal animal = hit.GetComponent <Animal>(); UseableItem item = hit.GetComponent <UseableItem>(); FarmPlot farmPlot = hit.GetComponent <FarmPlot>(); Plant plant = hit.GetComponent <Plant>(); //Getting resources if (hitResource) { hitResource.health -= attackDamage; audioManager.PlaySound("Hit Marker"); } //Tree chopping if (hitTree) { hitTree.ChopTree(attackDamage); audioManager.PlaySound("Hit Marker"); } //Building ghosts if (buildingGhost) { if (buildingGhost.requiredResource == "Wood") { if (GameController.Instance.resourceController.wood >= 1) { buildingGhost.AddResources(1); } } if (buildingGhost.requiredResource == "Stone") { if (GameController.Instance.resourceController.stone >= 1) { buildingGhost.AddResources(1); } } } //Hit animal if (animal) { animal.TakeDamage(attackDamage, this.transform); audioManager.PlaySound("Smack"); //Debug.Log("Dealt " + damage + " dmg to " + hit.transform.name); } //Pickup item if (item) { if (itemInHand == null) { item.pickedUp = true; itemInHand = hit.transform; audioManager.PlaySound("Item Pickup"); } } //Farming if (farmPlot) { farmPlot.PlantSeed(); } if (plant) { plant.Harvest(); } } attackCoolDown = Time.time + (1.0f / attackSpeed); } }