public void PlayerPutsCard(Player player, TileCard card, TileCardEffect effect, Hotel involvedHotel) { Log(string.Format("{0}: {1} puts {2}", nameof(PlayerPutsCard), player, card)); }
/// <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."); }
/// <summary> /// Determining which is the mainly involved hotel in putting a specific tile card on board - /// by completing a specific process, which varies by the effect the tile card has on the board. /// </summary> /// <param name="card">The tile card to be put on board.</param> /// <param name="effect">The effect the tile card has on the board.</param> /// <returns>The mainly involved hotel in putting the tile card on board.</returns> private static Hotel PrePuttingProcess(TileCard card, TileCardEffect effect) { switch (effect) { case TileCardEffect.None: return Hotel.Neutral; case TileCardEffect.Enlarge: return BoardManager.GetEnlargedHotel(card); case TileCardEffect.SetUp: Hotel selectedHotel = CurrentPlayer.SelectSetUpHotel(); if (HotelsManager.StockBank.GetNumberOfStocks(selectedHotel.Name) > 0) { HotelsManager.GiveStocksToPlayer(CurrentPlayer, selectedHotel.Name, 1); } return selectedHotel; case TileCardEffect.Merge: return Merge(card); default: Debug.Fail("Unknown effect."); return null; } }
/// <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); }
/// <summary> /// Determining whether or not a tile card is legal at the moment.(Can be put on board), /// and also whether the card's illegal status is permanent, which makes it replaceable. /// </summary> /// <param name="card">The tile card being tested.</param> /// <param name="effect">The effect which the tile card has on the board.</param> /// <param name="replaceAble">Whether or not the card is eligible for replacement since it is permanently illegal.</param> /// <returns>Whether or not the tile card is legal at the moment.</returns> private static bool IsCardLegal(TileCard card, out TileCardEffect effect, out bool replaceAble) { effect = BoardManager.GetEffect(card); replaceAble = false; if (effect == TileCardEffect.Enlarge || effect == TileCardEffect.None) return true; else if (effect == TileCardEffect.SetUp) return HotelsManager.GetAvailableHotels().Count > 0; else { replaceAble = !BoardManager.IsMergeLegal(card); return !replaceAble; } }