public void onPlayerLandsOnOwnedSquare(object obj, LandArgs args) { var square = (BoardSquare)obj; var player = args.Player; if (player == this) { Console.WriteLine("Player {0} enjoyed their time on {1}", player.PlayerType.ToString(), square.Name); } else { var playerMoney = player.GetPlayerMoney(); var rentCost = GetOwnedSquareRent(square.Name); if (playerMoney >= rentCost) { Console.WriteLine("Player {0} is paying {1} rent to Owner {2}", player.PlayerType.ToString(), rentCost, this.PlayerType.ToString()); player.TakeFromPlayer(rentCost); PayToPlayer(rentCost); } else { Console.WriteLine("Player {0} cannot afford to pay rent to Owner {1}", player.PlayerType.ToString(), this.PlayerType.ToString()); } } }
private void OnPlayerLandsOnRegularSquare(object obj, LandArgs args) { //obj should always be a board square var square = (BoardSquare)obj; Console.WriteLine("Player {0} relaxes on {1}", args.Player.PlayerType.ToString(), square.Name); }
private void OnPlayerLandsOnGoToJailSquare(object obj, LandArgs args) { var jailPosition = _board.GetJailPosition(); var player = args.Player; Console.WriteLine("Player {0} has gone to jail. Player {0} has gone directly to jail. Has not passed go or collected 200", player.PlayerType.ToString()); player.SetPlayerPosition(jailPosition); player.SetJailTerm(2); }
private void OnPlayerLandsOnTaxSquare(object obj, LandArgs args) { var square = (TaxSquare)obj; var player = args.Player; var tax = square.TaxValue; Console.WriteLine("Player {0} has payed {1} in tax", player.PlayerType.ToString(), tax); player.TakeFromPlayer(tax); }
private void OnPlayerLandsOnCommunityChestSquare(object obj, LandArgs args) { var player = args.Player; Console.WriteLine("Player {0} has drawn a Community Chest card", player.PlayerType.ToString()); var rnd = new Random(); var index = rnd.Next(_communityChestCards.Count); var card = _chanceCards[index]; card.PlayerDrawsCard(this, player); }
private void OnPlayerLandsOnBuyableSquare(object obj, LandArgs args) { var square = (BoardSquare)obj; var deed = _deeds[square.Name]; var player = args.Player; var playerMoney = player.GetPlayerMoney(); if (playerMoney >= deed.Cost) { Console.WriteLine("Player {0} is buying {1}", player.PlayerType.ToString(), square.Name); player.TakeFromPlayer(deed.Cost); player.AddDeed(deed); _deeds.Remove(square.Name); //set new event handler here for purchased squares square.SetEventHandler(player.onPlayerLandsOnOwnedSquare); } else { Console.WriteLine("Player {0} cannot afford {1}", player.PlayerType.ToString(), square.Name); } }