예제 #1
0
파일: Railroad.cs 프로젝트: knw7x9/M0N0P0LY
        /// <summary>
        /// Sets the rent due when landing on a railroad property
        /// </summary>
        /// <param name="railroad1">one of the railroads</param>
        /// <param name="railroad2">one of the railroads</param>
        /// <param name="railroad3">one of the railroads</param>
        /// <param name="railroad4">one of the railroads</param>
        /// <param name="advanceToNearestRailroad">whether or not the player is advancing to the nearest railroad</param>
        public void CalculateRent(Railroad railroad1, Railroad railroad2, Railroad railroad3, Railroad railroad4, bool advanceToNearestRailroad)
        {
            // an array of the railroads owned
            bool[] railroadsOwned = { false, false, false, false };

            //Updates the array depending on which railroads are owned on the gameboard
            railroadsOwned[0] = railroad1.IsOwned;
            railroadsOwned[1] = railroad2.IsOwned;
            railroadsOwned[2] = railroad3.IsOwned;
            railroadsOwned[3] = railroad4.IsOwned;

            // Counts the number of railroads owned
            int count = 0;

            for (int i = 0; i < railroadsOwned.Length; i++)
            {
                if (railroadsOwned[i] == true)
                {
                    count++;
                }
            }

            if (advanceToNearestRailroad)
            {
                Rent = AmountOfRent(count, 25) * 2;
                advanceToNearestRailroad = false;
            } //Gets the rent based on the number of railroads owned on the board
            else
            {
                Rent = AmountOfRent(count, 25);
            }
        }
