コード例 #1
0
ファイル: Publisher.cs プロジェクト: ophirbushi/Acquire
 public void PlayerReceivedCard(Player player, TileCard card, DidPlayerReceiveCard didPlayerReceiveCard)
 {
     if (didPlayerReceiveCard == DidPlayerReceiveCard.Received && card != null)
     {
         Log(string.Format("{0}: {1} received {2}", nameof(PlayerReceivedCard), player, card));
     }
     else
     {
         Log(string.Format("{0}: {1} did not take a card, reason - {2}", nameof(PlayerReceivedCard), player, didPlayerReceiveCard));
     }
 }
コード例 #2
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Gets the effect a specific tile card will cause, if the card is to be put on board.
 /// </summary>
 /// <param name="card">The card whose effect is checked.</param>
 /// <returns>The effect the card is to cause, if is to be put on board.</returns>
 public static TileCardEffect GetEffect(TileCard card)
 {
     List<TileGroup> neighbors = GetNeighbors(card);
     if (neighbors.Count == 0)
         return TileCardEffect.None;
     else if (!neighbors.Any(group => group.Hotel != Hotel.Neutral))
         return TileCardEffect.SetUp;
     else if (neighbors.Any(group => group.Hotel != Hotel.Neutral &&
         group.Hotel != neighbors.First(g => g.Hotel != Hotel.Neutral).Hotel))
         return TileCardEffect.Merge;
     else
         return TileCardEffect.Enlarge;
 }
コード例 #3
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Gets the hotel being enlarged by a certain tile card.
 /// </summary>
 /// <param name="card">The tile card whose effect on board is enlarge.</param>
 /// <returns>The hotel to be enlarged by the tile card.</returns>
 public static Hotel GetEnlargedHotel(TileCard card)
 {
     Debug.Assert(GetEffect(card) == TileCardEffect.Enlarge, "wrong effect");
     return GetNeighbors(card).First(group => group.Hotel != Hotel.Neutral).Hotel;
 }
コード例 #4
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Make a specific tile group swallow all its neighboring groups.
 /// </summary>
 /// <param name="swallowingCard">The tile card which causes the swallowing of the other groups.</param>
 /// <param name="swallowingGroup">The group which swallows all its neighboring groups.</param>
 private static void SwallowGroups(TileCard swallowingCard, TileGroup swallowingGroup)
 {
     swallowingCard.Tile.Hotel = swallowingGroup.Hotel;
     var neighboringGroups = new List<TileGroup>();
     foreach (var neighbor in swallowingCard.Point.Neighbors)
     {
         if (Board.PointGroupDictionary.ContainsKey(neighbor) &&
             !neighboringGroups.Contains(Board.PointGroupDictionary[neighbor]) &&
             Board.PointGroupDictionary[neighbor] != swallowingGroup)
         {
             neighboringGroups.Add(Board.PointGroupDictionary[neighbor]);
         }
     }
     foreach (var group in neighboringGroups)
     {
         group.Tiles.ForEach(tile => Board.PointGroupDictionary.Remove(tile.Point));
         group.Tiles.ForEach(tile => tile.Hotel = swallowingGroup.Hotel);
         group.Tiles.ForEach(tile => Board.PointGroupDictionary.Add(tile.Point, swallowingGroup));
         swallowingGroup.AddTiles(group.Tiles);
         Board.TileGroups.Remove(group);
     }
     NotifyGroupChanged(swallowingGroup);
 }
コード例 #5
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <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);
 }
コード例 #6
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
        /// <summary>
        /// Puts a new tile on board.
        /// </summary>
        /// <param name="card">The tile card representing the tile to be put.</param>
        private static void PutTile(TileCard card)
        {
            card.Tile.Occupied = true;
            var group = new TileGroup(card.Tile);

            // Only for the pre-game putting of tiles where neighboring tiles do not set-up a new hotel.
            SwallowGroups(card, group);
        }
コード例 #7
0
ファイル: GameManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Performing a merge of hotels.
 /// </summary>
 /// <param name="card">The tile card which caused the merge.</param>
 /// <returns>The hotel which swallowed the other hotels.</returns>
 private static Hotel Merge(TileCard card)
 {
     List<Hotel> mergingHotels = BoardManager.GetMergingHotels(card);
     Hotel mergerHotel = HotelsManager.DetermineMerger(mergingHotels);
     if (mergerHotel == null)
     {
         mergerHotel = CurrentPlayer.SelectMergerHotel(mergingHotels);
     }
     mergingHotels.Remove(mergerHotel);
     HotelsManager.Merge(mergerHotel, mergingHotels);
     return mergerHotel;
 }
