예제 #1
0
        /// <summary>
        /// Converts the axial to cube.
        /// </summary>
        /// <param name="q">The q.</param>
        /// <param name="r">The r.</param>
        /// <returns></returns>
        public static CubeCoordinate AxialToCube(OffSetCoordinate o)
        {
            int x = o.Q;
            int z = o.R;
            int y = -x - z;

            return(new CubeCoordinate(x, y, z));
        }
예제 #2
0
        /// <summary>
        /// Converts the even q to cube.
        /// </summary>
        /// <param name="q">The q.</param>
        /// <param name="r">The r.</param>
        /// <returns></returns>
        public static CubeCoordinate EvenQToCube(OffSetCoordinate o)
        {
            int x = o.Q;
            int z = o.R - (o.Q - (o.Q & 1)) / 2;
            int y = -x - z;

            return(new CubeCoordinate(x, y, z));
        }
예제 #3
0
        /// <summary>
        /// Moves the in offset corrdinates.
        /// </summary>
        /// <returns>The in offset corrdinates.</returns>
        /// <param name="cooridinates">Cooridinates.</param>
        /// <param name="offsetType">Offset type.</param>
        /// <param name="direction">Direction.</param>
        public OffSetCoordinate MoveInOffsetCorrdinates(OffSetCoordinate cooridinates, OffsetCoordinateType offsetType, int direction)
        {
            Dictionary <int, Dictionary <int, int[]> > neighbors = new Dictionary <int, Dictionary <int, int[]> >();
            int parity = 0;

            if (offsetType.Equals(OffsetCoordinateType.OddR))
            {
                neighbors = new Dictionary <int, Dictionary <int, int[]> >
                {
                    { 0, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 0, -1 } }, { 2, new int[] { -1, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } }
                      } },
                    { 1, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { 0, 1 } }, { 5, new int[] { 1, 1 } }
                      } }
                };
                parity = cooridinates.R & 1;
            }

            if (offsetType.Equals(OffsetCoordinateType.EvenR))
            {
                neighbors = new Dictionary <int, Dictionary <int, int[]> >
                {
                    { 0, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { 0, 1 } }, { 5, new int[] { 1, 1 } }
                      } },
                    { 1, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 0, -1 } }, { 2, new int[] { -1, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } }
                      } }
                };
                parity = cooridinates.R & 1;
            }

            if (offsetType.Equals(OffsetCoordinateType.OddQ))
            {
                neighbors = new Dictionary <int, Dictionary <int, int[]> >
                {
                    { 0, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, -1 } }, { 4, new int[] { -1, 0 } }, { 5, new int[] { 0, 1 } }
                      } },
                    { 1, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 1 } }, { 1, new int[] { 1, 0 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } }
                      } }
                };
                parity = cooridinates.Q & 1;
            }

            if (offsetType.Equals(OffsetCoordinateType.EvenQ))
            {
                neighbors = new Dictionary <int, Dictionary <int, int[]> >
                {
                    { 0, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 1 } }, { 1, new int[] { 1, 0 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, 0 } }, { 4, new int[] { -1, 1 } }, { 5, new int[] { 0, 1 } }
                      } },
                    { 1, new Dictionary <int, int[]>
                      {
                          { 0, new int[] { 1, 0 } }, { 1, new int[] { 1, -1 } }, { 2, new int[] { 0, -1 } },
                          { 3, new int[] { -1, -1 } }, { 4, new int[] { -1, 0 } }, { 5, new int[] { 0, 1 } }
                      } }
                };
                parity = cooridinates.Q & 1;
            }

            int[] d = neighbors[parity][direction];
            return(new OffSetCoordinate(cooridinates.Q + d[0], cooridinates.R + d[1], offsetType));
        }