예제 #2
0
파일: Property.cs 프로젝트: knw7x9/M0N0P0LY
        /// <summary>
        /// Pays rent to the owner and takes the rent away from the current player
        /// </summary>
        /// <param name="player">the current player's turn</param>
        private void PayRent(Player player)
        {
            // Check if a utility, and calculates the rent
            if (GetType() == typeof(Utility))
            {
                Utility currentUtility = (Utility)this;
                currentUtility.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], currentUtility.NearstUtility);
            }
            // Checks if a railroad, and and calculates the rent
            if (GetType() == typeof(Railroad))
            {
                Railroad currentRailroad = (Railroad)this;
                currentRailroad.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15],
                                              (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], currentRailroad.NearestRailroad);
            }
            // Takes the money away from the current player
            player.Money -= Rent;

            // Pays rent to the owner
            foreach (Player plyr in GameLoop.getInstance().Gameboard.Players)
            {
                if (plyr == Owner)
                {
                    plyr.Money += Rent;
                    break;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Display the pay rent form or the purchase property form
        /// </summary>
        /// <param name="player">Current player</param>
        /// <param name="property">Property tile that the current player landed on</param>
        private void DisplayPayRentOrPurchasePropertyForm(Player player, Property property)
        {
            Player propertyOwner = property.Owner;

            // if a property and is not owned, call the purchase property form
            if (propertyOwner == null)
            {
                // Figured out how to center windows with respect to their predecessors:
                // https://stackoverflow.com/questions/4306593/wpf-how-to-set-a-dialog-position-to-show-at-the-center-of-the-application
                PurchaseProperty purchaseProperty = new PurchaseProperty();
                purchaseProperty.Owner = this;

                // Output information to the purchase property form
                purchaseProperty.tbOutputName.Text  = player.Name;
                purchaseProperty.tbOutputMoney.Text = string.Format("{0:$#,##0}", player.Money);
                foreach (Property proprty in player.PropertiesOwned)
                {
                    purchaseProperty.lbOutputPropertiesOwned.Items.Add(proprty.Name);
                }
                purchaseProperty.tbOutputCostOfProperty.Text = property.Cost.ToString("c0");
                if (player.Money >= property.Cost)
                {
                    purchaseProperty.tbUserInformation.Text = "Would you like to buy " + property.Name + "?";
                }
                else
                {
                    purchaseProperty.tbUserInformation.Text = "Sorry, you do not have enough money to purchase " + property.Name + ".";
                    purchaseProperty.btnYesBuy.IsEnabled    = false;
                }
                purchaseProperty.ShowDialog();
            } // if the current player owns the property, do nothing
            else if (propertyOwner.Name == player.Name)
            {
            } // if another player owns the property, call the PayRent form
            else
            {
                PayRent payRent = new PayRent();
                payRent.Owner = this;

                // Output information to pay rent form
                payRent.tbOutputName.Text      = player.Name;
                payRent.tbOutputMoney.Text     = string.Format("{0:$#,##0}", player.Money);
                payRent.tbOutputPayRentTo.Text = propertyOwner.Name;

                // Calculates the rent for utility or railroad property before output to the pay rent form
                if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Utility))
                {
                    Utility utilityProperty = (Utility)property;
                    utilityProperty.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], utilityProperty.NearstUtility);
                }
                else if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Railroad))
                {
                    Railroad railroadProperty = (Railroad)property;
                    railroadProperty.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15],
                                                   (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], railroadProperty.NearestRailroad);
                }
                payRent.tbOutputRentIsHowMuch.Text = property.Rent.ToString("c0");
                payRent.ShowDialog();
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes all the tiles in the game and stores them in order.
        /// </summary>
        private void InitializeTileOrder()
        {
            _TileOrder = new Tile[40];

            _TileOrder[0]  = new PassGo();
            _TileOrder[1]  = new Basic("Mediterranean Avenue", 60, 2);
            _TileOrder[2]  = new CardSpace("Community Chest");
            _TileOrder[3]  = new Basic("Baltic Avenue", 80, 4);
            _TileOrder[4]  = new FreeParking("Income Tax"); //IncomeTax
            _TileOrder[5]  = new Railroad("Reading Railroad", 200, 25);
            _TileOrder[6]  = new Basic("Oriental Avenue", 100, 6);
            _TileOrder[7]  = new CardSpace("Chance");
            _TileOrder[8]  = new Basic("Vermont Avenue", 100, 6);
            _TileOrder[9]  = new Basic("Connecticut Avenue", 120, 8);
            _TileOrder[10] = new Jail();
            _TileOrder[11] = new Basic("St. Charles Place", 140, 10);
            _TileOrder[12] = new Utility("Electric Company", 150, 1);
            _TileOrder[13] = new Basic("States Avenue", 140, 10);
            _TileOrder[14] = new Basic("Virginia Avenue", 160, 12);
            _TileOrder[15] = new Railroad("Pennsylvania Railroad", 200, 25);
            _TileOrder[16] = new Basic("St. James Place", 180, 14);
            _TileOrder[17] = new CardSpace("Community Chest");
            _TileOrder[18] = new Basic("Tennessee Avenue", 180, 14);
            _TileOrder[19] = new Basic("New York Avenue", 200, 16);
            _TileOrder[20] = new FreeParking();
            _TileOrder[21] = new Basic("Kentucky Avenue", 220, 18);
            _TileOrder[22] = new CardSpace("Chance");
            _TileOrder[23] = new Basic("Indiana Avenue", 220, 18);
            _TileOrder[24] = new Basic("Illinois Avenue", 240, 20);
            _TileOrder[25] = new Railroad("B & O Railroad", 200, 25);
            _TileOrder[26] = new Basic("Atlantic Avenue", 260, 22);
            _TileOrder[27] = new Basic("Ventnor Avenue", 260, 22);
            _TileOrder[28] = new Utility("Water Works", 150, 1);
            _TileOrder[29] = new Basic("Marvin Gardens", 280, 24);
            _TileOrder[30] = new GoToJail();
            _TileOrder[31] = new Basic("Pacific Avenue", 300, 26);
            _TileOrder[32] = new Basic("North Carolina Avenue", 300, 26);
            _TileOrder[33] = new CardSpace("Community Chest");
            _TileOrder[34] = new Basic("Pennsylvania Avenue", 320, 28);
            _TileOrder[35] = new Railroad("Short Line Railroad", 200, 25);
            _TileOrder[36] = new CardSpace("Chance");
            _TileOrder[37] = new Basic("Park Place", 350, 35);
            _TileOrder[38] = new FreeParking("Luxury Tax");   //LuxuryTax
            _TileOrder[39] = new Basic("Boardwalk", 400, 50);
        }
