Пример #1
0
        public int CreateHexSet()
        {
            int currentIdx = sets.Count;

            HexSet set = new HexSet(this);

            AddHexSet(set);
            return(currentIdx);
        }
Пример #2
0
        public HexSet Convert(List <HexaPos> hexaPosSet)
        {
            HexSet hexSet = new HexSet(this.mapState);

            List <HexaPos> .Enumerator e = hexaPosSet.GetEnumerator();

            while (e.MoveNext())
            {
                hexSet.hexSet.Add(GetHex(e.Current.X, e.Current.Y));
            }

            return(hexSet);
        }
Пример #3
0
        public HexagonalMapState()
        {
            backgroundColor      = Color.White;
            gridColor            = Color.Black;
            gridPenWidth         = 1;
            activeHex            = null;
            activeHexBorderColor = Color.Blue;
            activeHexBorderWidth = 1;

            sets      = new List <HexSet>();
            obstacles = new HexSet(this);
            activeSet = null;
        }
Пример #4
0
 public void AddHexSet(HexSet set)
 {
     sets.Add(set);
 }
Пример #5
0
        public void Draw(Graphics graphics)
        {
            int width  = Convert.ToInt32(System.Math.Ceiling(map.PixelWidth));
            int height = Convert.ToInt32(System.Math.Ceiling(map.PixelHeight));

            // seems to be needed to avoid bottom and right from being chopped off
            width  += 1;
            height += 1;

            //
            // Create drawing objects
            //
            Bitmap     bitmap         = new Bitmap(width, height);
            Graphics   bitmapGraphics = Graphics.FromImage(bitmap);
            Pen        p  = new Pen(Color.Black);
            SolidBrush sb = new SolidBrush(Color.Black);

            //
            // Draw Board background
            //
            sb = new SolidBrush(map.MapState.BackgroundColor);
            bitmapGraphics.FillRectangle(sb, 0, 0, width, height);

            //
            // Draw Hex Background
            //
            for (int i = 0; i < map.Hexes.GetLength(0); i++)
            {
                for (int j = 0; j < map.Hexes.GetLength(1); j++)
                {
                    //bitmapGraphics.DrawPolygon(p, board.Hexes[i, j].Points);
                    bitmapGraphics.FillPolygon(new SolidBrush(map.GetHexColor(map.Hexes[i, j].posX, map.Hexes[i, j].posY)), map.Hexes[i, j].Points);
                }
            }

            //
            // Draw Hex Grid
            //
            p.Color = map.MapState.GridColor;
            p.Width = map.MapState.GridPenWidth;
            for (int i = 0; i < map.Hexes.GetLength(0); i++)
            {
                for (int j = 0; j < map.Hexes.GetLength(1); j++)
                {
                    bitmapGraphics.DrawPolygon(p, map.Hexes[i, j].Points);
                }
            }

            //
            // Draw Active Hex, if present
            //
            if (map.MapState.ActiveHex != null)
            {
                p.Color = map.MapState.ActiveHexBorderColor;
                p.Width = map.MapState.ActiveHexBorderWidth;
                //bitmapGraphics.DrawPolygon(p, map.MapState.ActiveHex.Points);
                bitmapGraphics.FillPolygon(new SolidBrush(p.Color), map.MapState.ActiveHex.Points);

                /*
                 * List<HexaPos> tempList = map.GetHexes(map.MapState.ActiveHex.posX, map.MapState.ActiveHex.posY, 1);
                 * List<HexaPos>.Enumerator e = tempList.GetEnumerator();
                 * while (e.MoveNext())
                 * {
                 *  Hex tempHex = map.GetHex(e.Current.X, e.Current.Y);
                 *
                 *  p.Color = Color.Blue;
                 *  bitmapGraphics.DrawPolygon(p, tempHex.Points);
                 * }
                 */
            }

            if (map.MapState.ActiveHexSet != null)
            {
                HexSet activeHexSet      = map.MapState.ActiveHexSet;
                List <Hex> .Enumerator e = activeHexSet.hexSet.GetEnumerator();
                while (e.MoveNext())
                {
                    p.Color = Color.Yellow;
                    bitmapGraphics.FillPolygon(new SolidBrush(p.Color), e.Current.Points);
                }
            }

            List <Hex> .Enumerator eO = map.MapState.obstacles.hexSet.GetEnumerator();
            while (eO.MoveNext())
            {
                bitmapGraphics.FillPolygon(new SolidBrush(Color.Chocolate), eO.Current.Points);
            }

            int setNum = map.MapState.GetHexSetNum();

            if (setNum > 0)
            {
                for (int i = 0; i < setNum; i++)
                {
                    HexSet set = map.MapState.GetHexSet(i);

                    int setSize = set.hexSet.Count;
                    for (int j = 0; j < setSize; j++)
                    {
                        Hex tempHex = set.hexSet[j];
                        p.Color = set.borderColor;
                        bitmapGraphics.DrawPolygon(p, tempHex.Points);
                    }
                }
            }

            //
            // Draw internal bitmap to screen
            //
            graphics.DrawImage(bitmap, new Point(this.mapXOffset, this.mapYOffset));

            //
            // Release objects
            //
            bitmapGraphics.Dispose();
            bitmap.Dispose();
        }