Exemplo n.º 1
0
        public void SellDevelopableLand_Developed_Unmortgaged()
        {
            int[] rentTable = new int[6] {
                4, 20, 60, 180, 320, 500
            };
            DevelopableLand gangstersParadise = new DevelopableLand("Gangsters Paradise",
                                                                    60, Colour.Brown, rentTable);

            // develop property with 1 house
            gangstersParadise.Develop();
            Assert.AreEqual(1, gangstersParadise.GetHouses());

            // check if property can be sold
            Assert.IsFalse(gangstersParadise.CanSellProperty());

            // cannot sell, must undevelop property first
            gangstersParadise.Undevelop();
            Assert.AreEqual(0, gangstersParadise.GetHouses());

            // unmortgaged property sells for original price value (£60)
            Assert.IsTrue(gangstersParadise.CanSellProperty());
            int sellingPrice = gangstersParadise.SellPropertyToBank();

            Assert.AreEqual(60, sellingPrice);
            // property is unowned after selling
            Assert.IsNull(gangstersParadise.GetOwner());
        }
Exemplo n.º 2
0
        public void InitaliseDevelopableLandWithCorrectData()
        {
            int[] rentTable = new int[6] {
                30, 60, 100, 150, 200, 320
            };
            int             price   = 200;
            Colour          group   = Colour.Blue;
            DevelopableLand reyLane = new DevelopableLand("Rey Lane", price, group, rentTable);

            // correct name
            Assert.AreEqual("Rey Lane", reyLane.GetPropertyName());
            // correct price
            Assert.AreEqual(200, reyLane.GetPrice());
            // correct group
            Assert.AreEqual(Colour.Blue, reyLane.GetColourGroup());
            // correct rent table
            var actualRentTable = reyLane.GetRentTable();

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(rentTable[i], actualRentTable[i]);
            }
            // initially unowned
            Assert.IsNull(reyLane.GetOwner());
            // initially unmortgaged
            Assert.IsFalse(reyLane.IsMortgaged());
            // initially undeveloped
            Assert.AreEqual(0, reyLane.GetHouses());
            // implements IProperty interface
            Assert.IsTrue(reyLane is IProperty);
        }
Exemplo n.º 3
0
        public void Player_TradeProperty()
        {
            DevelopableLand crapperStreet = new DevelopableLand("Crapper Street", 100, Colour.Brown, new int[6] {
                20, 20, 40, 60, 80, 100
            });
            DevelopableLand gangsters = new DevelopableLand("Gangsters Paradise", 100, Colour.Brown, new int[6] {
                20, 20, 40, 60, 80, 100
            });
            Station     lewes = new Station("Lewes Station", 200);
            HumanPlayer sarah = new HumanPlayer("Sarah", 0, Token.Boot);
            HumanPlayer bob   = new HumanPlayer("Bob", 1, Token.Hatstand);

            // sarah buys crapper street, gangsters paradise and bob buys lewes station
            sarah.BuyProperty(crapperStreet);
            sarah.BuyProperty(gangsters);
            bob.BuyProperty(lewes);

            // assume bob and sarah agree to trade 2 brown properties for lewes station
            // trade method only handles updated player property lists and station/utility counts
            List <IProperty> tradeOff = new List <IProperty>()
            {
                crapperStreet, gangsters
            };
            List <IProperty> tradeReturn = new List <IProperty>()
            {
                lewes
            };

            sarah.TradeProperties(tradeOff, tradeReturn);
            bob.TradeProperties(tradeReturn, tradeOff);

            // check player's owned property lists are updated correctly
            Assert.IsTrue(bob.GetPropertiesOwned().Contains(crapperStreet));
            Assert.IsTrue(bob.GetPropertiesOwned().Contains(gangsters));
            Assert.IsFalse(bob.GetPropertiesOwned().Contains(lewes));
            Assert.AreEqual(0, bob.GetNumberOfStations()); // check stations count updated

            Assert.IsFalse(sarah.GetPropertiesOwned().Contains(crapperStreet));
            Assert.IsFalse(sarah.GetPropertiesOwned().Contains(gangsters));
            Assert.IsTrue(sarah.GetPropertiesOwned().Contains(lewes));
            Assert.AreEqual(1, sarah.GetNumberOfStations()); // check stations count updated

            // ensure owner of property objects updated correctly
            Assert.AreEqual(bob, crapperStreet.GetOwner());
            Assert.AreEqual(bob, gangsters.GetOwner());
            Assert.AreEqual(sarah, lewes.GetOwner());

            // attempting to trade property that isn't owned by that player throws exception
            try
            {
                sarah.TradeProperties(tradeOff, tradeReturn);
            }
            catch (HumanPlayerException e)
            {
                Console.WriteLine(e.Message);
                Assert.AreEqual(e.Message, "Cannot trade a property because the player doesn't own it.");
            }
        }
Exemplo n.º 4
0
        public void SellDevelopableLand_Mortgaged()
        {
            int[] rentTable = new int[6] {
                4, 20, 60, 180, 320, 450
            };
            DevelopableLand gangstersParadise = new DevelopableLand("Gangsters Paradise",
                                                                    60, Colour.Brown, rentTable);

            // mortgage property
            gangstersParadise.Mortgage();
            Assert.IsTrue(gangstersParadise.IsMortgaged());
            // mortgaged property sells for half price (£30)
            Assert.IsTrue(gangstersParadise.CanSellProperty());
            int sellingPrice = gangstersParadise.SellPropertyToBank();

            Assert.AreEqual(30, sellingPrice);
            // property is unowned and unmortgaged after selling
            Assert.IsNull(gangstersParadise.GetOwner());
            Assert.IsFalse(gangstersParadise.IsMortgaged());
        }