Ejemplo n.º 1
0
        //Creates a shuffler object and shuffles the list of Community Chest Cards.
        //The shuffle list is than stored in a stack for use when drawing the cards.
        public static void LoadCards()
        {
            shuffler = new Shuffler <CommunuityChestCards>(CommunuityChestCards.LoadCommunityChestCardFromFile());
            List <CommunuityChestCards> cardsToStack = shuffler.GetNewShuffle();

            foreach (CommunuityChestCards card in cardsToStack)
            {
                chestCards.Push(card);
            }
        }
        //Initiate Card Effect
        public void CardEffect(Player player, CommunuityChestCards card)
        {
            int amount = card.GetCommunuityChestEffect();

            if (amount < 0)
            {
                amount = Math.Abs(amount);
                player.RemoveMoney(amount);
            }
            else
            {
                player.AddMoney(amount);
            }
        }
Ejemplo n.º 3
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();
        }