public void AddPlayer(Player playerToAdd) { if (this.players.Any(p => p.Name == playerToAdd.Name)) throw new InvalidOperationException("Cannot add the same player to the game more than once."); this.players.Add(playerToAdd); }
public void PlayerPassingIncomeTaxDoesNotAffectPlayerBalance() { horse = new Player("Horse", 500); incomeTax.PassedByPlayer(horse, currentDiceValue); Assert.AreEqual(500, horse.Balance); }
private void TakeTurn(Player player) { Turn turn = new Turn(this.dice, player, this.gameBoard); turn.Take(); this.currentRound.AddPlayerTurn(player); }
public void PlayerOrderIsRandomized() { Mock<IRoundManager> mockRoundManager = new Mock<IRoundManager>(); var car = new Player("Car"); var horse = new Player( "Horse"); var hat = new Player("Hat"); var players = new List<Player>() { car, horse, hat }; var game = new Game(mockRoundManager.Object, players); Boolean carIsFirst = false; Boolean horseIsFirst = false; Boolean hatIsFirst = false; for (Int32 i = 0; i < 100; i++) { game.PlayNumberOfRounds(1); if (game.players.First().Name == "Car") carIsFirst = true; else if (game.players.First().Name == "Horse") horseIsFirst = true; else if (game.players.First().Name == "Hat") hatIsFirst = true; } Assert.IsTrue(carIsFirst && horseIsFirst && hatIsFirst); }
public override void LandedOn(Player curPlayer) { int tax; Debug.WriteLine("Player Landed on IncomeTax Cell"); Console.WriteLine(curPlayer.Name + " arrived at " + this.CellName); //Minimum of 2000 and 10% of player's property value will be deducted. //Player should know his property value tax = (int)Math.Floor(Math.Min((double)2000, (double)(curPlayer.getNetWorth() * 0.1))); if (tax > 0) { Console.WriteLine("Sorry!!! $"+tax+" will be charged for tax"); if (curPlayer.Money >= tax) { curPlayer.Money -= tax; } else { Console.WriteLine("You dont have suffecient funds \nPlease sell a property "); if ((curPlayer.SellProperty() == true) && (curPlayer.Money < 0)) { curPlayer.Money -= tax; } else { curPlayer.IsKickedOut = true; Console.WriteLine("You dont have any propertie to sell \nYou have been kicked out of the game"); } } } }
public override void LandedOn(Player curPlayer) { const int FINE_FOR_JAIL=2000; Debug.WriteLine("Player Landed on GoToJail Cell"); Console.WriteLine(curPlayer.Name + " arrived at " + this.CellName); Console.WriteLine("Sorry, $"+FINE_FOR_JAIL+" will be take for Fine"); if (curPlayer.Money >= FINE_FOR_JAIL) { curPlayer.Money -= FINE_FOR_JAIL; } else { Console.WriteLine("You dont have suffecient funds \nPlease sell a property "); if ((curPlayer.SellProperty() == true) && (curPlayer.Money >= FINE_FOR_JAIL)) { curPlayer.Money -= FINE_FOR_JAIL; } else { curPlayer.IsKickedOut = true; Console.WriteLine("You dont have any propertie to sell \nYou have been kicked out of the game"); } } moveToJailCell(curPlayer); }
public void PlayerLandingOnLuxuryTaxDecreasesPlayerBalanceByLuxuryTaxAmount() { horse = new Player("Horse", 1500); luxuryTax.LandedOnByPlayer(this.horse, this.currentDiceValue); Assert.AreEqual(1500 - ClassicBoard.LuxuryTaxPaymentAmount, this.horse.Balance); }
public void PlayerLandingOnIncomeTaxWheNetWorthIsZeroDecreasesPlayerBalanceByZero() { horse = new Player("Horse", 0); incomeTax.LandedOnByPlayer(horse, currentDiceValue); Assert.AreEqual(0, horse.Balance); }
public override void LandedOn(Player curPlayer) { Console.WriteLine(curPlayer.Name + " arrived at " + SQUARE_NAME); curPlayer.SetLocation(jailSquare); curPlayer.IsInJail = true; Console.WriteLine(curPlayer.Name + " is moved to JailCell $$"); }
public void Initialize() { this.fakeDice = new FakeDice(); this.player = new Player("Horse"); this.board = new ClassicBoard(); this.turn = new Turn(this.fakeDice, this.player, this.board); }
public void PlayerLandingOnIncomeTaxWhenPercentageOfNetWorthIsAboveMaximumPaymentDecreasesPlayerBalanceByMaximumPayment() { horse = new Player("Horse", 2200); incomeTax.LandedOnByPlayer(horse, currentDiceValue); Assert.AreEqual(2200 - ClassicBoard.MaximumIncomeTaxPaymentAmount, horse.Balance); }
public void PlayerLandingOnIncomeTaxWhenPercentageOfNetWorthIsBelowMaximumPaymentDecreasesPlayerBalanceByPercentage() { horse = new Player("Horse", 1800); incomeTax.LandedOnByPlayer(horse, currentDiceValue); Assert.AreEqual(1800 - (1800 / ClassicBoard.IncomeTaxPercentage), horse.Balance); }
public JailTests() { player = new Player("Name", 1500); player.BuyingStrategy = new NeverBuyStrategy(); goToJail = new GoToJail(ClassicBoard.GoToJailLocation, ClassicBoard.JailLocation); dice = new FakeDice(); turn = new Turn(dice, player, new ClassicBoard()); }
public override void LandedOn(Player curPlayer) { Console.WriteLine(curPlayer.Name + " arrived at " + this.CellName); Console.WriteLine("Sorry!! Next turn will be skipped"); Debug.WriteLine("Player Landed on Jail Cell"); //If user is from GotoJail, then fine will be given and next turn will be skipped //But If user is landed by turn, he will just skip next turn. }
public override void LandedOn(Player curPlayer) { string answer; Debug.WriteLine("Player Landed on PropertyCell Cell"); Console.WriteLine(curPlayer.Name + " arrived at " + this.CellName); if (this.available) { Console.WriteLine("This cell is available"); Console.Write("Do you want to buy this cell? (y/n): "); answer = Console.ReadLine(); if (answer == "y" || answer == "Y") { if (curPlayer.BuyProperty() == true) { Console.WriteLine("Congratulation , you own this cell now"); } else { Console.WriteLine("You dont have suffecient money!!. Please sell a property "); while (curPlayer.getPropertyNumber() > 0) { if ((curPlayer.SellProperty() == true) && (curPlayer.BuyProperty() == true)) { Console.WriteLine("Congratulation , you own this cell now"); break; } else { Console.WriteLine("Sorry, due to shortage of money, it was not processed!"); } } } } } else if (this.owner != curPlayer) { Console.WriteLine("Unfortunaetly you are in someone's properties. You have to pay rent for him"); if (curPlayer.PayRentTo() == true) { Console.WriteLine("Rent fee $" + this.rentPrice + " have been paid to " + this.owner.Name); } else { Console.WriteLine("You dont have suffecient funds!"); if ((curPlayer.SellProperty() == false) || (curPlayer.PayRentTo() == false)) { curPlayer.IsKickedOut = true; Console.WriteLine("You dont have any propertie to sell \nYou have been kicked out of the game"); } else { Console.WriteLine("Rent fee $" + this.rentPrice + " have been paid to " + this.owner.Name); } } } }
public void PlayerStartsAtZeroAndRollsASevenDude() { IPlayer player = new Player("Horse"); var turnManager = new TurnManager(board, dice); turnManager.PlayTurn(player); Assert.AreEqual(7, player.Location); }
public MonopolyGame() { const int INIT_CASH = 2000; Player p; p = new Player("Horse", cup, board, INIT_CASH); players.Add(p); p = new Player("Cars", cup, board, INIT_CASH); players.Add(p); }
public PropertyTests() { horse = new Player("Horse", 2000); hat = new Player("Hat", 1500); mediterraneanAvenue = new Property(ClassicBoard.MediterraneanAvenueLocation, ClassicBoard.MediterraneanAvenuePrice, ClassicBoard.MediterraneanAvenueRent); balticAvenue = new Property(ClassicBoard.BalticAvenueLocation, ClassicBoard.BalticAvenuePrice, ClassicBoard.BalticAvenueRent); purpleGroup = new PropertyGroup(new ClassicPropertyRentStrategy(), mediterraneanAvenue, balticAvenue); currentDiceValue = 7; }
public void LessThanTwoPlayersThrowsException() { Mock<IRoundManager> mockRoundManager = new Mock<IRoundManager>(); var car = new Player("Car"); var players = new List<Player>() { car }; var game = new Game(mockRoundManager.Object, players); game.PlayGame(); }
public PropertyCell(int index, int cellPrice, int rentPrice) : base(index, "Property Cell " + index) { Debug.WriteLine("Property Cell Created with index" + index); available = true; owner = null; this.cellPrice = cellPrice; this.rentPrice = rentPrice; }
private void InitPlayer(Player player) { if (this.Dispatcher.CheckAccess()) { LocalPlayer = player; MoneyDisplay.Text = "Cash: $" + player.Money; player.PlayerUpdate += new EventHandler<PlayerUpdateEventArgs>(player_PlayerUpdate); } else this.Dispatcher.BeginInvoke(new Action<Player>(InitPlayer), new object[] { player }); }
private bool PayRent(Player curPlayer) { int r; r = this.GetRent(); this.owner.AddCash(r); if (curPlayer.ReduceCash(r) == false) { return false; } return true; }
private void GameOver(Player loser) { MessageBox.Show(string.Format("輸家為{0}", loser.Name), "遊戲結束"); btnDice.Enabled = false; DialogResult result = MessageBox.Show("在玩一局?", "Monopoly", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) Initial(); else Application.Exit(); }
public void Setup() { generator = new RandomGeneratorMoc(); string[] properties = { "a", "b", "c", "d", "e" }; gameBoard = new Board(new PropertyFactory(properties)); player = new Player(generator, gameBoard); }
public int TestRoundsPlayed(int roundsToPlay) { Player player = new Player("Car", new RandomNumberGenerator()); for (int i = 0; i < roundsToPlay; i++) { player.TakeTurn(); } return player.RoundsPlayed; }
public int TestTakeTurn(int initialPosition, int die1, int die2) { Mock<IRandomNumberGenerator> randMock = new Mock<IRandomNumberGenerator>(); randMock.SetupSequence(s => s.Generate(1, MonopolyGame.NUMBER_OF_SIDES)).Returns(die1).Returns(die2); Player player = new Player("Car", randMock.Object) { CurrentPosition = initialPosition }; player.TakeTurn(); return player.CurrentPosition; }
public virtual void BuyProperty(Player curPlayer) { if ((this.owner == null) || (curPlayer == this.owner)) { curPlayer.AttemptPurchase(this); } else if (curPlayer != this.owner) { PayRent(curPlayer); } }
public override string landOn(ref Player player) { if ((this.getOwner() != Banker.access()) && (this.getOwner() != player)) { this.payRent(ref player); return String.Format("You rolled for a total of {0}. Your rent is ${1}", player.getLastMove(), dRent); } else { return base.landOn(ref player); } }
public RailroadTests() { this.horse = new Player("Horse", 1500); this.hat = new Player("Hat", 1000); this.currentDiceValue = 7; this.readingRailroad = new Property(ClassicBoard.ReadingRailroadLocation, ClassicBoard.RailroadPrice, ClassicBoard.BaseRailroadRent); this.pennsylvaniaRailroad = new Property(ClassicBoard.PennsylvaniaAvenueLocation, ClassicBoard.RailroadPrice, ClassicBoard.BaseRailroadRent); this.boRailroad = new Property(ClassicBoard.BORailroadLocation, ClassicBoard.RailroadPrice, ClassicBoard.BaseRailroadRent); this.shortLine = new Property(ClassicBoard.ShortLineLocation, ClassicBoard.RailroadPrice, ClassicBoard.BaseRailroadRent); this.railroadGroup = new PropertyGroup(new ClassicRailroadRentStrategy(), this.readingRailroad, this.pennsylvaniaRailroad, this.boRailroad, this.shortLine); }
public Property(Int16 space, string name, string set, int price, int[] rent, bool ownable) { _space = space; _name = name; _set = set; _price = price; _rent = rent; _ownable = ownable; _owner = null; _inMonopoly = false; _houses = 0; }
public override int GetRent(Dictionary<int, int> realEstateOwnerMap, Dictionary<int, Location> locations, Player player, int rollOfDice) { var ownerId = realEstateOwnerMap[player.BoardPosition]; var numOfOwnedUtility = GetNumberOfOwnedPropertyInPropertyGroup(ownerId, this, realEstateOwnerMap, locations); return DiceMultiplierForRent[numOfOwnedUtility] * rollOfDice; }