Ejemplo n.º 1
0
        //overwrite original virtual method declared in Property class
        public override string landOn(ref Player player)
        {
            //if the following is a jail property and player has gone past then set player in jail
            if(this.isJail == true)
            {
                //enable setIsInJail to true
                player.setIsInJail();
                //don't let player pass GO and don't let collect $200
                player.setLocation(10, false);

                return null;
                //return base.landOn(ref player) + String.Format(player.getName() + " has gone to jail!");
            }
            else
            {
                if(player.getJailStats() == true)
                {
                    return null;
                    //return base.landOn(ref player) + String.Format(player.getName() + " you're now in jail, you cannot pass Go or collect $200.00\nTo Get out of jail you must:\n \t-pay $50\n \t-use a 'Get out of Jail Card'\n \t-or attempt to roll doubles.\n");
                }
                else
                {
                    return base.landOn(ref player) + String.Format(player.getName() + " is visiting jail!");
                }
                //when player is only visiting Jail
                //player.setNotInJail();
            }
        }
        public void testLandOn()
        {
            Utility util = new Utility();

            //Create two players
            Player p1 = new Player("Bill");
            Player p2 = new Player("Fred", 1500);

            string msg;

            //test landon normally with no rent payable
            msg = util.landOn(ref p1);
            Console.WriteLine(msg);

            //set owner to p1
            util.setOwner(ref p1);

            //move p2 so that utility rent can be calculated
            p2.move();

            //p2 lands on util and should pay rent
            msg = util.landOn(ref p2);
            Console.WriteLine(msg);

            //check that correct rent  has been paid
            decimal balance = 1500 - (6 * p2.getLastMove());
            Assert.AreEqual(balance, p2.getBalance());
        }
        public override string landOn(ref Player player)
        {
            if (this.setJail == true)
            {

              Console.WriteLine("You have gone to jail, you do not pass go you can not collect $200\n");
                player.setIsInJail();
                player.setLocation(10, false);
                return base.landOn(ref player) + String.Format(player.getName().ToString() + " has gone to jail!");
            }
            else
            {
                if (player.getJailStatis() == true)
                {

                    if (player.sendMsg == false)
                    {
                        return null;
                    }

                    return base.landOn(ref player) + String.Format(player.getName().ToString() + " is in jail!..");
                }
                return base.landOn(ref player) + String.Format(player.getName().ToString() + " is just visiting!.");

            }
        }
Ejemplo n.º 4
0
        public void testAddGetPlayer()
        {
            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);


        }
Ejemplo n.º 5
0
 public override string landOn(ref Player player)
 {
     //Pay rent if needed
     if ((this.getOwner() != Banker.access()) && (this.getOwner() != player))
     {
         //pay rent
         this.payRent(ref player);
         return base.landOn(ref player) + string.Format("Rent has been paid for {0} of ${1} to {2}.", this.getName(), this.getRent(), this.getOwner().getName());
     }
     else
         return base.landOn(ref player);
 }
Ejemplo n.º 6
0
 Player[] playersInJail = new Player[8];//arrayList of players in jail
 
 public Jail(Player _player)
 {
     this._player = _player;
     //loop through array and assign new player to the next empty index
     for(int i = 0; i <= playersInJail.Length; i++)
     {
         if(playersInJail[i] == null)
         {
             playersInJail[i] = _player;
         }                
     }
 }
Ejemplo n.º 7
0
 public override string landOn(ref Player player)
 {
     //Pay rent if needed
     if ((this.getOwner() != Banker.access()) && (this.getOwner() != player))
     {
         //pay rent
         this.payRent(ref player);
         return string.Format("You rolled a total of {0}. So your rent is {0} x {1} = ${2}.", player.getLastMove(), Utility.rentMultiplier, (player.getLastMove() * Utility.rentMultiplier));
     }
     else
         return base.landOn(ref player);
 }
        public override string landOn(ref Player player)
        {
            //Pay rent if needed, you will only pay rent when the property is owned by a player that is not the current player and the propety has not been mortgaged.
            if ((this.getOwner() != Banker.access()) && (this.getOwner() != player) && (this.isMortgaged == false))
            {

                //pay rent
                this.payRent(ref player);
                return base.landOn(ref player) + string.Format("Rent has been paid for {0} of ${1} to {2}.", this.getName(), this.getRent(), this.getOwner().getName());
            }
            else
                return base.landOn(ref player);
        }
