Пример #1
0
 public bool InMap(Tile tile)
 {
     if (tile == null)
     {
         return false;
     }
     return InMapIndexRegion(tile.Row, tile.Col);
 }
Пример #2
0
 private void removeSelectedTile(Tile tile)
 {
     if (tile != null && selectedTiles.Contains(tile))
     {
         selectedTiles.Remove(tile);
     }
 }
Пример #3
0
 public Point GetTileCenterPoint(Tile tile)
 {
     return GetTileCenterPoint(tile.Row, tile.Col);
 }
Пример #4
0
 private void drawTiles(Graphics g, Pen borderPen, Brush tileBrush, Tile[][] tiles, bool drawNullRegion)
 {
     int sx = mapX, sy = mapY;
     for (int r = 0; r < rows; ++r)
     {
         sx = mapX;
         if (r % 2 != 0)
         {
             sx += sideXMappingLen;
         }
         for (int c = 0; c < cols; ++c)
         {
             Tile tile = tiles[r][c];
             if (tile != null)
             {
                 if (tile.Region != null || drawNullRegion)
                 {
                     Brush brush = tileBrush;
                     if (brush == null)
                     {
                         if (tile.Region != null && tile.Region.Influence != null && tile.Region.Influence.Color != null)
                         {
                             brush = new SolidBrush(tile.Region.Influence.Color);
                         }
                         else
                         {
                             brush = Brushes.Gray;
                         }
                     }
                     fillHexagon(g, brush, sx, sy);
                     drawRegionBorder(g, borderPen, r, c, sx, sy, tiles);
                 }
             }
             sx += (sideXMappingLen + sideXMappingLen);
         }
         sy += (sideYMappingLen + sideLen);
     }
 }
Пример #5
0
 private HashSet<Region> getAroundRegions(Tile tile)
 {
     HashSet<Region> aroundRegions = new HashSet<Region>();
     HashSet<Tile> aroundTiles = getAroundTiles(tile);
     foreach (Tile t in aroundTiles)
     {
         Region region = t.Region;
         if (region != null && region!=tile.Region && !aroundRegions.Contains(region))
         {
             aroundRegions.Add(region);
         }
     }
     return aroundRegions;
 }
Пример #6
0
 private void assignMap(MapHead mh)
 {
     version = mh.Version;
     ScreenWidth = mh.ScreenWidth;
     ScreenHeight = mh.ScreenHeight;
     mapX = mh.MapX;
     mapY = mh.MapY;
     mapW = mh.MapW;
     mapH = mh.MapH;
     sideLen = mh.SideLen;
     sideXMappingLen = mh.SideXMappingLen;
     sideYMappingLen = mh.SideYMappingLen;
     mapRegionW = mh.MapRegionW;
     mapRegionH = mh.MapRegionH;
     mapTiles = new Tile[ScreenHeight][];
     for (int r = 0; r < ScreenHeight; ++r)
     {
         mapTiles[r] = new Tile[ScreenWidth];
     }
 }
Пример #7
0
 private Tile[][] createTilesContainer(int rows, int cols)
 {
     Tile[][] tiles = new Tile[rows][];
     for (int i = 0; i < rows; ++i)
     {
         tiles[i] = new Tile[cols];
     }
     return tiles;
 }
Пример #8
0
 private Tile readTile(FileStream fs, IList<Region> regions)
 {
     Tile tile = new Tile();
     short regionId = readShort(fs);
     if (regionId >= 0)
     {
         tile.Region = regions.ElementAt(regionId);
         tile.Region.AddTile(tile);
     }
     return tile;
 }
Пример #9
0
        private Tile[][] readTiles(FileStream fs, int rows, int cols, IList<Region> regions)
        {
            Tile[][] tiles = new Tile[rows][];
            for (int i = 0; i < tiles.Length; ++i)
            {
                tiles[i] = new Tile[cols];
            }

            for (int r = 0; r < rows; ++r)
            {
                for (int c = 0; c < cols; ++c)
                {
                    Tile tile = readTile(fs, regions);
                    tile.Row = r;
                    tile.Col = c;
                    tiles[r][c] = tile;
                }
            }

            return tiles;
        }
