コード例 #1
0
        public void DrawHexGrid(Graphics graphics, Pen pen, MinsAndMaxes minsAndMaxes, float height)
        {
            //loop until hexagons cannot fit?

            for (int row = 0; ; row++)
            {
                PointF[] points = ConvertHexToPointF(rowPosition: row, columnPosition: 0, height: height);

                //break the loop if the hexagon does not fit
                if (points[4].Y > minsAndMaxes.yMax)
                {
                    break;
                }

                //Otherwise, just draw the row
                //  int columnCount = 0;
                for (int col = 0; ; col++)
                {
                    //Get the points
                    points = ConvertHexToPointF(row, col, height);

                    //If we cannot fit the hexagon horizontally, next..
                    if (points[3].X > minsAndMaxes.xMax)
                    {
                        break;
                    }

                    //If the hexagon fits vertically, DRAW IT
                    if (points[4].Y <= minsAndMaxes.yMax)
                    {
                        graphics.DrawPolygon(pen, points);
                    }
                }
            }/////////////
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hexagons"></param>
        public void DrawTilesToHexGrid(
            List <PointF> pointsZ, MinsAndMaxes minsAndMaxes,
            float height, Graphics graphics)
        {
            try
            {
                for (int row = 0; ; row++)
                {
                    PointF[] points = ConvertHexToPointF(rowPosition: row, columnPosition: 0, height: height);

                    //break the loop if the hexagon does not fit
                    if (points[4].Y > minsAndMaxes.yMax)
                    {
                        break;
                    }

                    //Otherwise, just draw the row
                    //  int columnCount = 0;
                    for (int col = 0; ; col++)
                    {
                        //Get the points
                        points = ConvertHexToPointF(row, col, height);

                        //If we cannot fit the hexagon horizontally, next..
                        if (points[3].X > minsAndMaxes.xMax)
                        {
                            break;
                        }

                        //If the hexagon fits vertically, DRAW IT
                        if (points[4].Y <= minsAndMaxes.yMax)
                        {
                            //graphics.DrawImage(, points);
                        }
                    }
                }/////////////



                //// Create image.
                //Image newImage  = global::BraveNewWorld.Properties.Resources.settlement;

                //// Create parallelogram for drawing image.
                //PointF[] destPara = pointsZ.ToArray();



                //// Draw image to screen.
                ////for (int i = 0; i < destPara.Length; i++)
                ////{
                ////graphics.DrawImageUnscaled(newImage, (int)destPara[i].X, (int)destPara[i].Y);

                ////                    graphics.DrawImage(newImage, destPara);
                //    graphics.DrawImage(newImage, new Point((int)destPara[17].X,(int)destPara[45].Y));

                ////}
            }
            catch (Exception exc)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(exc.Message + " " + exc.Data + " " + exc.Source + " " + exc.StackTrace);
            }
        }