示例#1
0
        //Method that is used to determine what the player action should be.
        //Method depends heavliy on what space is sent over.
        public void Action(Space space, GameBoard board, List <Player> players)
        {
            if (space is PropertySpace)
            {
                PropertySpace temp = (PropertySpace)space;
                PropertySpaceAction(temp);
            }
            else if (space is ChanceSpace)
            {
                //Player draws a chance card and the card effect is applied
                ChanceCards card = ChanceSpace.DrawCard();
                MessageBox.Show(card.GetChanceDescription());
                card.CardEffect(this, board, card, players);

                //Activates the property space action when player is moved to a property space.
                if (card.GetChanceEffect() == 2 || card.GetChanceEffect() == 3 || card.GetChanceEffect() == 13 || card.GetChanceEffect() == 12)
                {
                    PropertySpace temp = (PropertySpace)GetSpaceOccupied();
                    PropertySpaceAction(temp);
                }
            }
            else if (space is CommunityChestSpace)
            {
                //Player draws a community chest card and the card effect is applied
                CommunuityChestCards card = CommunityChestSpace.DrawCard();
                MessageBox.Show(card.GetCommunuityChestName());
                card.CardEffect(this, card);
            }
            else if (space is UtilitySpace)
            {
                UtilityAction(space);
            }
            else if (space is FreeParkingSpace)
            {
                //Gives player who landed on free parking the total money given to free parking.
                FreeParkingSpace fpSpace = (FreeParkingSpace)space;
                MessageBox.Show($"Player {playerId} has collect {fpSpace.GetAccumulatedMoney().ToString("C2")}");
                fpSpace.CollectMoney(this);
            }
            else if (space is RailroadSpace)
            {
                RailroadSpace temp = (RailroadSpace)space;
                RailroadSpaceAction(temp);
            }
            else if (space is GoToJailSpace)
            {
                //Sends player to jail space and jails them
                MessageBox.Show("Sent to Jail");
                MovePlayerToSpace(board.GetJailSpace());
                JailSpace jailSpace = (JailSpace)spaceOccupied;

                if (!isJailed)
                {
                    jailSpace.AddPlayerToJail(this);
                }
                else
                {
                    jailSpace.EscapeJail(this);
                }
            }
            else if (space is JailSpace || IsPlayerJailed() == true)
            {
                //If player is jailed, it allows them to attempt escape or if they
                //have a get out of jail free card, they can instantly escape.
                JailSpace jailSpace = (JailSpace)board.GetJailSpace();

                if (HasGetOutOfJailFreeCard())
                {
                    jailSpace.RemovePlayerFromJail(this);
                }

                if (isJailed)
                {
                    jailSpace.EscapeJail(this);
                }
            }

            CheckForLost();
        }
示例#2
0
 //Removes money from player who landed on the utility space and adds it to free parking
 public void RemoveMoneyFromPlayer(Player player)
 {
     FreeParkingSpace.AddMoney(player.RemoveMoneyWithReturn(utility.GetCost()));
 }