public void test_player_landOn()
        {
            //Board.access().resetBoard(true);
            Player newPlayer1 = new Player("player1", 1500);
            Player newPlayer2 = new Player("player2", 1500);

            TradeableProperty theTradeProp = new TradeableProperty();
            //set prop owner
            theTradeProp.setOwner(ref newPlayer1);

            //String the1 = theTradeProp.landOn(ref newPlayer2);
            string landon1 = theTradeProp.landOn(ref newPlayer2).ToString();
            StringAssert.Contains("$100 to player1", landon1);

            //set prop mortgaged
            theTradeProp.setMortgaged(true);
            string landon2 = theTradeProp.landOn(ref newPlayer2).ToString();
            StringAssert.Contains("is currently morgaged skipping rent payment", landon2);
            String the2 = theTradeProp.landOn(ref newPlayer2);

            //set owner as landon should be just visting
            theTradeProp.setMortgaged(false);
            string landon3 = theTradeProp.landOn(ref newPlayer1).ToString();
            StringAssert.Contains("player1 landed on", landon3);
        }
        public void test_pay_rent()
        {
            //Board.access().resetBoard(true);
            Player newPlayer1 = new Player("player1", 1500);
            Player newPlayer2 = new Player("player2", 1500);

            decimal expected_player1 = newPlayer1.getBalance() + 100;
            decimal expected_player2 = newPlayer2.getBalance() - 100;

            TradeableProperty theTradeProp = new TradeableProperty();
            theTradeProp.setOwner(ref newPlayer1);
            theTradeProp.payRent(ref newPlayer2);

            Assert.AreEqual(expected_player1, newPlayer1.getBalance());
            Assert.AreEqual(expected_player2, newPlayer2.getBalance());
        }
        public void test_bank_owns_purchase()
        {
            Player newPlayer1 = new Player("player1", 1500);
            Player newPlayer2 = new Player("player2", 1500);

            TradeableProperty theTradeProp = new TradeableProperty();
            theTradeProp.setOwner(ref newPlayer1);
            //this will throw error as prop should not be availble
            try
            {
                theTradeProp.purchase(ref newPlayer2);
            }
            catch (ApplicationException e)
            {
                StringAssert.Contains("The property is not available from purchase", e.ToString());
            }
        }
        public void test_player_purchase()
        {
            Player play = new Player("player1", 1500);
            TradeableProperty tradeProp = new TradeableProperty();
            //this will throw error as prop should not be availble
            try
            {
                tradeProp.purchase(ref play);

            }
            catch (ApplicationException)
            {
                Assert.Fail();
            }
            Assert.IsTrue(tradeProp.getOwner() == play);
        }
 public void test_construct()
 {
     TradeableProperty theProp = new TradeableProperty();
     //default is 200
     Assert.AreEqual(200, theProp.getPrice());
 }
Beispiel #6
0
        public void displayJailMenu(Player player)
        {
            Monopoly game = new Monopoly();
            Property property = new Property();
            TradeableProperty trade = new TradeableProperty();
            PlayerInput input = new PlayerInput();

            // If the player has been in Jail for 3 turns, on the 4th turn in jail they will be forced to pay themselves out
            if (player.getTurnsInJail() < 3)
            {
                int resp = 0;
                Console.WriteLine("1. Roll doubles to get out of jail");
                Console.WriteLine("2. Pay $50 to get out of jail");
                Console.WriteLine("3. Use \"Get out of jail free\" card");
                Console.WriteLine("4. Trade Property with Player");
                Console.WriteLine("5. Upgrade properties");
                Console.WriteLine("6. View your details");
                Console.WriteLine("7. Declare Bankrupt");
                Console.Write("(1-7)>");
                //read response
                resp = input.inputInteger();
                //if response is invalid redisplay menu
                if (resp == 0)
                    this.displayJailMenu(player);

                //perform choice according to number input
                switch (resp)
                {
                    case 1:
                        player.playerJailRoll();
                        break;
                    case 2:
                        if (player.getBalance() >= 50)
                        {
                            player.pay(50);
                            Console.WriteLine("{0} payed $50 to get out of jail.\n", player.getName());
                            player.setSentToJail(false);
                            player.setInJail(false);
                            player.setTurnsInJail(0);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("You do not have enough money, please make another selection.\n");
                            this.displayJailMenu(player);
                            break;
                        }
                    case 3:
                        if (player.getGetOutOfJailCard())
                        {
                            Console.WriteLine("{0} used their get out of Jail card.\n", player.getName()); ;
                            player.setGetOutOfJailCard(false);
                            player.setInJail(false);
                            player.setTurnsInJail(0);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("{0} doesn't have a get out of Jail card, please make another selection.\n", player.getName());
                            this.displayJailMenu(player);
                            break;
                        }
                    case 4:
                        game.tradeProperty(player);
                        displayJailMenu(player);
                        break;
                    case 5:
                        Console.WriteLine("That option is not implemented yet, please try again.\n");
                        break;
                    case 6:
                        Console.WriteLine("==================================");
                        Console.WriteLine(player.FullDetailsToString());
                        Console.WriteLine("==================================");
                        this.displayJailMenu(player);
                        break;
                    case 7:
                        Console.WriteLine("That option is not implemented yet, please try again.\n");
                        break;
                    default:
                        Console.WriteLine("That option is not avaliable, please try again.");
                        this.displayJailMenu(player);
                        break;
                }
                player.setTurnsInJail(player.getTurnsInJail() + 1);
            }

            // Runs on player's 4th turn in jail
            else if (player.getTurnsInJail() == 3)
            {
                Console.WriteLine("{0} has been in jail for 3 turns and must pay the $50", player.getName());
                player.setInJail(false);
                player.setSentToJail(false);
                player.pay(50);
                player.setTurnsInJail(0);
            }
        }
Beispiel #7
0
 public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
 {
     purchaser.pay(amount);
     this.receive(amount);
     property.setOwner(ref purchaser);
 }