Пример #10
0
        private short getTileFlag(Tile tile)
        {
            short flag = 0;

            int row = tile.Row;
            int col = tile.Col;
            Tile[][] tiles = mapTiles;
            int adjacentRow = -1, adjacentCol = -1;
            Region tileRegion = tiles[row][col].Region;
            adjacentRow = row;
            adjacentCol = col - 1;
            //左边的竖线
            if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
            {
                flag |= 1 << 1;
            }
            adjacentCol = col + 1;
            //右边的竖线
            if (adjacentCol >= tiles[row].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
            {
                flag |= 1 << 4;
            }

            //偶数行
            bool evenRow = (row % 2 == 0);
            adjacentRow = row - 1;
            if (adjacentRow >= 0)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左上角的斜线
                if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    flag |= 1;
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右上角的斜线
                if (adjacentCol >= tiles[adjacentRow].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    flag |= 1 << 5;
                }
            }
            else
            {
                //上面的斜线
                flag |= 1;
                flag |= 1 << 5;
            }
            adjacentRow = row + 1;
            if (adjacentRow < tiles.Length)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左下角的斜线
                if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    flag |= 1 << 2;
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右下角的斜线
                if (adjacentCol >= tiles[adjacentRow].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    flag |= 1 << 3;
                }
            }
            else
            {
                //下面的斜线
                flag |= 1 << 2;
                flag |= 1 << 3;
            }
            return flag;
        }
Пример #11
0
 public Map(int screenWidth, int screenHeight)
 {
     this.ScreenWidth = screenWidth;
     this.ScreenHeight = screenHeight;
     this.mapTiles = new Tile[screenHeight][];
     for (int r = 0; r < screenHeight; ++r)
     {
         mapTiles[r] = new Tile[screenWidth];
         for (int c = 0; c < screenWidth; ++c)
         {
             mapTiles[r][c] = new Tile(r, c);
         }
     }
 }
Пример #12
0
 private void addSelectedTile(Tile tile)
 {
     if (tile != null && !selectedTiles.Contains(tile))
     {
         selectedTiles.Add(tile);
     }
 }
Пример #13
0
 public void SelectCurTile(int x, int y)
 {
     Tile tile = translateToTile(x, y);
     if (tile != null)
     {
         curTile = tile;
     }
 }
Пример #14
0
 public void CancelCurTile()
 {
     curTile = null;
 }
Пример #15
0
 public bool InMapIndexRegion(Tile tile)
 {
     return InMapIndexRegion(tile.Row, tile.Col);
 }
Пример #16
0
 private void resetRegions(IList<Region> regions, Tile[][] tiles)
 {
     for (int i = 0; i < regions.Count; ++i)
     {
         Region region = regions.ElementAt(i);
         if (region.UpRegionId >= 0)
         {
             region.UpRegion = regions.ElementAt(region.UpRegionId);
         }
         if (region.LeftRegionId >= 0)
         {
             region.LeftRegion = regions.ElementAt(region.LeftRegionId);
         }
         if (region.DownRegionId >= 0)
         {
             region.DownRegion = regions.ElementAt(region.DownRegionId);
         }
         if (region.RightRegionId >= 0)
         {
             region.RightRegion = regions.ElementAt(region.RightRegionId);
         }
         region.CenterTile = tiles[region.CenterTileRow][region.CenterTileCol];
     }
 }
Пример #17
0
 public Point TranslateToPosition(Tile tile)
 {
     return TranslateToPosition(tile.Row, tile.Col);
 }
Пример #18
0
 private void writeTile(FileStream fs, Tile tile, Dictionary<Region, short> regIds)
 {
     if (tile.Region != null)
     {
         write(fs, regIds[tile.Region]);
     }
     else
     {
         write(fs, (short)-1);
     }
 }
Пример #19
0
 private void assignTiles(TileHead th, Tile[][] tiles)
 {
     this.rows = th.Rows;
     this.cols = th.Cols;
     for (int r = 0; r < th.Rows; ++r)
     {
         for (int c = 0; c < th.Cols; ++c)
         {
             mapTiles[r][c] = tiles[r][c];
         }
     }
     for (int r = 0; r < mapTiles.Length; ++r)
     {
         for (int c = 0; c < mapTiles[0].Length; ++c)
         {
             if (mapTiles[r][c] == null)
             {
                 mapTiles[r][c] = new Tile(r, c);
             }
         }
     }
 }
Пример #20
0
 public void AddTile(Tile tile)
 {
     if (!tiles.Contains(tile))
     {
         tiles.Add(tile);
     }
 }
