public static void Merge(Hotel mergerHotel, List<Hotel> mergingHotels) { foreach (var hotel in mergingHotels) { DividePrizes(hotel); DecideStocks(hotel, mergerHotel); } }
public StockDecision(Player player, Hotel mergingHotel, Hotel mergerHotel, int keeping, int exchanging, int selling) { Player = player; MergingHotel = mergingHotel; MergerHotel = mergerHotel; TotalStocks = player.StockBank.NameStocksDictionary[mergingHotel.Name].Quantity; Keeping = keeping; Exchanging = exchanging; Selling = selling; Debug.Assert(this.Correct()); }
public static void Initialize() { HotelsList = new List<Hotel>(); HotelNameHotelDictionary = new Dictionary<string, Hotel>(); foreach (string hotelName in Hotel.HOTEL_NAMES) { var hotel = new Hotel(hotelName); HotelsList.Add(hotel); HotelNameHotelDictionary.Add(hotelName, hotel); } StockBank = new StockBank(); StockBank.Fill(); }
public void PlayerPutsCard(Player player, TileCard card, TileCardEffect effect, Hotel involvedHotel) { Log(string.Format("{0}: {1} puts {2}", nameof(PlayerPutsCard), player, card)); }
public StockDecision GetStockDecision(Player player, Hotel mergingHotel, Hotel mergerHotel) { return new StockDecision(player, mergingHotel, mergerHotel, player.StockBank.NameStocksDictionary[mergingHotel.Name].Quantity, 0, 0); }
/// <summary> /// Gets the current size of a hotel on board. /// </summary> /// <param name="hotel">The hotel to be checked.</param> /// <returns>The size of the selected hotel.</returns> public static int GetHotelSize(Hotel hotel) { // Maybe need to add hotel-group dictionary to the board. TileGroup group = Board.TileGroups.FirstOrDefault(tg => tg.Hotel == hotel); return group != null ? group.Size : 0; }
/// <summary> /// Setup a new hotel on board. /// </summary> /// <param name="card">The card who caused the setup.</param> /// <param name="involvedHotel">The hotel chosen to be setup.</param> private static void SetUp(TileCard card, Hotel involvedHotel) { card.Tile.Occupied = true; var group = new TileGroup(card.Tile) { Hotel = involvedHotel }; SwallowGroups(card, group); }
/// <summary> /// Merge hotels to one big hotel on board. /// </summary> /// <param name="card">The tile card which caused the merge.</param> /// <param name="involvedHotel">The hotel which swallowes all his neighbor hotels.</param> private static void Merge(TileCard card, Hotel involvedHotel) { card.Tile.Occupied = true; TileGroup group = Board.TileGroups.FirstOrDefault(tg => tg.Hotel == involvedHotel); group.AddTiles(card.Tile); SwallowGroups(card, group); }
/// <summary> /// Enlarge a hotel on board. /// </summary> /// <param name="card">The tile card whose effect is enlarge.</param> /// <param name="involvedHotel"></param> private static void EnlageHotel(TileCard card, Hotel involvedHotel) { // Maybe need to add hotel-group dictionary to the board. card.Tile.Occupied = true; TileGroup group = Board.TileGroups.FirstOrDefault(tg => tg.Hotel == involvedHotel); group.AddTiles(card.Tile); SwallowGroups(card, group); }
/// <summary> /// Putting a tile card on board, by removing the card from the player's bank, /// and calling the BoardManager to handle the effect the card has on the board. /// </summary> /// <param name="player">The player who puts the tile card.</param> /// <param name="card">The tile card being put.</param> /// <param name="effect">Which effect the tile card has on the board.</param> /// <param name="involvedHotel">The main hotel that is being affected by putting the tile card: /// In case of enlarging an hotel, the involved hotel is the hotel being enlarged. In case of setting up a new hotel, the involved hotel /// is the hotel the player decided to setup. In case of a merge effect, the involved hotel is the main hotel that swallows all his neighbor hotels.</param> private static void PutCardOnBoard(Player player, TileCard card, TileCardEffect effect, Hotel involvedHotel) { player.TileCardBank.Remove(card); Output.PlayerPutsCard(player, card, effect, involvedHotel); BoardManager.HandleEffect(card, effect, involvedHotel); }
private static void DecideStocks(Hotel mergingHotel, Hotel mergerHotel) { Player decider = GameManager.CurrentPlayer; StockDecision decision; for (var i = 0; i < GameManager.NumberOfPlayers; i++) { decision = decider.DecideStocks(mergingHotel, mergerHotel); ProcessDecision(decision); decider = GameManager.GetNextPlayer(decider); } }
public static void BuyStocksFromPlayer(Player player, Hotel hotel, int quantity) { TakeStocksFromPlayer(player, hotel.Name, quantity); player.Cash += hotel.CurrentStockValue * quantity; }
private static void ExchangeStocks(Player player, Hotel mergingHotel, Hotel mergerHotel, int mergingHotelStocksExchangedNumber) { Debug.Assert(mergingHotelStocksExchangedNumber % 2 == 0); TakeStocksFromPlayer(player, mergingHotel.Name, mergingHotelStocksExchangedNumber); GiveStocksToPlayer(player, mergerHotel.Name, mergingHotelStocksExchangedNumber / 2); }
private static void DividePrizes(Hotel hotel) { int firstPrize = hotel.CurrentStockValue * 10; int secondPrize = firstPrize / 2; List<Player> firstPrizeReceivers = new List<Player>(); List<Player> secondPrizeReceivers = new List<Player>(); var stocksHolders = GameManager.Players.Where(p => p.StockBank.NameStocksDictionary[hotel.Name].Quantity > 0).OrderByDescending(p => p.StockBank.NameStocksDictionary[hotel.Name].Quantity).Select(p => new { Player = p, Quantity = p.StockBank.NameStocksDictionary[hotel.Name].Quantity }).ToList(); foreach (var p in stocksHolders.Where(p => p.Quantity == stocksHolders.First().Quantity)) { firstPrizeReceivers.Add(p.Player); } if (stocksHolders.Any(p => p.Quantity != stocksHolders.First().Quantity)) { foreach (var pl in stocksHolders.Where(pl => pl.Quantity == stocksHolders.First(p => p.Quantity != stocksHolders.First().Quantity).Quantity)) { secondPrizeReceivers.Add(pl.Player); } } else secondPrizeReceivers.AddRange(firstPrizeReceivers); foreach (var p in firstPrizeReceivers) GivePrize(p, firstPrize, true); foreach (var p in secondPrizeReceivers) GivePrize(p, secondPrize, false); }
public void PlayerSetsUpHotel(Player player, Hotel setUpHotel) { Log(string.Format("{0}: {1} sets up {2}", nameof(PlayerSetsUpHotel), player, setUpHotel)); }
/// <summary> /// Handles the effect of a newly put tile card on the board. /// This method happens after all the prerequisites for putting the new card are met. /// </summary> /// <param name="card">The newly put tile card.</param> /// <param name="effect">The effect this tile card has on the board, which was calculated earlier.</param> /// <param name="involvedHotel">The main hotel that is being affected by putting the tile card: /// In case of enlarging an hotel, the involved hotel is the hotel being enlarged. In case of setting up a new hotel, the involved hotel /// is the hotel the player decided to setup. In case of a merge effect, the involved hotel is the main hotel that swallows all his neighbor hotels.</param> public static void HandleEffect(TileCard card, TileCardEffect effect, Hotel involvedHotel) { switch (effect) { case TileCardEffect.None: PutTile(card); break; case TileCardEffect.Enlarge: EnlageHotel(card, involvedHotel); break; case TileCardEffect.SetUp: SetUp(card, involvedHotel); break; case TileCardEffect.Merge: Merge(card, involvedHotel); break; default: Debug.Fail("Unknown effect"); break; } Debug.Assert(card.Tile.Occupied == true, "Tile is not occupied as it should be."); }
public StockDecision DecideStocks(Hotel mergingHotel, Hotel mergerHotel) { var decision = (StockDecision)GameManager.Input.GetStockDecision(this, mergingHotel, mergerHotel); GameManager.Output.PlayerStockDecision(this, decision); return decision; }
/// <summary> /// Initialization of some static fields. /// </summary> public static void Initialize() { Neutral = new Hotel(HOTEL_NAME_NEUTRAL); HOTEL_NAMES = new List<string>{ HOTEL_NAME_EUROPLAZA, HOTEL_NAME_CONTINENTAL, HOTEL_NAME_OLYMPIA, HOTEL_NAME_PARK, HOTEL_NAME_LASVEGAS, HOTEL_NAME_REVIERA, HOTEL_NAME_HOLIDAY }; }