예제 #5
0
 public override void LocationAction(Player player)
 {
     // When the card allows the current player to collect money
     if (ProcessedCard[0, 1] == "Collect")
     {
         // if the current player collects money only once
         if (ProcessedCard[0, 2] == "Once")
         {
             // the current player recieves the money
             int.TryParse(ProcessedCard[0, 3], out int collectedMoney);
             player.Money += collectedMoney;
         } // the current player collects money from every player
         else if (ProcessedCard[0, 2] == "Every")
         {
             int.TryParse(ProcessedCard[0, 3], out int collectedMoney);
             // Take the money away from each player in the list except the current player
             foreach (Player member in GameLoop.getInstance().Gameboard.Players)
             {
                 if (member == player)
                 {
                     continue;
                 }
                 else
                 {
                     member.Money -= collectedMoney;
                     player.Money += collectedMoney;
                 }
             }
         }
     }
     else if (ProcessedCard[0, 1] == "Pay")
     {
         // if the current player collects money only once
         if (ProcessedCard[0, 2] == "Once")
         {
             // the current player pays the money
             int.TryParse(ProcessedCard[0, 3], out int payMoney);
             player.Money -= payMoney;
         } // the current player pays money from every player
         else if (ProcessedCard[0, 2] == "Every")
         {
             int.TryParse(ProcessedCard[0, 3], out int payMoney);
             if (payMoney != 0)
             {
                 // Pay money to each player in the list except the current player
                 foreach (Player member in GameLoop.getInstance().Gameboard.Players)
                 {
                     if (member == player)
                     {
                         continue;
                     }
                     else
                     {
                         member.Money += payMoney;
                         player.Money -= payMoney;
                     }
                 }
             }
         }
     }
     else if (ProcessedCard[0, 1] == "Advance")
     {
         // Move to a direct location
         if (ProcessedCard[0, 2] == "NotNearest")
         {
             string nameOfTile = ProcessedCard[0, 3];
             // if the card specifies to move forward or backwards a certain number of spaces, move the player to this new location
             if (nameOfTile == "Location")
             {
                 int.TryParse(ProcessedCard[0, 5], out int SpacesToMove);
                 int newLocation = player.Location + SpacesToMove;
                 GameLoop.getInstance().Gameboard.Move(player, newLocation);
             }
             else   // move player to specified tile
             {
                 for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++)
                 {
                     // if the tile name equals the name from the processing array, move player to that location
                     if (GameLoop.getInstance().Gameboard.TileOrder[i].Name == nameOfTile)
                     {
                         GameLoop.getInstance().Gameboard.Move(player, i);
                         if (nameOfTile == "Jail")
                         {
                             player.IsInJail = true;
                         }
                         break;
                     }
                 }
             }
         }
         else if (ProcessedCard[0, 2] == "Nearest")
         {
             if (ProcessedCard[0, 3] == "Railroad")
             {
                 // for player locations less than the last railroad on the game board
                 if (player.Location < 35)
                 {
                     for (int i = player.Location + 1; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++)
                     {
                         // move player to nearest railroad and set advance to nearst railroad attribute used to Calculate Rent
                         if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Railroad))
                         {
                             GameLoop.getInstance().Gameboard.Move(player, i);
                             Railroad nearestRailroad = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[i];
                             nearestRailroad.NearestRailroad = true;
                             break;
                         }
                     }
                 } // for player locations greater than or equal to the last railroad on the game board
                 else
                 {
                     for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++)
                     {
                         // move player to nearest railroad, and set advance to nearst railroad attribute used to Calculate Rent
                         if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Railroad))
                         {
                             GameLoop.getInstance().Gameboard.Move(player, i);
                             Railroad nearestRailroad = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[i];
                             nearestRailroad.NearestRailroad = true;
                             break;
                         }
                     }
                 }
             }
             else if (ProcessedCard[0, 3] == "Utility")
             {
                 // for player locations less than the last utility on the game board
                 if (player.Location < 28)
                 {
                     for (int i = player.Location + 1; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++)
                     {
                         // move player to nearest utility, and set advance to nearst utility attribute used to Calculate Rent
                         if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Utility))
                         {
                             GameLoop.getInstance().Gameboard.Move(player, i);
                             Utility nearestUtility = (Utility)GameLoop.getInstance().Gameboard.TileOrder[i];
                             nearestUtility.NearstUtility = true;
                             break;
                         }
                     }
                 } // for player locations greater than or equal to the last utility on the game board
                 else
                 {
                     for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++)
                     {
                         // move player to nearest utility, and set advance to nearst utility attribute used to Calculate Rent
                         if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Utility))
                         {
                             GameLoop.getInstance().Gameboard.Move(player, i);
                             Utility nearestUtility = (Utility)GameLoop.getInstance().Gameboard.TileOrder[i];
                             nearestUtility.NearstUtility = true;
                             break;
                         }
                     }
                 }
             }
         }
     }
 }