Пример #21
0
        private void drawRegionBorder(Graphics g, Pen pen, int row, int col, int x, int y, Tile[][] tiles)
        {
            int adjacentRow = -1, adjacentCol = -1;
            Region tileRegion = tiles[row][col].Region;
            adjacentRow = row;
            adjacentCol = col - 1;
            //左边的竖线
            if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol]==null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
            {
                g.DrawLine(pen, x, y + sideYMappingLen, x, y + sideYMappingLen + sideLen);
            }
            adjacentCol = col + 1;
            //右边的竖线
            if (adjacentCol >= tiles[row].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
            {
                g.DrawLine(pen, x + 2 * sideXMappingLen, y + sideYMappingLen, x + 2 * sideXMappingLen, y + sideYMappingLen + sideLen);
            }

            //偶数行
            bool evenRow = (row % 2 == 0);
            adjacentRow = row - 1;
            if (adjacentRow >= 0)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左上角的斜线
                if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    g.DrawLine(pen, x, y + sideYMappingLen, x + sideXMappingLen, y);
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右上角的斜线
                if (adjacentCol >= tiles[adjacentRow].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    g.DrawLine(pen, x + sideXMappingLen, y, x + 2 * sideXMappingLen, y + sideYMappingLen);
                }
            }
            else
            {
                //上面的斜线
                g.DrawLine(pen, x, y + sideYMappingLen, x + sideXMappingLen, y);
                g.DrawLine(pen, x + sideXMappingLen, y, x + 2 * sideXMappingLen, y + sideYMappingLen);
            }
            adjacentRow = row + 1;
            if (adjacentRow < tiles.Length)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左下角的斜线
                if (adjacentCol < 0 || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    g.DrawLine(pen, x, y + sideYMappingLen + sideLen, x + sideXMappingLen, y + 2 * sideYMappingLen + sideLen);
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右下角的斜线
                if (adjacentCol >= tiles[adjacentRow].Length || tiles[adjacentRow][adjacentCol] == null || tiles[adjacentRow][adjacentCol].Region != tileRegion)
                {
                    g.DrawLine(pen, x + sideXMappingLen, y + 2 * sideYMappingLen + sideLen, x + 2 * sideXMappingLen, y + sideYMappingLen + sideLen);
                }
            }
            else
            {
                //下面的斜线
                g.DrawLine(pen, x, y + sideYMappingLen + sideLen, x + sideXMappingLen, y + 2 * sideYMappingLen + sideLen);
                g.DrawLine(pen, x + sideXMappingLen, y + 2 * sideYMappingLen + sideLen, x + 2 * sideXMappingLen, y + sideYMappingLen + sideLen);
            }
        }
Пример #22
0
 public bool ContainsTile(Tile tile)
 {
     return tiles.Contains(tile);
 }
Пример #23
0
 private HashSet<Region> getAllRegions(Tile[][] tiles, int rows, int cols)
 {
     HashSet<Region> regions = new HashSet<Region>();
     for (int r = 0; r < rows; ++r)
     {
         for (int c = 0; c < cols; ++c)
         {
             Region region = tiles[r][c].Region;
             if (region != null && !regions.Contains(region))
             {
                 regions.Add(region);
             }
         }
     }
     return regions;
 }
Пример #24
0
 public void RemoveTile(Tile tile)
 {
     if (tiles.Contains(tile))
     {
         tiles.Remove(tile);
     }
     if (CenterTile == tile)
     {
         CenterTile = null;
     }
     if (tiles.Count <= 0)
     {
         if (Influence != null)
         {
             Influence.RemoveRegion(this);
         }
     }
 }
Пример #25
0
        private HashSet<Tile> getAroundTiles(Tile tile)
        {
            HashSet<Tile> aroundTiles = new HashSet<Tile>();
            Tile[][] tiles = mapTiles;
            int row = tile.Row;
            int col = tile.Col;

            //左边的tile
            if (col - 1 >= 0)
            {
                aroundTiles.Add(tiles[row][col - 1]);
            }
            //右边的tile
            if (col + 1 <= Cols - 1)
            {
                aroundTiles.Add(tiles[row][col + 1]);
            }

            //偶数行
            bool evenRow = (row % 2 == 0);
            int adjacentRow = -1, adjacentCol = -1;
            adjacentRow = row - 1;
            if (adjacentRow >= 0)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左上角的tile
                if (adjacentCol >= 0)
                {
                    aroundTiles.Add(tiles[adjacentRow][adjacentCol]);
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右上角的tile
                if (adjacentCol <= Cols - 1)
                {
                    aroundTiles.Add(tiles[adjacentRow][adjacentCol]);
                }
            }

            adjacentRow = row + 1;
            if (adjacentRow <= Rows-1)
            {
                if (evenRow)
                {
                    adjacentCol = col - 1;
                }
                else
                {
                    adjacentCol = col;
                }
                //左下角的tile
                if (adjacentCol >= 0)
                {
                    aroundTiles.Add(tiles[adjacentRow][adjacentCol]);
                }

                if (evenRow)
                {
                    adjacentCol = col;
                }
                else
                {
                    adjacentCol = col + 1;
                }
                //右下角的斜线
                if (adjacentCol <= Cols - 1)
                {
                    aroundTiles.Add(tiles[adjacentRow][adjacentCol]);
                }
            }
            return aroundTiles;
        }
Пример #26
0
 private bool inSelectedTiles(Tile tile)
 {
     if (tile == null)
     {
         return false;
     }
     return selectedTiles.Contains(tile);
 }