コード例 #8
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Checks if two tile cards are neighbors.
 /// </summary>
 /// <param name="card1">The first card.</param>
 /// <param name="card2">The second card.</param>
 /// <returns>Whether or not the tile cards are neighbors.</returns>
 private static bool AreNeighbors(TileCard card1, TileCard card2)
 {
     return card1.Point.Neighbors.Contains(card2.Point);
     //return (card1.X == card2.X && Math.Abs(card1.Y - card2.Y) == 1) ||
     //    (Math.Abs(card1.X - card2.X) == 1 && card1.Y == card2.Y);
 }
コード例 #9
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <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);
 }
コード例 #10
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Checks to see if a tile card whose effect on board is merge is legel (Not merging 2 or more immune hotels).
 /// </summary>
 /// <param name="card">The tile card whose effect on board is merge.</param>
 /// <returns>Whether or not the merge effect of the card, if put on board, is legal.</returns>
 public static bool IsMergeLegal(TileCard card)
 {
     Debug.Assert(GetEffect(card) == TileCardEffect.Merge);
     var neighbors = GetNeighbors(card);
     var immuneHotels = neighbors.Where(group => group.Hotel != Hotel.Neutral && group.Hotel.CurrentSize > 10).ToList();
     return immuneHotels.Count < 2;
 }
コード例 #11
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Replaces an illegal tile card given by a player with a card from the TileCardBank, if there are still cards left.
 /// This method assumes that the tile card it receives is indeed illegal. 
 /// </summary>
 /// <param name="player">The player who wants to replace his illegal card.</param>
 /// <param name="card">The illegal card to replace.</param>
 public static void ReplaceCard(Player player, TileCard card)
 {
     GameManager.Output.ReplaceCard(player, card);
     player.TileCardBank.Remove(card);
     GiveCards(player, 1);
 }
コード例 #12
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <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.");
 }
コード例 #13
0
ファイル: GameManager.cs プロジェクト: ophirbushi/Acquire
 /// <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);
 }
コード例 #14
0
ファイル: GameManager.cs プロジェクト: ophirbushi/Acquire
 /// <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;
     }
 }
コード例 #15
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Gets the hotels involved in a merge caused by a tile card.
 /// </summary>
 /// <param name="card">The merging tile card.</param>
 /// <returns>The hotels involved in a merge caused by a tile card.</returns>
 public static List<Hotel> GetMergingHotels(TileCard card)
 {
     return GetNeighbors(card).Where(group => group.Hotel != Hotel.Neutral).Select(g => g.Hotel).ToList();
 }
コード例 #16
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <summary>
 /// Gets all the tile groups who are neighbors of a specific tile card.
 /// </summary>
 /// <param name="card">The tile card whose neighbors are sought.</param>
 /// <returns>All the tile groups who are neighbors of a specific tile card.</returns>
 private static List<TileGroup> GetNeighbors(TileCard card)
 {
     var neighbors = new List<TileGroup>();
     foreach (BoardPoint p in card.Point.Neighbors.Where(p =>
         Board.PointGroupDictionary.ContainsKey(p) &&
         !neighbors.Contains(Board.PointGroupDictionary[p])))
     {
         neighbors.Add(Board.PointGroupDictionary[p]);
     }
     return neighbors;
 }
コード例 #17
0
ファイル: Publisher.cs プロジェクト: ophirbushi/Acquire
 public void PlayerPutsCard(Player player, TileCard card, TileCardEffect effect, Hotel involvedHotel)
 {
     Log(string.Format("{0}: {1} puts {2}", nameof(PlayerPutsCard), player, card));
 }
コード例 #18
0
ファイル: BoardManager.cs プロジェクト: ophirbushi/Acquire
 /// <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);
 }
コード例 #19
0
ファイル: Publisher.cs プロジェクト: ophirbushi/Acquire
 public void ReplaceCard(Player player, TileCard card)
 {
 }
コード例 #20
0
ファイル: GameManager.cs プロジェクト: ophirbushi/Acquire
 /// <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;
     }
 }