Ejemplo n.º 9
0
 public override string landOn(ref Player player)
 {
     //if is a benefit player receives amount else pay amount
     if (this.isBenefitNotPenalty)
     {
         player.receive(this.penaltyOrBenefitAmount);
         return base.landOn(ref player) + String.Format("{0} has recieved {2}.", player.getName(), this.getName(), this.penaltyOrBenefitAmount);
     }
     else
     {
         player.pay(this.penaltyOrBenefitAmount);
         return base.landOn(ref player) + String.Format("{0} has paid {2}.", player.getName(), this.getName(), this.penaltyOrBenefitAmount);
     }
 }
Ejemplo n.º 10
0
        /*----- MENU FOR PLAYER WHEN IN JAIL -----*/
        public void displayInJailPlayerChoice(Player player)
        {
            int resp = 0;
            Console.WriteLine("\n{0}Please make a selection:\n", playerPrompt(player));
            Console.WriteLine("\t1. Attempt to roll doubles to get Released");
            Console.WriteLine("\t2. View your details");
            Console.WriteLine("\t3. Trade Property with Player");
            Console.WriteLine("\t4. Mortgage Property");
            Console.WriteLine("\t5. Pay $50");

            //read response
            resp = inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
                this.displayInJailPlayerChoice(player);

            switch (resp)
            {
                case 1:
                    player.hasRolledDoublesInJail();
                    //this.displayInJailPlayerChoice(player);
                    Console.WriteLine("\n\tPress ENTER to continue");
                    Console.ReadLine();
                    break;
                case 2:
                    Console.WriteLine("\n\t==================================");
                    Console.WriteLine(player.FullDetailsToString());
                    Console.WriteLine("\t====================================");
                    this.displayInJailPlayerChoice(player);
                    break;
                case 3:
                    this.tradeProperty(player);
                    this.displayInJailPlayerChoice(player);
                    break;
                case 4:
                    this.mortgageProperty(player);
                    this.displayInJailPlayerChoice(player);
                    break;
                case 5:
                    player.payFine();
                    Console.WriteLine("\n\tPress ENTER to continue");
                    Console.ReadLine();
                    break;
                default:
                    Console.WriteLine("\n\tThat option is not available!");
                    displayInJailPlayerChoice(player);
                    return;
            }
        }
Ejemplo n.º 11
0
 public void purchase(ref Player buyer)
 {
     //check that it is owned by bank
     if (this.availableForPurchase())
     {
         //pay price 
         buyer.pay(this.getPrice());
         //set owner to buyer
         this.setOwner(ref buyer);
     }
     else
     {
         throw new ApplicationException("The property is not available from purchase from the Bank.");
     }
 }
 public virtual void payRent(ref Player player)
 {
     //Need to check if the property has been mortgage before we charge the player rent.
     if (this.isMortgaged == false)
     {
         player.pay(this.getRent());
         this.getOwner().receive(this.getRent());
     }
     //Do not have to pay rent
     else
     {
         //Should change this to an exception
         Console.WriteLine("This property has been mortgaged, you do not need to pay rent: ");
     }
 }
