Esempio n. 1
0
 public void ExchangeField(Player owner, Player buyer, IRentableField field)
 {
     if (Level > 0)
     {
         throw new InvalidOperationException("You have to sell all your houses before its possible to exchange with other players");
     }
     if (owner.Name == buyer.Name)
     {
         throw new ArgumentException("You can't Exchange with yourself");
     }
     if (field.Owner.Name != buyer.Name)
     {
         throw new ArgumentException("The Buyer has to own the " + field.Name);
     }
     if (owner.Name != this.Owner.Name)
     {
         throw new ArgumentException("The Player " + owner.Name + " does not own this field");
     }
     owner.AddToOwnerShip(field);
     buyer.RemoveFromOwnerShip(field);
     owner.RemoveFromOwnerShip(this);
     buyer.AddToOwnerShip(this);
     this.Owner = buyer;
     field.SetOwner(owner);
 }
Esempio n. 2
0
 public void AuctionField(IRentableField rentableField, Dictionary <Player, int> bid)
 {
     if (SameBid(bid))
     {
         throw new ArgumentException("The Players have the same bid value");
     }
     if (_auction.Contains(rentableField) == false)
     {
         throw new ArgumentException("This field is not available for the auction");
     }
     rentableField.BuyInAuction(GetHighestbidPlayer(bid), GetHighestBidValue(bid));
 }
        public void RemoveFromOwnerShip(IRentableField fieldToRemove)
        {
            int indexToRemove = 0;

            for (int i = 0; i < OwnerShip.Count(); i++)
            {
                if (fieldToRemove.Name == OwnerShip[i].Name)
                {
                    indexToRemove = i;
                }
            }
            _ownerShip.RemoveAt(indexToRemove);
        }
        private static void ExchangeField(Game game)
        {
            //Property
            Console.WriteLine("Choose the Property you want to Exchange");
            for (int s = 0; s < game.CurrentPlayer.OwnerShip.Count(); s++)
            {
                IRentableField field = (StreetField)game.CurrentPlayer.OwnerShip[s];
                Console.WriteLine(s + ". " + field.Name);
            }
            Console.Write("PropertyNum: ");
            int propetyIndex = int.Parse(Console.ReadLine());

            //Player
            Console.WriteLine("Choose the Player you want to Exchange With");
            for (int i = 0; i < game.Players.Count(); i++)
            {
                Console.WriteLine(i + ". " + game.Players[i].Name);
            }
            int playerNum = int.Parse(Console.ReadLine());

            //Money Or Field
            Console.WriteLine("Do you want to exchange with Money(m) or another Property(p)");
            string decision = Console.ReadLine();


            if (decision == "m")
            {
                //Amont of Money
                Console.Write("How Much Money: ");
                int amount = int.Parse(Console.ReadLine());
                //Exchange
                game.CurrentPlayer.OwnerShip[propetyIndex].ExchangeField(game.CurrentPlayer, game.Players[playerNum], amount);
            }
            else if (decision == "p")
            {
                //Property
                Console.WriteLine("Choose the Property the other player wants to Pay with");
                for (int s = 0; s < game.Players[playerNum].OwnerShip.Count(); s++)
                {
                    Console.WriteLine(s + ". " + game.Players[playerNum].OwnerShip[s]);
                }
                Console.WriteLine("propNum: ");
                int propNum = int.Parse(Console.ReadLine());
                game.CurrentPlayer.OwnerShip[propetyIndex].ExchangeField(game.CurrentPlayer, game.Players[playerNum], game.Players[playerNum].OwnerShip[propNum]);
            }
        }
 public void ExchangeField(Player owner, Player buyer, IRentableField field)
 {
     if (owner.Name == buyer.Name)
     {
         throw new ArgumentException("You can't Exchange with yourself");
     }
     if (field.Owner.Name != buyer.Name)
     {
         throw new ArgumentException("The Buyer has to own the " + field.Name);
     }
     if (owner.Name != this.Owner.Name)
     {
         throw new ArgumentException("The Player " + owner.Name + " does not own this field");
     }
     owner.AddToOwnerShip(field);
     buyer.RemoveFromOwnerShip(field);
     owner.RemoveFromOwnerShip(this);
     buyer.AddToOwnerShip(this);
     this.Owner = buyer;
     field.SetOwner(owner);
 }
 private void MortageButton(object sender, RoutedEventArgs e)
 {
     try
     {
         IRentableField field = (IRentableField)selectedField;
         if ((field).IsMortage == false)
         {
             (field).TakeMortage(_game.CurrentPlayer);
             MessageBox.Show("You took a mortage on " + field.Name + " and got " + field.MortageValue + "$");
         }
         else
         {
             (field).PayOffMortage(_game.CurrentPlayer);
             MessageBox.Show("You payed of your mortage on " + field.Name + " and payed " + (field.MortageValue + field.MortageValue * 0.1) + "$");
         }
         _monopolyField.Update();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 public void AddToOwnerShip(IRentableField streetField)
 {
     _ownerShip.Add(streetField);
 }