Beispiel #1
0
        public void BuyLand(Player player, Square land)
        {
            MessageBox.Show(player.name + " buys " + land.name + "\n");
            Console.WriteLine("BuyLand");
            player.addBankAccount(-land.landPrice);

            if (player.BankAccount < 0)
            {
                player.Bankrupt = true;
            }

            land.owner = player;
            String colour = land.colour;

            if (land.colour == "black")                 //railroad
            {
                player.railways++;
            }
            else if (land.colour == "utility")          //electric company or water works
            {
                player.utility++;
            }
            if (player.dominates.ContainsKey(land.colour))
            {
                player.dominates[land.colour]++;
            }
            else
            {
                player.dominates[land.colour] = 1;
            }
        }
Beispiel #2
0
 // Change money amount(increase or decrease)
 public void ChangeMoney(Player player, int money)
 {
     //MessageBox.Show(player.name + " loses $" + losingMoney + "\n");
     player.addBankAccount(money);;
     if (player.BankAccount < 0)
     {
         player.Bankrupt = true;
         MessageBox.Show(player.name + " gets out of the game. \n");
     }
 }
Beispiel #3
0
 public void BuyHouse(Player player, Square land)
 {
     MessageBox.Show(player.name + " updates house on " + land.name + "\n");
     Console.WriteLine("BuyHouse");
     player.addBankAccount(-land.housePrice);
     if (player.BankAccount < 0)   //bankcrupt
     {
         player.Bankrupt = true;
     }
     land.building++;
 }
Beispiel #4
0
        // if the land is owned by other player, current player transform some money to land owner
        // if the land is empty, current player has chance to buy land
        // if current player has every property with that colour, he can build a hotel.
        public void LandAnalysis(Player player)
        {
            int    location = player.location;
            Square land     = lands[location];

            if (land.owner == null)
            {
                if (player.BankAccount >= land.landPrice)
                {
                    player.couldBuyLand = true;
                }
            }
            else if (land.owner != player)
            {
                int total;
                if (land.colour == "black")         //railroad
                // 2 ^ railways-1 because
                // for 1 => (2^0) railway we get 25, for 2 => (2^1)*25 = 50, for 3 => (2^2)*25 = 100, for 4 => (2^3)*25 = 200
                {
                    total = (int)Math.Pow(2, land.owner.railways - 1) * 25;
                }
                else if (land.colour == "utility") //electric company or water works
                {
                    if (land.owner.utility > 1)    //if both 2 utilities are owned
                    {
                        total = 10 * (dice1Value + dice2Value);
                    }
                    else
                    {
                        total = 4 * (dice1Value + dice2Value);
                    }
                }
                else
                {
                    total = land.passLand + land.passHouse * land.building;     //standard payment plus number of houses multiplied by houses' value
                }
                player.addBankAccount(-total);
                land.owner.addBankAccount(total);
                MessageBox.Show(player.name + " pays " + total + " to " + land.owner.name + "\n");
                if (player.BankAccount < 0)
                {
                    player.Bankrupt = true;
                    MessageBox.Show(player.name + " gets out of the game because he/she is bankrupt\n");
                }
            }
            else if (land.colour == "black")        //railroad
            {
                Console.WriteLine("Cannot buy house");
            }
            else if (land.colour == "utility")      //electric company or water works
            {
                Console.WriteLine("Cannot buy house");
            }
            // can buy house when all 3 properties of the same colour are owned
            else if (player.dominates[land.colour] > 2 && land.building < 2)
            {
                if (player.BankAccount >= land.housePrice)
                {
                    player.couldBuyHouse = true;
                }
                Console.WriteLine("Can buy house");
            }
            // can buy house when all 2 properties of the same colour are owned as blue and brown regions have only 2 properties
            else if (player.dominates[land.colour] > 1 && land.building < 1 && (land.colour == "blue" || land.colour == "brown"))
            {
                if (player.BankAccount >= land.housePrice)
                {
                    player.couldBuyHouse = true;
                }
                Console.WriteLine("Can buy house");
            }
        }
Beispiel #5
0
 public void AddSalary(Player player)
 {
     player.addBankAccount(200);
     MessageBox.Show(player.name + " gains 200\n");
 }