Ejemplo n.º 13
0
        public void buyHouse(Player player)
        {
            //create prompt
            string sPrompt = String.Format("{0}Please select a property to buy a house for:", this.playerPrompt(player));
            //create variable for propertyToBuy
            Residential propertyToBuyFor = null;
            if (player.getPropertiesOwnedFromBoard().Count == 0)
            {
                //write message
                Console.WriteLine("{0}\nYou do not own any properties.", playerPrompt(player));
                //return from method
                return;
            }
            //get the property to buy house for
            Property property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt);
            //if dont own any properties

            //check that it is a residential
            if (property.GetType() == (new Residential().GetType()))
            {
                //cast to residential property
                propertyToBuyFor = (Residential)property;
            }
            else //else display msg
            {
                Console.WriteLine("{0}A house can no be bought for {1} because it is not a Residential Property.", this.playerPrompt(player), propertyToBuyFor.getName());
                return;
            }

            //check that max houses has not been reached
            if (propertyToBuyFor.getHouseCount() >= Residential.getMaxHouses())
            {
                Console.WriteLine("{0}The maximum house limit for {1} of {2} houses has been reached.", playerPrompt(player), propertyToBuyFor.getName(), Residential.getMaxHouses());
            }
            else
            {
                //confirm
                bool doBuyHouse = this.getInputYN(player, String.Format("You chose to buy a house for {0}. Are you sure you want to purchase a house for ${1}?", propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                //if confirmed
                if (doBuyHouse)
                {
                    //buy the house
                    propertyToBuyFor.addHouse();
                    Console.WriteLine("{0}A new house for {1} has been bought successfully", playerPrompt(player), propertyToBuyFor.getName());
                }
            }
        }
Ejemplo n.º 14
0
        public void testPayRent()
        {
            Utility u = new Utility();

            Player p = new Player("John", 1500);

            //move p so that utility rent can be calculated
            p.move();

            u.payRent(ref p);

            //get p last move
            int i = p.getLastMove();

            //check that p has played correct rent of 6 times last move
            decimal balance = 1500 - (6 * i);
            Assert.AreEqual(balance, p.getBalance());
        }
Ejemplo n.º 15
0
        public override string landOn(ref Player player)
        {
            //if this is a jail property and user has past go.
            //&& player.passGo()
            if (this.isJail)
            {
                //player landed on jail
                player.setIsInJail();
                //if is a benefit player receives amount else pay amount
                return base.landOn(ref player) + String.Format("{0} has gone to jail.", player.getName());

            }
            else
            {
                //if is a benefit player receives amount else pay amount
                return base.landOn(ref player) + String.Format("{0} just visting jail.", player.getName());

            }
        }
Ejemplo n.º 16
0
 public void addPlayer(Player player)
 {
     players.Add(player);
 }
Ejemplo n.º 17
0
        public void tradeProperty(Player player)
        {
            //create prompt
            string sPropPrompt = String.Format("{0}Please select a property to trade:", this.playerPrompt(player));
            //create prompt
            string sPlayerPrompt = String.Format("{0}Please select a player to trade with:", this.playerPrompt(player));

            //get the property to trade
            TradeableProperty propertyToTrade = (TradeableProperty)this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt);

            //if dont own any properties
            if (propertyToTrade == null)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", playerPrompt(player));
                //return from method
                return;
            }

            //get the player wishing to trade with
            Player playerToTradeWith = this.displayPlayerChooser(Board.access().getPlayers(), player, sPlayerPrompt);

            //get the amount wanted

            string inputAmtMsg = string.Format("{0}How much do you want for this property?", playerPrompt(player));

            decimal amountWanted = inputDecimal(inputAmtMsg);

            //confirm with playerToTradeWith
                //set console color
            ConsoleColor origColor = Console.ForegroundColor;
            int i = Board.access().getPlayers().IndexOf(playerToTradeWith);
            Console.ForegroundColor = this.colors[i];
                //get player response
            bool agreesToTrade = getInputYN(playerToTradeWith, string.Format("{0} wants to trade '{1}' with you for ${2}. Do you agree to pay {2} for '{1}'", player.getName(), propertyToTrade.getName(), amountWanted));
            //resent console color
            Console.ForegroundColor = origColor;
            if (agreesToTrade)
            {
                Player playerFromBoard = Board.access().getPlayer(playerToTradeWith.getName());
                //player trades property

                player.tradeProperty(ref propertyToTrade, ref playerFromBoard, amountWanted);
                Console.WriteLine("{0} has been traded successfully. {0} is now owned by {1}", propertyToTrade.getName(), playerFromBoard.getName());
            }
            else
            {
                //display rejection message
                Console.WriteLine("{0}{1} does not agree to trade {2} for ${3}", playerPrompt(player), playerToTradeWith.getName(), propertyToTrade.getName(), amountWanted);
            }     
        }
        public override string landOn(ref Player player)
        {
            //if the whole deck has been used, re shuffle the cards
            if (this.cardPulled >= this.Community_Cards_Actions.Count) this.ShuffleCards();

            string drawedCord = draw_card(player);
            return base.landOn(ref player) + String.Format(drawedCord);
        }
