Пример #1
0
 public HexagonTileSerializable(HexagonTile source)
 {
     this.Id        = source.Id;
     this.X         = source.X;
     this.Y         = source.Y;
     this.TileType  = source.TileType;
     this.TileValue = source.TileValue;
     this.Fortress  = source.Fortress;
 }
 public HexagonTileSerializable(HexagonTile source)
 {
     this.Id = source.Id;
     this.X = source.X;
     this.Y = source.Y;
     this.TileType = source.TileType;
     this.TileValue = source.TileValue;
     this.Fortress = source.Fortress;
 }
 private HexagonTile GetClone(HexagonTile tile, Game target)
 {
     if (this.hexagonList.IndexOf(tile) >= 0)
     {
         return target.hexagonList[this.hexagonList.IndexOf(tile)];
     }
     else
     {
         return null;
     }
 }
 private void TurnColorInLine(HexagonTile search, Func<HexagonTile, HexagonTile> GetNext)
 {
     HexagonTile next = GetNext(search);
     while (next.TileType != search.TileType)
     {
         next.TileType = search.TileType;
         next = GetNext(next);
     }
 }
        private HexagonTile FindColorInLine(HexagonTile search, Func<HexagonTile, HexagonTile> GetNext)
        {
            TileType found = TileType.none;

            HexagonTile next = GetNext(search);

            if (next == null || next.TileType == search.TileType || next.TileType == TileType.board || next.TileType == TileType.none||next.Fortress)
            {
                return null;
            }

            while (next != null && next.TileType != TileType.board && next.TileType != TileType.none && next.TileType != search.TileType && !next.Fortress)
            {
                found = next.TileType;
                next = GetNext(next);

                // endboard => end search
                if (next == null || next.TileType == TileType.none)
                {
                    return null;
                }
            }

            if (next.TileType == search.TileType)
            {
                if (this.firstCapture == TileType.none)
                {
                    this.firstCapture = found;
                }
                return next;
            }
            return null;
        }
        private void TurnTilesToCurrentColor(HexagonTile chosenTile)
        {
            bool first = (this.firstCapture == TileType.none);

            if (FindColorInLine(chosenTile, f => f.North) != null)
            {
                TurnColorInLine(chosenTile, f => f.North);
            }

            if (FindColorInLine(chosenTile, f => f.NorthEast) != null)
            {
                TurnColorInLine(chosenTile, f => f.NorthEast);
            }

            if (FindColorInLine(chosenTile, f => f.NorthWest) != null)
            {
                TurnColorInLine(chosenTile, f => f.NorthWest);
            }

            if (FindColorInLine(chosenTile, f => f.South) != null)
            {
                TurnColorInLine(chosenTile, f => f.South);
            }

            if (FindColorInLine(chosenTile, f => f.SouthWest) != null)
            {
                TurnColorInLine(chosenTile, f => f.SouthWest);
            }

            if (FindColorInLine(chosenTile, f => f.SouthEast) != null)
            {
                TurnColorInLine(chosenTile, f => f.SouthEast);
            }

            if (first)
            {
                logger.Debug("First move");
                switch (this.firstCapture)
                {
                    case TileType.red:
                        turnOrder.Add(TileType.red);
                        turnOrder.Add(TileType.blue);
                        break;
                    case TileType.blue:
                        turnOrder.Add(TileType.blue);
                        turnOrder.Add(TileType.red);
                        break;
                }
                logger.Debug("The order of turns is: {0}, {1}, {2}", turnOrder[0], turnOrder[1], turnOrder[2]);
            }

            var boardtiles = from p in hexagonList
                             where p.TileType == TileType.board
                             select p;
        }
        private HexagonTile FindChoiceCandidateForDirection(HexagonTile search, Func<HexagonTile, HexagonTile> GetNext)
        {
            HexagonTile next = GetNext(search);

            // skip first
            if (next == null || next.TileType == search.TileType || next.TileType == TileType.board || next.TileType == TileType.none)
            {
                return null;
            }

            while (next.TileType != TileType.board)
            {
                if (next.TileType == search.TileType)
                {
                    return null;
                }

                if (next.Fortress)  // blocks possible moves
                {
                    return null;
                }

                next = GetNext(next);

                // endboard => end search
                if (next == null || next.TileType == TileType.none)
                {
                    return null;
                }
            }

            return next;
        }
 private void AddPosibility(List<HexagonTile> posibilities, HexagonTile tile)
 {
     if (tile != null && !posibilities.Contains(tile))
     {
         posibilities.Add(tile);
     }
 }
        private List<HexagonTile> FindChoiceCandidatesForTile(HexagonTile search, List<HexagonTile> posibilities)
        {
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.North));
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.NorthWest));
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.NorthEast));
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.South));
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.SouthEast));
            AddPosibility(posibilities, FindChoiceCandidateForDirection(search, f => f.SouthWest));

            return posibilities;
        }
