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!.");

            }
        }
Пример #2
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);
     }
 }
Пример #3
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();
            }
        }
Пример #4
0
        public static void playerBankruptHandler(object obj, EventArgs args)
        {
            //cast to player
            Player p = (Player)obj;

            //display bankrupt msg
            Console.WriteLine("{0} IS BANKRUPT!", p.getName().ToUpper());
        }
Пример #5
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);
            }
        }
Пример #6
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());

            }
        }
Пример #7
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));
     }
 }
Пример #8
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);
            }
        }
Пример #9
0
        public override void printWinner()
        {
            Player winner = null;

            //get winner who is last active player
            foreach (Player p in Board.access().getPlayers())
            {
                //if player is active
                if (!p.isNotActive())
                {
                    winner = p;
                }
            }
            //display winner
            Console.WriteLine("\n\n{0} has won the game!\n\n", winner.getName());
            //end the game
            this.endOfGame();
        }
Пример #10
0
 public string playerPrompt(Player player)
 {
     return(string.Format("{0}:\t", player.getName()));
 }
Пример #11
0
        public static void playerPassGoHandler(object obj, EventArgs args)
        {
            Player p = (Player)obj;

            Console.WriteLine("{0} has passed go.{0} has received $200", p.getName());
        }
Пример #12
0
        public override void makePlay(int iPlayerIndex)
        {
            AgainPlayerIndex = iPlayerIndex;
            //2.7 Extend use of Delegates and Events by adding at least two new Events to the game.

            Console.Clear();

            //make variable for player
            Player player = Board.access().getPlayer(iPlayerIndex);

            //Change the colour for the player
            Console.ForegroundColor = this.colors[iPlayerIndex];

            //if inactive skip turn
            if (player.isNotActive())
            {
                Console.WriteLine("\n{0} is inactive.\n", player.getName());
                //check players to continue

                //check that there are still two players to continue
                int activePlayerCount = 0;

                foreach (Player p in Board.access().getPlayers())
                {
                    //if player is active
                    if (!p.isNotActive())
                    {
                        //increment activePlayerCount
                        activePlayerCount++;
                    }
                }

                //if less than two active players display winner
                if (activePlayerCount < 2)
                {
                    this.printWinner();
                }

                return;
            }



            //prompt player to make move
            Console.WriteLine("{0}Your turn. Press Enter to make move", playerPrompt(iPlayerIndex));
            Console.ReadLine();
            //move player
            player.move();

            //Display making move
            Console.WriteLine("*****Move for {0}:*****", player.getName());
            //Display rolling
            Console.WriteLine("{0}{1}\n", playerPrompt(iPlayerIndex), player.diceRollingToString());

            Property propertyLandedOn = Board.access().getProperty(player.getLocation());

            //landon property and output to console
            Console.WriteLine(propertyLandedOn.landOn(ref player));
            //Display player details
            Console.WriteLine("\n{0}{1}", playerPrompt(iPlayerIndex), player.BriefDetailsToString());
            //display player choice menu
            displayPlayerChoiceMenu(player);
        }
Пример #13
0
 public virtual string landOn(ref Player player)
 {
     return(String.Format("{0} landed on {1}. ", player.getName(), this.getName()));
 }
Пример #14
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);
            }     
        }
Пример #15
0
 public string playerPrompt(Player player)
 {
     return string.Format("{0}:\t", player.getName());
 }
Пример #16
0
 public virtual string landOn(ref Player player)
 {
     return String.Format("{0} landed on {1}. ", player.getName(), this.getName());
 }
Пример #17
0
        public void test_PlayerGettersAndSetters()
        {
            Banker theTestBanker = new Banker();
             Player theTestPlayer = new Player();

            //hasRolledDoubles bool
            theTestPlayer.get_hasRolledDoubles();
            theTestPlayer.is_hasRolledDoubles();
            theTestPlayer.hasRolledDoubles = true;
            theTestPlayer.not_hasRolledDoubles();

            //paidFine bool
            theTestPlayer.getPaidFine();
            theTestPlayer.isPaidFine();
            theTestPlayer.notPaidFine();

            //landedInJailByThreeStraightDoubles bool
            theTestPlayer.get_LandedInJailByThreeStraightDoubles();
            theTestPlayer.not_LandedInJailByThreeStraightDoubles();
            theTestPlayer.is_LandedInJailByThreeStraightDoubles();

            //inJail bool
            theTestPlayer.getJailStats();
            theTestPlayer.setIsInJail();
            theTestPlayer.setNotInJail();

            //lastMove int
            theTestPlayer.getLastMove();

            theTestPlayer.getLocation();

            theTestPlayer.getName();

            theTestPlayer.getPropertiesOwned();

            theTestPlayer.getBalance();

            theTestPlayer.getBalance();

            theTestPlayer.hasRolledDoublesInJail();

            theTestPlayer.isNotActive();

            theTestPlayer.get_firstTurnInJail();

            theTestPlayer.not_firstTurnInJail();
        }