Ejemplo n.º 19
0
 /*----- METHOD TO UNMORTGAGE PROPERTY -----*/
 public void unMortgageProperty(Player player)
 {
     string sPropPrompt = String.Format("{0}\tPlease select a property to mortgage:", this.playerPrompt(player));
     //get selected property to UnMortgage
     TradeableProperty propertyToUnMortgage = (TradeableProperty)this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt);
     //check if player has any mortgaged properties
     if (player.getPropertiesOwnedFromBoard().Count == 0)
     {
         Console.WriteLine("\n\tYou don't currently own any mortgaged properties.");
     }
     else
     {
         //now call the unmortgage method in Property class
         propertyToUnMortgage.unMortgage(propertyToUnMortgage);
         Console.WriteLine("\n\tYou've successfully unmortgaged " + propertyToUnMortgage.getName());
     }
 }
Ejemplo n.º 20
0
 public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
 {
     purchaser.pay(amount);
     this.receive(amount);
     property.setOwner(ref purchaser);
 }
 //draw a card
 public string draw_card(Player player)
 {
     ///Community_Cards_Actions
     current_player = player; //Current Player
     Actionable cardPull = Community_Cards_Actions[this.cardPulled++];
     cardPull.Action.Invoke();
     return cardPull.Name.ToString();
 }
