Ejemplo n.º 1
0
        public static float Distance(float px, float py, HexagonIndex hexagonIndex)
        {
            var hexagon = new Hexagon();

            hexagon.x = hexagonIndex.x;
            hexagon.y = hexagonIndex.y;

            var distance = Math.Sqrt((px - hexagon.px) * (px - hexagon.px) + (py - hexagon.py) * (py - hexagon.py));

            return((float)distance);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 得到周围相邻的的六边形
        /// 逆时针旋转,分别取各个相邻的,从12点开始,2小时取一个边
        /// </summary>
        /// <param name="hexagon"></param>
        /// <returns></returns>
        public static List <HexagonIndex> GetAroundHexagon(int x, int y)
        {
            var list = new List <HexagonIndex>();

            //偶然
            if (y % 2 == 0)
            {
                //1
                var hindex1 = new HexagonIndex();
                hindex1.x = x;
                hindex1.y = y + 1;
                list.Add(hindex1);
                //2
                var hindex2 = new HexagonIndex();
                hindex2.x = x + 1;
                hindex2.y = y;
                list.Add(hindex2);
                //3
                var hindex3 = new HexagonIndex();
                hindex3.x = x;
                hindex3.y = y - 1;
                list.Add(hindex3);
                //4
                var hindex4 = new HexagonIndex();
                hindex4.x = x - 1;
                hindex4.y = y - 1;
                list.Add(hindex4);
                //5
                var hindex5 = new HexagonIndex();
                hindex5.x = x - 1;
                hindex5.y = y;
                list.Add(hindex5);
                //6
                var hindex6 = new HexagonIndex();
                hindex6.x = x - 1;
                hindex6.y = y + 1;
                list.Add(hindex6);
            }
            else ///奇数
            {
                //1
                var hindex1 = new HexagonIndex();
                hindex1.x = x + 1;
                hindex1.y = y + 1;
                list.Add(hindex1);
                //2
                var hindex2 = new HexagonIndex();
                hindex2.x = x + 1;
                hindex2.y = y;
                list.Add(hindex2);
                //3
                var hindex3 = new HexagonIndex();
                hindex3.x = x + 1;
                hindex3.y = y - 1;
                list.Add(hindex3);
                //4
                var hindex4 = new HexagonIndex();
                hindex4.x = x;
                hindex4.y = y - 1;
                list.Add(hindex4);
                //5
                var hindex5 = new HexagonIndex();
                hindex5.x = x - 1;
                hindex5.y = y + 1;
                list.Add(hindex5);
                //6
                var hindex6 = new HexagonIndex();
                hindex6.x = x;
                hindex6.y = y + 1;
                list.Add(hindex6);
            }
            //清理不存在的
            list.RemoveAll(i => i.x <0 || i.y <0 || i.x> Config.Width_Count || i.y> Config.Heigth_Count);
            return(list);
        }