protected void GiveMine(string code, Player player) { int level = Int32.Parse(code[0].ToString()) - 1; int number = Int32.Parse(code[1].ToString()) - 1; Mine chosenMine = MinesOnBoard[level][number]; if (chosenMine.Prices["w"] <= player.CountResources("w") && chosenMine.Prices["b"] <= player.CountResources("b") && chosenMine.Prices["g"] <= player.CountResources("g") && chosenMine.Prices["r"] <= player.CountResources("r") && chosenMine.Prices["k"] <= player.CountResources("k")) { if (MinesOnBoard[level].Remove(chosenMine)) { Dictionary <string, int> coinsToRemove = new Dictionary <string, int>(); coinsToRemove.Add("w", chosenMine.Prices["w"] - player.CountMines("w")); coinsToRemove.Add("b", chosenMine.Prices["b"] - player.CountMines("b")); coinsToRemove.Add("g", chosenMine.Prices["g"] - player.CountMines("g")); coinsToRemove.Add("r", chosenMine.Prices["r"] - player.CountMines("r")); coinsToRemove.Add("k", chosenMine.Prices["k"] - player.CountMines("k")); List <Coin> removedCoins = player.RemoveCoins(coinsToRemove); CoinsOnBoard.AddRange(removedCoins); player.AddMine(chosenMine); } } }
protected void PopulateCoins() { for (int i = 0; i < 8; i++) { CoinsOnBoard.Add(new Coin("b")); CoinsOnBoard.Add(new Coin("g")); CoinsOnBoard.Add(new Coin("k")); CoinsOnBoard.Add(new Coin("r")); CoinsOnBoard.Add(new Coin("w")); } for (int i = 0; i < 5; i++) { CoinsOnBoard.Add(new Coin("gold")); } }
protected bool GiveCoins(string[] codes, Player player) { bool result = true; foreach (var code in codes) { Coin coin = CoinsOnBoard.FirstOrDefault(c => c.Color == code); if (CoinsOnBoard.Remove(coin) && coin != null) { player.AddCoin(coin); } else if (coin == null) { result = false; } } return(result); }