Ejemplo n.º 22
0
        public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
        {
            //get property's original mortgage price
            decimal originalMortgagePrice = property.calculateMortgage(property);
            //get 10% of original mortgage price
            decimal originalMortgagePriceTenPercent = originalMortgagePrice * 10 / 100;
            decimal unMortgagePrice = originalMortgagePrice + originalMortgagePriceTenPercent;

            //purchaser.pay(amount);

            //check if purchased property is already mortgaged
            if (property.getMortgagedStatus() == true)
            {
                int userOption = 0;
                //if purchased property is mortgaged then player must unmortgage
                Console.WriteLine("\n\tThis property is currently mortgaged, you must either:\n\t1. Unmortgage it for the mortgage price plus 10%.\n\t2. Pay the bank 10% and keep it mortgaged.\n");

                //get user options input
                userOption = userInput();

                //grab user input value and run appropriate methods
                try
                {
                    switch (userOption)
                    {
                        case 1:
                            purchaser.pay(unMortgagePrice);
                            //---STILL NEED TO MAKE OTHER PLAYER RECEIVE PAYMENT
                            this.receive(unMortgagePrice);
                            property.setPropertyNotMortgaged();
                            property.setOwner(ref purchaser);
                            //property.unMortgage(property);
                            //Console.WriteLine("You've unmortgaged this property and now own it");
                            break;
                        case 2:
                            //pay 10%
                            purchaser.pay(originalMortgagePriceTenPercent);
                            //allocate da moneys to da banker
                            Banker.access().receive(originalMortgagePriceTenPercent);
                            //keep property as mortgaged
                            property.setPropertyIsMortgaged();

                            property.getMortgagedStatus();
                            //set owner
                            property.setOwner(ref purchaser);
                            break;
                    }
                }
                catch (ApplicationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                this.receive(amount);
                property.setOwner(ref purchaser);
            }
        }
Ejemplo n.º 23
0
        public void setUpPlayers()
        {
            //Add players to the board
            Console.WriteLine("How many players are playing?");
            Console.Write("(2-8)>");
            int playerCount = this.inputInteger();

            //if it is out of range then display msg and redo this method
            if ((playerCount < 2) || (playerCount > 8))
            {
                Console.WriteLine("That is an invalid amount. Please try again.");
                this.setUpPlayers();
            }

            //Ask for players names
            for (int i = 0; i < playerCount; i++)
            {
                Console.WriteLine("Please enter the name for Player {0}:", i + 1);
                Console.Write(">");
                string sPlayerName = Console.ReadLine();
                Player player = new Player(sPlayerName);
                //subscribe to events
                player.playerBankrupt += playerBankruptHandler;
                player.playerPassGo += playerPassGoHandler;
                //add player 
                Board.access().addPlayer(player);
                Console.WriteLine("{0} has been added to the game.", Board.access().getPlayer(i).getName());
            }

            Console.WriteLine("Players have been setup");
        }
Ejemplo n.º 24
0
 public string playerPrompt(Player player)
 {
     return string.Format("{0}:\t", player.getName());
 }
        //override the landOn method
        public override string landOn(ref Player player)
        {
            //if we have pulled the complete deck we need to reshuffle
            if (this.cardPulled >= this.CommunityCardsActions.Count) this.ShuffleCards();

            theCurrentBank = Banker.access();
            string drawedCord = draw_card(player);
            return base.landOn(ref player) + String.Format(drawedCord);
        }
Ejemplo n.º 26
0
        public bool getInputYN(Player player, string sQuestion)
        {
            Console.WriteLine(playerPrompt(player) + sQuestion);
            Console.Write("y/n>");
            string resp = Console.ReadLine().ToUpper();

            switch (resp)
            {
                case "Y":
                    return true;
                case "N":
                    return false;
                default:
                    Console.WriteLine("That answer cannot be understood. Please answer 'y' or 'n'.");
                    this.getInputYN(player, sQuestion);
                    return false;
            }
        }
Ejemplo n.º 27
0
        public void displayPlayerChoiceMenu(Player player)
        {
            int resp = 0;
            Console.WriteLine("\n{0}Please make a selection:\n", playerPrompt(player));
            Console.WriteLine("1. Finish turn");
            Console.WriteLine("2. View your details");
            Console.WriteLine("3. Purchase This Property");
            Console.WriteLine("4. Buy House for Property");
            Console.WriteLine("5. Trade Property with Player");
            Console.Write("(1-5)>");
            //read response
            resp = inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
                this.displayPlayerChoiceMenu(player);

            //perform choice according to number input
                switch (resp)
                {
                    case 1:
                        break;
                    case 2:
                        Console.WriteLine("==================================");
                        Console.WriteLine(player.FullDetailsToString());
                        Console.WriteLine("==================================");
                        this.displayPlayerChoiceMenu(player);
                        break;
                    case 3:
                        this.purchaseProperty(player);
                        this.displayPlayerChoiceMenu(player);
                        break;
                    case 4:
                        this.buyHouse(player);
                        this.displayPlayerChoiceMenu(player);
                        break;
                    case 5:
                        this.tradeProperty(player);
                        this.displayPlayerChoiceMenu(player);
                        break;
                    default:
                        Console.WriteLine("That option is not avaliable. Please try again.");
                        this.displayPlayerChoiceMenu(player);
                        break;
                }
        }
Ejemplo n.º 28
0
 public virtual void payRent(ref Player player)
 {
     player.pay(this.getRent());
     this.getOwner().receive(this.getRent());
 }
Ejemplo n.º 29
0
        public Player displayPlayerChooser(ArrayList players, Player playerToExclude, String sPrompt)
        {
            //if no players return null
            if (players.Count == 0)
                return null;
            Console.WriteLine(sPrompt);
            //Create a new arraylist to display
            ArrayList displayList = new ArrayList(players);

            //remove the player to exlude
            displayList.Remove(playerToExclude);

            //go through and display each
            for (int i = 0; i < displayList.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, displayList[i].ToString());
            }
            //display prompt
            Console.Write("({0}-{1})>", 1, displayList.Count);
            //get input
            int resp = this.inputInteger();

            //if outside of range
            if ((resp < 1) || (resp > displayList.Count))
            {
                Console.WriteLine("That option is not avaliable. Please try again.");
                this.displayPlayerChooser(players, playerToExclude, sPrompt);
                return null;
            }
            else
            {
                Player chosenPlayer = (Player) displayList[resp - 1];
                //find the player to return
                foreach (Player p in players)
                {
                    if(p.getName() == chosenPlayer.getName())
                        return p;
                }
                return null;
            }
        }
Ejemplo n.º 30
0
 public void purchaseProperty(Player player)
 {
     //if property available give option to purchase else so not available
     if (Board.access().getProperty(player.getLocation()).availableForPurchase())
     {
         TradeableProperty propertyLocatedOn = (TradeableProperty)Board.access().getProperty(player.getLocation());
         bool respYN = getInputYN(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.getName(), propertyLocatedOn.getPrice()));
         if (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());
     }
 }