Exemple #1
0
        public void verify_ToString_methods()
        {
            // need to reset and add a property to the board for these tests
            var luckFactory = new LuckFactory();

            Board.Access().ResetBoard();
            Board.Access().AddProperty(luckFactory.create("Go", false, 200));

            _emptyPlayer.SetBalance(500);
            _emptyPlayer.SetName("Josh");
            _emptyPlayer.SetLocation(0);

            const string expectedStandardToString = "Josh";
            var          actualStandardToString   = _emptyPlayer.ToString();

            Assert.AreEqual(expectedStandardToString, actualStandardToString);

            const string expectedBriefDetailToString = "You are on Go.\tYou have $500.";
            var          actualBriefDetailToString   = _emptyPlayer.BriefDetailToString();

            Assert.AreEqual(expectedBriefDetailToString, actualBriefDetailToString);

            var expectedFullDetailToString = string.Format("Player:Josh.\nBalance: $500\nLocation: Go: \t Owned by: Leeroy Jenkins (Square 0) \nProperties Owned:\n{0}", _emptyPlayer.PropertiesOwnedToString());
            var actualFullDetailToString   = _emptyPlayer.FullDetailToString();

            Assert.AreEqual(expectedFullDetailToString, actualFullDetailToString);

            const string expectedDiceRollToString = "Rolling dice: \t Dice 1: 0 \t Dice 2: 0";
            var          actualDiceRollToString   = _emptyPlayer.DiceRollingToString();
        }
Exemple #2
0
        public void attempt_property_development()
        {
            FreshBoard();
            var blueProperties = Board.Access().GetAllPropertiesOfColour("Blue");

            foreach (var blueProperty in blueProperties)
            {
                blueProperty.SetOwner(ref _emptyPlayer);
            }

            // Just get a random one of those properties
            var randomBlueProperty = blueProperties.First();

            // Add a house to that property
            randomBlueProperty.AddHouse();

            // Now that property shouldn't be allowed to be developed anymore because
            // the other properties in this colour group don't have one house as well
            Assert.IsFalse(_emptyPlayer.CanDevelopPropertyFurther(randomBlueProperty));

            // Get another property
            var anotherRandomBlueProperty = blueProperties.Last();

            // This property should be okay to develop to bring it to the same development
            // of the previous property
            Assert.IsTrue(_emptyPlayer.CanDevelopPropertyFurther(anotherRandomBlueProperty));
        }
        public void correct_banker_should_be_loaded_on_load_game()
        {
            var gameOfMonopoly = new Monopoly();

            // Make him pay a bit of money so we know if it's the same
            // banker being loaded
            Banker.Access().Pay(1000);

            var bankerBeforeSavedBalance = Banker.Access().GetBalance();

            // Need to players on the board for saving and loading correctly
            Board.Access().AddPlayer(new Player());
            Board.Access().AddPlayer(new Player());

            gameOfMonopoly.SaveGame();

            // Set the banker's balance to something random so we know
            // it's then changed when we load the game that has the
            // other banker's balance from the previous save
            Banker.Access().SetBalance(500);

            gameOfMonopoly.LoadGame();

            var bankerAfterLoadedBalance = Banker.Access().GetBalance();

            // The balance should be what it was when we saved it even though we
            // changed it, this is because the banker we're loading is the one
            // before we changed the balance
            Assert.AreEqual(bankerBeforeSavedBalance, bankerAfterLoadedBalance);
        }
Exemple #4
0
        public void loading_board_from_saved_board()
        {
            Board.Access().ResetBoard();

            CollectionAssert.IsEmpty(Board.Access().GetProperties());

            _gameOfMonopoly.SetUpProperties();
            Board.Access().AddPlayer(new Player());
            Board.Access().AddPlayer(new Player());
            _gameOfMonopoly.SaveGame();

            _gameOfMonopoly.LoadGame();

            Assert.AreEqual(40, Board.Access().GetProperties().Count);

            var bankerOwnedProperty = (Property)Board.Access().GetProperties().ToArray().First();

            // Owner should be the banker for this property
            Assert.AreEqual(Banker.Access(), bankerOwnedProperty.GetOwner());

            // Need to reset the the save file to a blank board
            // for when actually playing the game
            Board.Access().ResetBoard();
            _gameOfMonopoly.SaveGame();
        }
