public void PurchaseProperty(Player player, bool?testAnswer = null) { if (player.IsInJail) { Console.WriteLine("You are in Jail and can not purchase property."); } //if property available give option to purchase else so not available else if (Board.Access().GetProperty(player.GetLocation()).AvailableForPurchase()) { TradeableProperty propertyLocatedOn = (TradeableProperty)Board.Access().GetProperty(player.GetLocation()); bool?respYN = testAnswer ?? GetInputYn(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.GetName(), propertyLocatedOn.GetPrice())); if ((bool)respYN) { propertyLocatedOn.Purchase(ref player);//purchase property Console.WriteLine("{0}You have successfully purchased {1}.", PlayerPrompt(player), propertyLocatedOn.GetName()); } } else { Console.WriteLine("{0}{1} is not available for purchase.", PlayerPrompt(player), Board.Access().GetProperty(player.GetLocation()).GetName()); } }
public void PurchaseProperty(Player player, bool? testAnswer = null) { if (player.IsInJail) { Console.WriteLine("You are in Jail and can not purchase property."); } //if property available give option to purchase else so not available else if (Board.Access().GetProperty(player.GetLocation()).AvailableForPurchase()) { TradeableProperty propertyLocatedOn = (TradeableProperty)Board.Access().GetProperty(player.GetLocation()); bool? respYN = testAnswer ?? GetInputYn(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.GetName(), propertyLocatedOn.GetPrice())); if ((bool) respYN) { propertyLocatedOn.Purchase(ref player);//purchase property Console.WriteLine("{0}You have successfully purchased {1}.", PlayerPrompt(player), propertyLocatedOn.GetName()); } } else { Console.WriteLine("{0}{1} is not available for purchase.", PlayerPrompt(player), Board.Access().GetProperty(player.GetLocation()).GetName()); } }
public override void MakePlay(int iPlayerIndex) { while (true) { //make variable for player Player player = Board.Access().GetPlayer(iPlayerIndex); //Change the colour for the player Console.ForegroundColor = this._colors[iPlayerIndex]; //if inactive skip turn if (!player.IsActive()) { Console.WriteLine("\n{0} is inactive.\n", player.GetName()); //check players to continue //check that there are still two players to continue int activePlayerCount = 0; foreach (Player p in Board.Access().GetPlayers()) { //if player is active if (p.IsActive()) { //increment activePlayerCount activePlayerCount++; } } //if less than two active players display winner if (activePlayerCount < 2) { this.PrintWinner(); } return; } //prompt player to make move Console.WriteLine("{0}Your turn. Press Enter to make move", PlayerPrompt(iPlayerIndex)); Console.ReadLine(); //move player player.Move(); if (player.IsInJail && player.RolledDoubles && (player.RollDoublesFailureCount < 3)) { player.SetFreeFromJail(); Console.WriteLine("You rolled doubles! You are out of Jail."); } if (player.IsInJail && player.RollDoublesFailureCount == 3) { Console.WriteLine("You've failed to roll doubles three times while in Jail and must now settle it."); GetOutOfJail(player, true); } //Display making move Console.WriteLine("*****Move for {0}:*****", player.GetName()); //Display rolling Console.WriteLine("{0}{1}\n", PlayerPrompt(iPlayerIndex), player.DiceRollingToString()); Property propertyLandedOn = Board.Access().GetProperty(player.GetLocation()); HandleLanding(propertyLandedOn, player); //Display player details Console.WriteLine("\n{0}{1}", PlayerPrompt(iPlayerIndex), player.BriefDetailToString()); if (player.IsCriminal()) { Console.WriteLine("You are a criminal, go to Jail and lose your turn."); // Need to reset this here so when they come to get out of jail they aren't seen as a ciminal again // Thrice in a row means jail! if (player.RolledDoublesCount > 2) { Console.WriteLine("This is because you rolled doubles thrice in a row."); } // Reset the count as they've been sent to jail player.RolledDoublesCount = 0; return; } //display player choice menu DisplayPlayerChoiceMenu(player); // Player's get another turn when they roll doubles if (player.RolledDoubles && !player.IsInJail) { Console.WriteLine("You rolled doubles and get another turn"); continue; } // When turn ends reset their rolled doubles count player.RolledDoublesCount = 0; break; } }