Пример #10
0
        private void MapUpTile(HexagonTile tile)
        {
            if (tile.North == null)
            {
                tile.North = FindTileAt((int)tile.X + 0, (int)tile.Y - yFull);
                if (tile.North != null)
                {
                    tile.North.South = tile;
                }
            }

            if (tile.South == null)
            {
                tile.South = FindTileAt((int)tile.X + 0, (int)tile.Y + yFull);
                if (tile.South != null)
                {
                    tile.South.North = tile;
                }
            }

            if (tile.NorthWest == null)
            {
                tile.NorthWest = FindTileAt((int)tile.X - xMarge, (int)tile.Y - yMarge);
                if (tile.NorthWest != null)
                {
                    tile.NorthWest.SouthEast = tile;
                }
            }

            if (tile.NorthEast == null)
            {
                tile.NorthEast = FindTileAt((int)tile.X + xMarge, (int)tile.Y - yMarge);
                if (tile.NorthEast != null)
                {
                    tile.NorthEast.SouthWest = tile;
                }
            }

            if (tile.SouthWest == null)
            {
                tile.SouthWest = FindTileAt((int)tile.X - xMarge, (int)tile.Y + yMarge);
                if (tile.SouthWest != null)
                {
                    tile.SouthWest.NorthEast = tile;
                }
            }

            if (tile.SouthEast == null)
            {
                tile.SouthEast = FindTileAt((int)tile.X + xMarge, (int)tile.Y + yMarge);
                if (tile.SouthEast != null)
                {
                    tile.SouthEast.NorthWest = tile;
                }
            }
        }
Пример #11
0
        public void LoadSaveData(BoardSerializable boardData)
        {
            int id = 0;

            this.Fortresses = boardData.FortressesPerPlayer;

            this.PlayerFortress[0] = boardData.FortressesPerPlayer;
            this.PlayerFortress[1] = boardData.FortressesPerPlayer;
            this.PlayerFortress[2] = boardData.FortressesPerPlayer;

            //Dictionary<HexagonTileSerializable, HexagonTile> mapping = new Dictionary<HexagonTileSerializable, HexagonTile>();

            this.hexagonList.Clear();

            foreach (HexagonTileSerializable serializedTile in boardData.ActiveTileList)
            {
                HexagonTile tile = new HexagonTile()
                {
                    Id = serializedTile.Id,
                    TileType = serializedTile.TileType,
                    X = serializedTile.X,
                    Y = serializedTile.Y,
                    TileValue = serializedTile.TileValue,
                    Fortress = serializedTile.Fortress,
                };

                if (tile.TileType != TileType.none)
                {
                    //mapping.Add(serializedTile, tile);
                    this.hexagonList.Add(tile);
                }
            }

            foreach (HexagonTile tile in hexagonList)
            {
                MapUpTile(tile);
            }

            //this.SetTurn();
        }