Exemplo n.º 1
0
        /// <summary>
        /// Gets the tile adjacent to the chunk who's coordinates are given in the paramters.
        /// </summary>
        public TileType GetRelativeTile(int x, int y, Compass.Direction targetRelativeLoc)
        {
            switch (targetRelativeLoc)
            {
            case Compass.Direction.East:
                x++;
                break;

            case Compass.Direction.NortEast:
                x++;
                y--;
                break;

            case Compass.Direction.North:
                y++;
                break;

            case Compass.Direction.NorthWest:
                y--;
                x--;
                break;

            case Compass.Direction.South:
                y++;
                break;

            case Compass.Direction.SouthEast:
                y++;
                x++;
                break;

            case Compass.Direction.SouthWest:
                x--;
                y++;
                break;

            case Compass.Direction.West:
                x--;
                break;
            }

            return(this[x, y]);
        }
        public void PositiveWest()
        {
            //Arrange
            Orientation orientation = new Orientation();

            //Act
            orientation.RotateClockwiseFacing(Compass.Direction.West, 1);

            Compass.Direction Foward = orientation.Facing[Orientation.RelativeDir.Foward];
            Compass.Direction Right  = orientation.Facing[Orientation.RelativeDir.Right];
            Compass.Direction Back   = orientation.Facing[Orientation.RelativeDir.Back];
            Compass.Direction Left   = orientation.Facing[Orientation.RelativeDir.Left];
            Compass.Direction Above  = orientation.Facing[Orientation.RelativeDir.Above];
            Compass.Direction Below  = orientation.Facing[Orientation.RelativeDir.Below];

            //Assert

            Assert.AreEqual(Foward, Compass.Direction.Down);
            Assert.AreEqual(Right, Compass.Direction.East);
            Assert.AreEqual(Back, Compass.Direction.Up);
            Assert.AreEqual(Left, Compass.Direction.West);
            Assert.AreEqual(Above, Compass.Direction.North);
            Assert.AreEqual(Below, Compass.Direction.South);
        }
        public void RotateClockwiseFacing(Compass.Direction facing, int quarterCount = 1)
        {
            //Array of the directions that will be cycled
            Compass.Direction[] Dir = new Compass.Direction[4];
            //Determine which direction are cycled depending on a perspective direction
            switch (facing)
            {
            case Compass.Direction.North:
                Dir[0] = Compass.Direction.Up;
                Dir[1] = Compass.Direction.East;
                Dir[2] = Compass.Direction.Down;
                Dir[3] = Compass.Direction.West;
                break;

            case Compass.Direction.East:
                Dir[0] = Compass.Direction.Up;
                Dir[1] = Compass.Direction.South;
                Dir[2] = Compass.Direction.Down;
                Dir[3] = Compass.Direction.North;
                break;

            case Compass.Direction.South:
                Dir[0] = Compass.Direction.Up;
                Dir[1] = Compass.Direction.West;
                Dir[2] = Compass.Direction.Down;
                Dir[3] = Compass.Direction.East;
                break;

            case Compass.Direction.West:
                Dir[0] = Compass.Direction.Up;
                Dir[1] = Compass.Direction.North;
                Dir[2] = Compass.Direction.Down;
                Dir[3] = Compass.Direction.South;
                break;

            case Compass.Direction.Up:
                Dir[0] = Compass.Direction.South;
                Dir[1] = Compass.Direction.East;
                Dir[2] = Compass.Direction.North;
                Dir[3] = Compass.Direction.West;
                break;

            case Compass.Direction.Down:
                Dir[0] = Compass.Direction.North;
                Dir[1] = Compass.Direction.East;
                Dir[2] = Compass.Direction.South;
                Dir[3] = Compass.Direction.West;
                break;
            }
            //Store the current indexes of the changing directions
            int[] vIndex = new int[]
            {
                Bearing.Values.ToList().IndexOf(Dir[0]),
                Bearing.Values.ToList().IndexOf(Dir[1]),
                Bearing.Values.ToList().IndexOf(Dir[2]),
                Bearing.Values.ToList().IndexOf(Dir[3])
            };
            //Handle quarterCounts greater than 4
            quarterCount = quarterCount % 4;
            for (int i = 0; i < 4; i++)
            {
                //determine the new direction of direction i
                int newDir = i + quarterCount;
                if (newDir >= 4)
                {
                    newDir -= 4;
                }
                if (newDir <= -1)
                {
                    newDir += 4;
                }
                //change the dictionary value from its current direction to its new direction
                Bearing[(RelativeDir)vIndex[i]] = Dir[newDir];
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the chunk adjacent to the chunk who's coordinates are given in the paramters.
        /// </summary>
        /// <param name="curChunkX">coord in the chunk grid</param>
        /// <param name="curChunkY">coord in the chunk grid</param>
        /// <param name="curChunkZ">coord in the chunk grid</param>
        /// <param name="targetRelativeLoc">determines which adjacent chunk is returned</param>
        /// <returns></returns>
        public MapChunk GetRelativeChunk(int curChunkCoordX, int curChunkCoordY, int curChunkCoordZ, Compass.Direction targetRelativeLoc)
        {
            switch (targetRelativeLoc)
            {
            case Compass.Direction.East:
                curChunkCoordX++;
                break;

            case Compass.Direction.NortEast:
                curChunkCoordX++;
                curChunkCoordY--;
                break;

            case Compass.Direction.North:
                curChunkCoordY++;
                break;

            case Compass.Direction.NorthWest:
                curChunkCoordY--;
                curChunkCoordX--;
                break;

            case Compass.Direction.South:
                curChunkCoordY++;
                break;

            case Compass.Direction.SouthEast:
                curChunkCoordY++;
                curChunkCoordX++;
                break;

            case Compass.Direction.SouthWest:
                curChunkCoordX--;
                curChunkCoordY++;
                break;

            case Compass.Direction.West:
                curChunkCoordX--;
                break;

            case Compass.Direction.Down:
                curChunkCoordZ--;
                break;

            case Compass.Direction.Up:
                curChunkCoordZ++;
                break;
            }

            return(GetChunkAtChunkCoord(new SVector3(curChunkCoordX, curChunkCoordY, curChunkCoordZ)));
        }