public Tuple <ReturnState, Dictionary <MoneyType, int> > SellProperty(LandCard landCard, PropertyType type, int number) { if (_landCards.Contains(landCard) && landCard.ValidateSellProperty(type, number)) { int price = landCard.SellPrice(type, number); Tuple <ReturnState, Dictionary <MoneyType, int> > resp = AddMoneyToPlayer(price); if (resp.Item1 == ReturnState.Success) { landCard.RemoveProperties(type, number); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(resp.Item1, resp.Item2)); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.ValidateSellPropertyError, null)); }
public Tuple <ReturnState, Dictionary <MoneyType, int> > MortgageLand(LandCard landCard) { if (_landCards.Contains(landCard) && NumberOfProperty(landCard) == 0) { int price = landCard.MortgagePrice; Tuple <ReturnState, Dictionary <MoneyType, int> > resp = AddMoneyToPlayer(price); if (resp.Item1 == ReturnState.Success) { _landCards.Remove(landCard); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(resp.Item1, resp.Item2)); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.MortgageError, null)); }
public Tuple <ReturnState, Dictionary <MoneyType, int> > BuyLand(LandCard landCard, LandCell landCell) { if (!_landCards.Contains(landCard)) { int price = landCell.Price; if (TotalMoney < price) { return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.InsufficientMoney, null)); } Tuple <ReturnState, Dictionary <MoneyType, int> > resp = DeductMoneyFromPlayer(price); if (resp.Item1 == ReturnState.Success) { _landCards.Add(landCard); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(resp.Item1, resp.Item2)); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.LandAlreadyBoughtError, null)); }
public Tuple <ReturnState, Dictionary <MoneyType, int> > BuyProperty(LandCard landCard, PropertyType type, int number) { // check if landCard in _landCards; if (_landCards.Contains(landCard) && (landCard.ValidateBuyProperty(type, number))) { int price = landCard.BuyPrice(type, number); if (TotalMoney < price) { return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.InsufficientMoney, null)); } Tuple <ReturnState, Dictionary <MoneyType, int> > resp = DeductMoneyFromPlayer(price); if (resp.Item1 == ReturnState.Success) { landCard.AddProperties(type, number); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(resp.Item1, resp.Item2)); } return(new Tuple <ReturnState, Dictionary <MoneyType, int> >(ReturnState.ValidateBuyPropertyError, null)); }
private int NumberOfProperty(LandCard landCard) { return(landCard.Properties.Count); }
public void LandOnCellStepped(object sender, EventArgs evt) { LandCell cell = (LandCell)sender; MonopolyPlayer player = GetPlayerFromCell(cell); LandCard card = _cellToCardLink[cell]; Console.WriteLine(player.Username + " stepped in " + cell.Name); Tuple <ReturnState, Dictionary <MoneyType, int> > buyState; string resp; // Check for ownership if (_cellsOwner[cell] == null) // If not owned by anyone { Console.Write("Do you want to buy this land? (y/n)"); resp = Console.ReadLine(); if (!resp.Equals("y") && !resp.Equals("Y")) { return; } buyState = player.BuyLand(card, cell); if (buyState.Item1 != ReturnState.Success) { Console.WriteLine("Error while buy this land"); } else { _bank.DepositMoney(buyState.Item2); } } else if (_cellsOwner[cell] != player) // If owned by other player { Console.WriteLine("This cell is owned by " + _cellsOwner[cell].Username); // Current player need to pay rent to the cell owner if (!TransferMoneyToPlayer(player, card.RentPrice, _cellsOwner[cell])) { GameLose(player); } return; } else if (_cellsOwner[cell] == null) // If owned by himself { if (card.Properties.Count < 4) { // Ask player want to buy house or not? Console.Write("Do you want to buy house(s) on this land? (y/n)"); resp = Console.ReadLine(); Console.WriteLine(); if (!resp.Equals("y") && !resp.Equals("Y")) { return; } // Buy house 1-4 int parsed = -1; while (parsed < 1 || parsed > 4) { Console.Write("How many? (1-4)"); parsed = int.Parse(Console.ReadLine()); } buyState = player.BuyProperty(card, PropertyType.House, parsed); if (buyState.Item1 != ReturnState.Success) { Console.WriteLine("Error while buy house on this land"); } else { _bank.DepositMoney(buyState.Item2); } } else if (card.Properties.Count == 4) { // Ask player want to buy hotel or not? Console.Write("Do you want to buy hotel on this land? (y/n)"); resp = Console.ReadLine(); Console.WriteLine(); if (!resp.Equals("y") && !resp.Equals("Y")) { return; } // Buy hotel buyState = player.BuyProperty(card, PropertyType.Hotel, 1); if (buyState.Item1 != ReturnState.Success) { Console.WriteLine("Error while buy hotel on this land"); } else { _bank.DepositMoney(buyState.Item2); } } } else { Console.WriteLine("Undefined behavior"); return; } }