Exemple #5
0
        public void board_has_16_chance_cards()
        {
            SetUp();
            const int expected = 16;
            var       actual   = Board.Access().GetChanceCards().Count;

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        public void board_has_16_community_cards()
        {
            SetUp();
            const int expected = 16;
            var       actual   = Board.Access().GetCommunityChestCards().Count;

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        private static void FreshBoard()
        {
            Board.Access().ResetBoard();
            // Need to add all properties to board
            var monopoly = new Monopoly();

            monopoly.SetUpProperties();
        }
Exemple #8
0
        public void setting_up_players_fails_with_less_than_2_players()
        {
            Board.Access().ResetBoard();
            _gameOfMonopoly = new Monopoly();
            _gameOfMonopoly.SetUpProperties();

            _gameOfMonopoly.SetUpPlayers(1);
        }
Exemple #9
0
        public void no_chance_cards_exist()
        {
            Board.Access().ResetBoard();

            var chanceCard = Board.Access().GetChanceCard();

            Assert.IsNull(chanceCard);
        }
Exemple #10
0
        public void player_doesnt_own_any_properties()
        {
            Board.Access().ResetBoard();

            _gameOfMonopoly.SellHouse(_player1);

            Assert.Pass();
        }
Exemple #11
0
        public void file_is_written()
        {
            var fileWriter = new FileWriter();

            fileWriter.SaveGame(Board.Access());

            Assert.IsTrue(File.Exists("SavedBoard.bin"));
        }
Exemple #12
0
        public void getting_property_by_name()
        {
            var property = new Property("Test");

            Board.Access().AddProperty(property);

            // Should not be null if it get us a property from this name
            Assert.IsNotNull(Board.Access().GetProperty("Test"));
        }
Exemple #13
0
        public void property_isnt_residential()
        {
            var property = new Transport();

            property.SetOwner(ref _player1);
            Board.Access().AddProperty(property);

            _gameOfMonopoly.BuyHouse(_player1, property, true);
        }
Exemple #14
0
        public void player_doesnt_own_properties()
        {
            Board.Access().ResetBoard();
            var property = new Residential();

            _gameOfMonopoly.BuyHouse(_player1, property, true);

            Assert.AreEqual(0, property.GetHouseCount());
        }
Exemple #15
0
        public void game_ends_when_1_active_player_left()
        {
            // Bankrupt the player to make inactive
            _player1.SetBalance(0);
            _player1.CheckBankrupt();

            _gameOfMonopoly.PlayGame();

            Assert.IsTrue(Board.Access().GetGameOver());
        }
Exemple #16
0
        public void landing_on_go_to_jail_sends_player_to_jail()
        {
            FreshBoard();
            PutPlayerInJail();

            Assert.IsTrue(_emptyPlayer.IsInJail);

            // Check they are now on the jail property
            Assert.AreEqual(Board.Access().GetProperty(10), Board.Access().GetProperty(_emptyPlayer.GetLocation()));
        }
        public void go_to_jail_card()
        {
            _card = _luckFactory.create("Chance: go to jail", false, 0);
            _card.LandOn(ref _player);
            var playersLocation = Board.Access().GetProperty(_player.GetLocation());
            var jail            = Board.Access().GetProperty(10);

            Assert.AreEqual(playersLocation, jail);
            Assert.IsTrue(_player.IsInJail);
        }
Exemple #18
0
        public void setting_up_players_with_valid_players()
        {
            Board.Access().ResetBoard();
            _gameOfMonopoly = new Monopoly();
            _gameOfMonopoly.SetUpProperties();

            _gameOfMonopoly.SetUpPlayers(2, "Josh");

            Assert.AreEqual(2, Board.Access().GetPlayerCount());
        }
Exemple #19
0
        public void setting_location_greater_than_board()
        {
            FreshBoard();

            _emptyPlayer.SetLocation(49);

            const string expectedPropertyName = "Waitangi Treaty Grounds";
            var          actualPropertyName   = Board.Access().GetProperty(_emptyPlayer.GetLocation()).GetName();

            Assert.AreEqual(expectedPropertyName, actualPropertyName);
        }
Exemple #20
0
        public void setting_location_not_greater_than_board()
        {
            FreshBoard();

            _emptyPlayer.SetLocation(30);

            var expectedProperty = Board.Access().GetProperty(30);
            var actualProperty   = Board.Access().GetProperty(_emptyPlayer.GetLocation());

            Assert.AreEqual(expectedProperty, actualProperty);
        }
        public void adding_house_takes_away_from_board()
        {
            Board.Access().ResetBoard();

            var expectedHouses = Board.Access().Houses - 1;

            _residentialProperty.AddHouse();

            var actualHouses = Board.Access().Houses;

            Assert.AreEqual(expectedHouses, actualHouses);
        }
Exemple #22
0
        public void adding_property()
        {
            Property p = new Property();

            Board.Access().AddProperty(p);

            Assert.AreEqual(p, Board.Access().GetProperty(0));

            ArrayList props = Board.Access().GetProperties();

            CollectionAssert.Contains(props, p);
        }
Exemple #23
0
        public void no_houses_left()
        {
            var property = new Residential();

            Board.Access().Houses = 0;

            _gameOfMonopoly.BuyHouse(_player1, property, true);

            Assert.AreEqual(0, property.GetHouseCount());

            Board.Access().ResetBoard();
        }
Exemple #24
0
        public void purchasing_property()
        {
            SetUp();

            _player1.SetLocation(5);

            _gameOfMonopoly.PurchaseProperty(_player1, true);

            var propertyOwner = Board.Access().GetProperty(5).GetOwner();

            Assert.AreEqual(propertyOwner, _player1);
        }
Exemple #25
0
        public void player_doesnt_own_property_with_house()
        {
            Board.Access().ResetBoard();
            var property = new Residential("Test");

            property.SetOwner(ref _player1);

            Board.Access().AddProperty(property);

            _gameOfMonopoly.SellHouse(_player1);

            Assert.Pass();
        }
Exemple #26
0
        public void adding_player()
        {
            Board.Access().ResetBoard();
            Player p = new Player("Go");

            Board.Access().AddPlayer(p);

            //check that the player is equal to a new player with name "Go"
            Assert.AreEqual(Board.Access().GetPlayer("Go"), p);

            // test that the player count is correct
            Assert.AreEqual(1, Board.Access().GetPlayerCount());
        }
Exemple #27
0
        public void property_is_mortgaged()
        {
            var property = new Residential();

            property.SetOwner(ref _player1);
            property.MortgageProperty();

            Board.Access().AddProperty(property);

            _gameOfMonopoly.BuyHouse(_player1, property, true);

            Assert.AreEqual(0, property.GetHouseCount());
        }
Exemple #28
0
        public void adding_house()
        {
            Board.Access().ResetBoard();

            var property = new Residential("Test");

            property.SetOwner(ref _player1);
            Board.Access().AddProperty(property);

            _gameOfMonopoly.BuyHouse(_player1, property, true);

            Assert.AreEqual(1, property.GetHouseCount());
        }
        public void adding_hotel()
        {
            Board.Access().ResetBoard();
            _residentialProperty = NewResidential();

            for (var i = 0; i <= 4; i++)
            {
                _residentialProperty.AddHouse();
            }

            Assert.AreEqual(0, _residentialProperty.GetHouseCount());
            Assert.AreEqual(32, Board.Access().Houses);
            Assert.IsTrue(_residentialProperty.HasHotel);
        }
        public void property_with_hotel()
        {
            Board.Access().ResetBoard();
            _residentialProperty = NewResidential();
            Board.Access().AddProperty(_residentialProperty);
            // Multiplied by 5 houses is the expected hotel rent cost
            var expectedRent = _residentialProperty.GetRent() + (_residentialProperty.GetRent() * 5);

            _residentialProperty.HasHotel = true;

            var actualRent = _residentialProperty.GetRent();

            Assert.AreEqual(expectedRent, actualRent);
        }