Exemplo n.º 1
0
        private CompassDirection GetCompassDirection(string[] lineParts)
        {
            CompassDirection compassDirection = CompassDirection.North;

            switch (lineParts[2][0])
            {
            case 'N':
                compassDirection = CompassDirection.North;
                break;

            case 'E':
                compassDirection = CompassDirection.East;
                break;

            case 'S':
                compassDirection = CompassDirection.South;
                break;

            case 'W':
                compassDirection = CompassDirection.West;
                break;
            }

            return(compassDirection);
        }
Exemplo n.º 2
0
        private void CalculateCompassDirection()
        {
            Vector2 vec = Vector2.zero;

            if (_previousRail == null && _nextRail == null)
            {
                CompassDirection = CompassDirection.E;
                return;
            }
            else if (_previousRail == null)
            {
                vec = _nextRail.Position - Position;
            }
            else if (_nextRail == null)
            {
                vec = Position - _previousRail.Position;
            }
            else
            {
                vec = _nextRail.Position - _previousRail.Position;
            }

            float angle  = Mathf.Atan2(y: vec.y, x: vec.x);
            int   octant = Mathf.RoundToInt(f: 8 * angle / (2 * Mathf.PI) + 8) % 8;

            CompassDirection = (CompassDirection)octant;
        }
Exemplo n.º 3
0
        private void ExitRoom(Room room, CompassDirection wallLocation)
        {
            if (room.Trap != null && room.Trap.TrippedOrDisarmed == false)
            {
                ProcessTrapMessagesAndDamage(room.Trap);
                room.Trap.TrippedOrDisarmed = true;
            }

            var exit = room.Exits.FirstOrDefault(x => x.WallLocation == wallLocation);

            if (exit == null)
            {
                throw new Exception("this room doesnt have that exception");
            }

            var newRoom = gameAdventure.Rooms.FirstOrDefault(x => x.RoomNumber == exit.LeadsToRoomNumber);

            if (newRoom == null)
            {
                throw new Exception("The room that this previous room was supposed to lead too does not exist!?  Dragons?  Or maybe a bad author!!!");
            }

            if ((exit.Lock == null || !exit.Lock.Locked) || TryUnlock(exit.Lock))
            {
                RoomProcessor(newRoom);
            }
            else
            {
                RoomProcessor(room);
            }
        }
Exemplo n.º 4
0
 public Collision(CompassDirection side, Rectangle intersectionRec, object collider, object collidee)
 {
     Side            = side;
     IntersectionRec = intersectionRec;
     Collider        = collider;
     Collidee        = collidee;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns the direction right of current.
 /// </summary>
 /// <param name="currentFacing"></param>
 /// <returns></returns>
 public CompassDirection TurnRight(CompassDirection currentFacing)
 {
     var current = (int)currentFacing + 1;
     if (current == 8)
         current = 0;
     return (CompassDirection)current;
 }
Exemplo n.º 6
0
        public void TurnRight(CompassDirection originalFacing, CompassDirection expectedFacing)
        {
            var compass   = new Compass();
            var newFacing = compass.RightTurns[originalFacing];

            Assert.AreEqual(expectedFacing, newFacing);
        }
Exemplo n.º 7
0
 public RoverSpec(int x, int y, CompassDirection facing, RoverInstruction[] instructions)
 {
     X            = x;
     Y            = y;
     Facing       = facing;
     Instructions = instructions ?? throw new ArgumentNullException(nameof(instructions));
 }
Exemplo n.º 8
0
        public CompassDirection GetCompassDirection(Point3D loc)
        {
            int i = loc.Y - m_Bounds.Y;
            int j = loc.X - m_Bounds.X;

            CompassDirection dir = CompassDirection.None;

            if (i > 0 && i < (m_Bounds.Height - 1))
            {
                if (j > 0 && !m_Traps[i - 1][j - 1])
                {
                    dir |= CompassDirection.West;
                }

                if (j < (m_Bounds.Width - 1) && !m_Traps[i - 1][j + 1])
                {
                    dir |= CompassDirection.East;
                }
            }

            if (i > 0 && (i == 1 || !m_Traps[i - 2][j]))
            {
                dir |= CompassDirection.North;
            }

            if (i < (m_Bounds.Height - 1) && (i == m_Bounds.Height - 2 || !m_Traps[i][j]))
            {
                dir |= CompassDirection.South;
            }

            return(dir);
        }
        public static float WindDirToInverseAngle(CompassDirection cdir)
        {
            switch (cdir)
            {
            case CompassDirection.N:
                return(180f);

            case CompassDirection.E:
                return(270f);

            case CompassDirection.W:
                return(90f);

            case CompassDirection.S:
                return(0f);

            case CompassDirection.NE:
                return(225f);

            case CompassDirection.NW:
                return(125f);

            case CompassDirection.SE:
                return(315f);

            case CompassDirection.SW:
                return(45f);

            default:
                return(0f);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate a (possibly multi-tile) doorway
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="direction"></param>
        /// <param name="template"></param>
        /// <param name="template2"></param>
        /// <param name="floorLevel"></param>
        protected void GenerateDoorway(int i, int j, CompassDirection direction, int width)
        {
            for (int n = -1; n < width + 1; n++)
            {
                int iA = i;
                int jA = j;

                if (direction == CompassDirection.North ||
                    direction == CompassDirection.South)
                {
                    iA += n;
                }
                else
                {
                    jA += n;
                }

                if (n < 0 || n > width)
                {
                    SetCell(i, j, CellGenerationType.WallCorner);
                }
                else
                {
                    SetCell(i, j, CellGenerationType.Door);
                }
            }
        }
Exemplo n.º 11
0
        public Rover(int x, int y, CompassDirection facing, int maxX, int maxY, Compass compass)
        {
            this.compass = compass ?? throw new ArgumentNullException(nameof(compass));

            if (x < 0 || x > maxX)
            {
                throw new ArgumentException(nameof(x));
            }

            if (y < 0 || y > maxY)
            {
                throw new ArgumentException(nameof(y));
            }

            if (!compass.ValidDirections.Contains(facing))
            {
                throw new ArgumentException(nameof(facing));
            }

            X         = x;
            Y         = y;
            Facing    = facing;
            this.maxX = maxX;
            this.maxY = maxY;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Choose a random point on the outside edge of this rectangle
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="rng"></param>
        /// <param name="endOffset"></param>
        /// <param name="i"></param>
        /// <param name="j"></param>
        public void RandomPointOnEdge(CompassDirection edge, Random rng, int endOffset, ref int i, ref int j)
        {
            if (edge == CompassDirection.North)
            {
                j = YMax + 1;
            }
            else if (edge == CompassDirection.East)
            {
                i = XMax + 1;
            }
            else if (edge == CompassDirection.South)
            {
                j = YMin - 1;
            }
            else if (edge == CompassDirection.West)
            {
                i = XMin - 1;
            }

            if (edge.IsHorizontal())
            {
                j = rng.Next(YMin, YMax - endOffset + 1);
            }
            else
            {
                i = rng.Next(XMin, XMax - endOffset + 1);
            }
        }
Exemplo n.º 13
0
        public void Transform_NotInvalidCompassDirection_ReturnsNewPosition(
            CompassDirection currentCompassDirection,
            int currentX,
            int currentY,
            int expectedOutputX,
            int expectedOutputY)
        {
            var currentState = this.mockRepository.Create <IRobotState>();

            currentState.Setup(s => s.GetCompassDirection()).Returns(currentCompassDirection);
            currentState.Setup(s => s.GetX()).Returns(currentX);
            currentState.Setup(s => s.GetY()).Returns(currentY);
            var robotStateBuilder = this.mockRepository.Create <IRobotStateBuilder>();

            this.robotStateBuilderFactory
            .Setup(f => f.CreateBuilderFromPrototype(currentState.Object))
            .Returns(robotStateBuilder.Object);
            robotStateBuilder.Setup(
                b => b.WithX(expectedOutputX)).Returns(robotStateBuilder.Object);
            robotStateBuilder.Setup(
                b => b.WithY(expectedOutputY)).Returns(robotStateBuilder.Object);
            var expectedState = this.mockRepository.Create <IRobotState>();

            robotStateBuilder.Setup(b => b.Build()).Returns(expectedState.Object);
            var outputState = this.moveStateTransformer.Transform(currentState.Object);

            Assert.Equal(outputState, expectedState.Object);
        }
Exemplo n.º 14
0
 public SquareType MovetoSquare(CompassDirection direction)
 {
     moveToSquareX    = GetMoveToSquareX(direction);
     moveToSquareY    = GetMoveToSquareY(direction);
     moveToSquareType = map[moveToSquareX, moveToSquareY];
     return(moveToSquareType);
 }
        private CurrentWeather MapCurrentConditionsResponse(CurrentConditionsResponse openWeatherApiResponse)
        {
            var currentConditions = new CurrentWeather()
            {
                Success      = true,
                ErrorMessage = String.Empty,
                Location     = new CurrentWeather.LocationData()
                {
                    Name      = openWeatherApiResponse.Name,
                    Latitude  = openWeatherApiResponse.Coordintates.Latitude,
                    Longitude = openWeatherApiResponse.Coordintates.Longitude
                },
                ObservationTime    = DateTimeOffset.FromUnixTimeSeconds(openWeatherApiResponse.ObservationTime + openWeatherApiResponse.TimezoneOffset).DateTime,
                ObservationTimeUtc = DateTimeOffset.FromUnixTimeSeconds(openWeatherApiResponse.ObservationTime).DateTime,
                CurrentConditions  = new CurrentWeather.WeatherData()
                {
                    Conditions            = openWeatherApiResponse.ObservedConditions.FirstOrDefault()?.Conditions,
                    ConditionsDescription = openWeatherApiResponse.ObservedConditions.FirstOrDefault()?.ConditionsDetail,
                    Visibility            = openWeatherApiResponse.Visibility / 1609.0, // Visibility always comes back in meters, even when imperial requested
                    CloudCover            = openWeatherApiResponse.Clouds.CloudCover,
                    Temperature           = openWeatherApiResponse.ObservationData.Temperature,
                    Humidity             = openWeatherApiResponse.ObservationData.Humidity,
                    Pressure             = openWeatherApiResponse.ObservationData.Pressure * 0.0295301, // Pressure always comes back in millibars, even when imperial requested
                    WindSpeed            = openWeatherApiResponse.WindData.Speed,
                    WindDirection        = CompassDirection.GetDirection(openWeatherApiResponse.WindData.Degrees),
                    WindDirectionDegrees = openWeatherApiResponse.WindData.Degrees,
                    RainfallOneHour      = (openWeatherApiResponse.Rain?.RainfallOneHour ?? 0.0) * 0.03937008
                },
                FetchTime = DateTime.Now
            };

            return(currentConditions);
        }
Exemplo n.º 16
0
        public static char GetCharByCompassDirection(this CompassDirection compassDirection)
        {
            char compassDirectionByChar;

            switch (compassDirection)
            {
            case CompassDirection.North:
                compassDirectionByChar = 'N';
                break;

            case CompassDirection.West:
                compassDirectionByChar = 'W';
                break;

            case CompassDirection.South:
                compassDirectionByChar = 'S';
                break;

            case CompassDirection.East:
                compassDirectionByChar = 'E';
                break;

            default:
                throw new ArgumentException();
            }

            return(compassDirectionByChar);
        }
Exemplo n.º 17
0
 public static bool IsCardinalDirection(this CompassDirection direction)
 {
     return(direction == CompassDirection.Top ||
            direction == CompassDirection.Right ||
            direction == CompassDirection.Bottom ||
            direction == CompassDirection.Left);
 }
Exemplo n.º 18
0
    public bool OffsetByOne(CompassDirection direction, out Subtile newTile)
    {
        var newX = X;
        var newY = Y;

        switch (direction)
        {
        case CompassDirection.Top:
            newX--;
            newY--;
            break;

        case CompassDirection.TopRight:
            newX--;
            break;

        case CompassDirection.Right:
            newX--;
            newY++;
            break;

        case CompassDirection.BottomRight:
            newY++;
            break;

        case CompassDirection.Bottom:
            newX++;
            newY++;
            break;

        case CompassDirection.BottomLeft:
            newX++;
            break;

        case CompassDirection.Left:
            newX++;
            newY--;
            break;

        case CompassDirection.TopLeft:
            newY--;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        if (newX < 0 || newX >= GameSystems.Location.LocationLimitX * 3 ||
            newY < 0 || newY >= GameSystems.Location.LocationLimitY * 3)
        {
            newTile = default;
            return(false);
        }
        else
        {
            newTile = new Subtile(newX, newY);
            return(true);
        }
    }
Exemplo n.º 19
0
        /// <summary>
        /// Rotates the camera about the cube so that the face adjacent to the current edge in the 
        /// specified face-direction becomes the current face. The input direction is cube 
        /// orientation-agnostic.
        /// </summary>
        /// <param name="direction">The direction to rotate towards, relative to the current 
        /// face.</param>
        public void Rotate( CompassDirection direction )
        {
            Face nextFace = CurrentFace.AdjacentFace( direction );
            CompassDirection backDir = nextFace.BackwardsDirectionFrom( CurrentFace );

            UpDir = GetNextUpDirection( direction, backDir );
            CurrentFace = nextFace;
        }
Exemplo n.º 20
0
 public LawnMower(int startX, int startY, CompassDirection initialHeading, ref ILawn lawn)
 {
     _heading = initialHeading;
     _lawn = lawn;
     XCord = startX;
     YCord = startY;
     _lawn.PlaceLawnMower(this, XCord, YCord);
 }
Exemplo n.º 21
0
 private void BackOffInDirection(locXY start, CompassDirection relPosCode, int tiles, out locXY locOut)
 {
     locOut = start;
     for (int i = 0; i < tiles; i++)
     {
         locOut = locOut.Offset(relPosCode);
     }
 }
        public void ParseCompassDirection_WhenPassingValidCompassDirection()
        {
            char             ch         = 'N';
            MowerInput       mowerInput = new MowerInput();
            CompassDirection direction  = MowerInput.ParseCompassDirection(ch);

            Assert.AreEqual(CompassDirection.North, direction);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="unit"></param>
 /// <param name="direction"></param>
 /// <param name="linkedAnimProcess"></param>
 /// <param name="delay"></param>
 public MovementProcess(Unit unit, CompassDirection direction, AnimProcess linkedAnimProcess, Isometry iso, float delay = .015f)
     : base()
 {
     _unit = unit;
     _direction = direction;
     _linkedAnimProcess = linkedAnimProcess;
     _speed = delay;
     _iso = iso;
 }
Exemplo n.º 24
0
 public override void Initialize(BaseCell primary, BaseCell other, CompassDirection direction)
 {
     base.Initialize(primary, other, direction);
     if (OtherSide != null)
     {
         // do something with the transform I guess
         isMirrored = true;
     }
 }
Exemplo n.º 25
0
        protected override string SolvePartOne()
        {
            (int x, int y)curPos = (0, 0);
            CompassDirection curDirection = CompassDirection.E;

            foreach (var line in Lines)
            {
                char instruction = line[0];
                int  val         = int.Parse(line[1..]);
Exemplo n.º 26
0
        public void Vectors(CompassDirection facing, int expectedX, int expectedY)
        {
            var compass = new Compass();
            var vector  = compass.Vectors[facing];

            Assert.AreEqual(facing, vector.Direction);
            Assert.AreEqual(expectedX, vector.XVector);
            Assert.AreEqual(expectedY, vector.YVector);
        }
Exemplo n.º 27
0
        public void CheckBoundaryBearingsReturCorrectDirectionForIntercardinalDirections(double bearing, string expectedDirection)
        {
            // Act
            var direction = CompassDirection.GetDirection(bearing);

            // Assert
            direction.Abbreviation.Should().Be(expectedDirection,
                                               $"Expected direction of {expectedDirection} but got {direction.Abbreviation} for bearing {bearing}");
        }
Exemplo n.º 28
0
        /// <summary>
        /// Rotates the robot with new direction value.
        /// </summary>
        /// <param name="newDirectionValue">The new direction value.</param>
        /// <returns>System.Int32.</returns>
        private int RotateRobotWithNewDirectionValue(int newDirectionValue)
        {
            newDirectionValue = newDirectionValue < 0 ? 3 : newDirectionValue > 3 ? 0 : newDirectionValue;

            CompassDirection newDirection = (CompassDirection)newDirectionValue;

            _newPosition = new Position(_currentPosition.Xcoordinate, _currentPosition.Ycoordinate, newDirection);
            return(newDirectionValue);
        }
Exemplo n.º 29
0
 public Model(string Name, CompassDirection Direction, string Icon, RowColumn RowColumn) : base(Name)
 {
     this.Direction     = Direction;
     this.Icon          = string.Concat(@"pack://application:,,,/Imagin.Controls.Common;component/Images/", Icon, ".png");
     this.Row           = RowColumn.Row.ToInt32();
     this.Column        = RowColumn.Column.ToInt32();
     this.DefaultRow    = RowColumn.Row.ToInt32();
     this.DefaultColumn = RowColumn.Column.ToInt32();
 }
Exemplo n.º 30
0
 private int YMoveForDirection(CompassDirection direction)
 {
     int[] yMoves = new int[4];
     yMoves[(int)CompassDirection.EAST]  = -1;
     yMoves[(int)CompassDirection.WEST]  = 1;
     yMoves[(int)CompassDirection.NORTH] = 0;
     yMoves[(int)CompassDirection.SOUTH] = 0;
     return(yMoves[(int)direction]);
 }
Exemplo n.º 31
0
        public void CheckBearingsResultInCorrectCompassDirection(double bearing, string expectedDirection)
        {
            // Act
            var direction = CompassDirection.GetDirection(bearing);

            // Assert
            direction.Abbreviation.Should().Be(expectedDirection,
                                               $"Expected direction of {expectedDirection} but got {direction.Abbreviation} for bearing {bearing}");
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            string inputFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../input.txt");
            string inputs        = File.ReadAllText(inputFilePath);

            Location         currentLocation  = new Location();
            Location         EasterHQ         = null;
            CompassDirection currentDirection = CompassDirection.North;

            List <Location> previouslyVisitedLocations = new List <Location>();;

            foreach (var input in inputs.Split(','))
            {
                string instruction = input.Trim();
                char   leftOrRight = instruction[0];
                int    distance    = int.Parse(instruction.Substring(1));

                if (leftOrRight == 'L')
                {
                    currentDirection = turn(true, currentDirection);
                }
                else if (leftOrRight == 'R')
                {
                    currentDirection = turn(false, currentDirection);
                }
                else
                {
                    throw new Exception("leftOrRight invalid.");
                }

                for (int i = 0; i < distance; i++)
                {
                    followDirections(currentDirection, 1, currentLocation);
                    if (EasterHQ == null && previouslyVisitedLocations.Contains(currentLocation))
                    {
                        Console.WriteLine(string.Format("We've been here before! ({0},{1})", currentLocation.X, currentLocation.Y));
                        EasterHQ = new Location()
                        {
                            X = currentLocation.X,
                            Y = currentLocation.Y
                        };
                    }
                    previouslyVisitedLocations.Add(new Location()
                    {
                        X = currentLocation.X,
                        Y = currentLocation.Y
                    });
                }
            }

            Console.WriteLine("Final Location: " + currentLocation.ToString());
            Console.WriteLine(string.Format("Shortest Distance:{0}", Math.Abs(currentLocation.X) + Math.Abs(currentLocation.Y)));

            Console.WriteLine("Easter Location: " + EasterHQ.ToString());
            Console.WriteLine(string.Format("Shortest Distance:{0}", Math.Abs(EasterHQ.X) + Math.Abs(EasterHQ.Y)));
            Console.ReadLine();
        }
Exemplo n.º 33
0
        public void TurnRight(CompassDirection originalFacing, CompassDirection expectedNewFacing)
        {
            var rover = new Rover(5, 6, originalFacing, MAX_X, MAX_Y, compass);

            rover.TurnRight();

            Assert.AreEqual(5, rover.X);
            Assert.AreEqual(6, rover.Y);
            Assert.AreEqual(expectedNewFacing, rover.Facing);
        }
Exemplo n.º 34
0
        public void Move(CompassDirection originalFacing, int expectedX, int expectedY)
        {
            var rover = new Rover(3, 6, originalFacing, MAX_X, MAX_Y, compass);

            rover.Move();

            Assert.AreEqual(expectedX, rover.X);
            Assert.AreEqual(expectedY, rover.Y);
            Assert.AreEqual(originalFacing, rover.Facing);
        }
        public CompassDirection LawnMowerSetNewHeading_CalledWithCurrentHeadingAndARotation_SetsLawnMowerHeading(CompassDirection compassDirection, int rotation)
        {
            //Arrange
            ILawn lawn = new Lawn(5, 5);
            var lawnMower = new LawnMowerWithPublicMethods(0, 0, compassDirection, ref lawn);

            //Act
            lawnMower.SetNewHeading(rotation);

            //Assert
            return lawnMower.Heading;
        }
Exemplo n.º 36
0
		public CompassGump( CompassDirection dir )
			: base( 100, 100 )
		{
			AddImage( 0, 0, 0x232F );
			AddAlphaRegion( 0, 0, 200, 200 );

			if ( ( dir & CompassDirection.West ) != 0 )
				AddImage( 50, 50, 0x119B );
			if ( ( dir & CompassDirection.North ) != 0 )
				AddImage( 100, 50, 0x1195 );
			if ( ( dir & CompassDirection.South ) != 0 )
				AddImage( 50, 100, 0x1199 );
			if ( ( dir & CompassDirection.East ) != 0 )
				AddImage( 100, 100, 0x1197 );
		}
Exemplo n.º 37
0
            protected void MoveSolid( Solid solid, CompassDirection dir )
            {
                Face nextFace = AdjacentFace( dir );
                var backDir = nextFace.BackwardsDirectionFrom( this );

                mSolids.Remove( solid );
                solid.World = nextFace.World;
                nextFace.mSolids.Add( solid );

                Body body = solid.Body;

                float pastRotation = body.Rotation;

                body.Rotation += nextFace.Rotation;
                body.AdHocGravity = Vector2.UnitY.Rotate( -body.Rotation ).Rounded();
                body.Awake = true;

                body.Position = body.Position.Rotate( pastRotation - body.Rotation );
                body.LinearVelocity = body.LinearVelocity.Rotate( pastRotation - body.Rotation );
            }
Exemplo n.º 38
0
        protected void SetNewHeading(int rotation) // -1 for left 90 degrees or 1 right 90 degrees 
        {
            var newHeadingInt = -1;

            switch (_heading)
            {
                case CompassDirection.N:
                    newHeadingInt = (4 + (0 + rotation)) % 4;
                    break;
                case CompassDirection.E:
                    newHeadingInt = (4 + (1 + rotation)) % 4;
                    break;
                case CompassDirection.S:
                    newHeadingInt = (4 + (2 + rotation)) % 4;
                    break;
                case CompassDirection.W:
                    newHeadingInt = (4 + (3 + rotation)) % 4;
                    break;
            }

            _heading = (CompassDirection)newHeadingInt;
        }
Exemplo n.º 39
0
 protected override void ApplyRotation( CompassDirection dir )
 {
     base.ApplyRotation( dir );
     mModelRotation.Value = Rotation;
     if ( IsActive )
         Cube.Rotate( dir );
 }
 public LawnMowerWithPublicMethods(int startX, int startY, CompassDirection initHeading, ref ILawn lawn) : base(startX, startY, initHeading, ref lawn)
 {
 }
Exemplo n.º 41
0
            public Face AdjacentFace( CompassDirection direction )
            {
                switch ( direction )
                {
                case CompassDirection.North:
                    return NorthFace;

                case CompassDirection.East:
                    return EastFace;

                case CompassDirection.South:
                    return SouthFace;

                case CompassDirection.West:
                    return WestFace;
                }

                throw new Tools.WtfException();
            }
 private void CreateFan(CompassDirection direction)
 {
     var fan = engine.CreateFan(direction, RelativeHeight.AnyHeight);
       fans.Add((eDirection)direction, fan);
 }
 public new static void GetLawnMowerXyHeading(string xYHeadingArgs, out int x, out int y, out CompassDirection heading)
 {
     Program.GetLawnMowerXyHeading(xYHeadingArgs, out x, out y, out heading);
 }
Exemplo n.º 44
0
 /// <summary>
 /// Returns a location a given direction and distance away from the start location.
 /// </summary>
 /// <param name="startTile"></param>
 /// <param name="dir"></param>
 /// <param name="distance"></param>
 /// <returns></returns>
 public Point TileWalker(Point startTile, CompassDirection dir, int distance)
 {
     var p = startTile;
     for (var i = 0; i < distance; i++)
         p = TileWalker(p, dir);
     return p;
 }
Exemplo n.º 45
0
 protected static void GetLawnMowerXyHeading(string xYHeadingArgs, out int x, out int y, out CompassDirection heading)
 {
     string[] lawnMower1StartxYHeadingArg = xYHeadingArgs.Split(new[] { " " }, StringSplitOptions.None);
     Int32.TryParse(lawnMower1StartxYHeadingArg[0], out x);
     Int32.TryParse(lawnMower1StartxYHeadingArg[1], out y);
     Enum.TryParse(lawnMower1StartxYHeadingArg[2], out heading);
 }
Exemplo n.º 46
0
        /// <summary>
        /// Returns the tile location adjacent to the passed tile location in the given direction.
        /// </summary>
        /// <param name="startTile"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public Point TileWalker(Point startTile, CompassDirection dir)
        {
            var p = new Point(startTile.X, startTile.Y);
            switch (Style)
            {
                case IsometricStyle.Diamond:
                    switch (dir)
                    {
                        case CompassDirection.North:
                            p.X--;
                            p.Y--;
                            break;
                        case CompassDirection.NorthEast:
                            p.Y--;
                            break;
                        case CompassDirection.East:
                            p.X++;
                            p.Y--;
                            break;
                        case CompassDirection.SouthEast:
                            p.X++;
                            break;
                        case CompassDirection.South:
                            p.X++;
                            p.Y++;
                            break;
                        case CompassDirection.SouthWest:
                            p.Y++;
                            break;
                        case CompassDirection.West:
                            p.X--;
                            p.Y++;
                            break;
                        case CompassDirection.NorthWest:
                            p.X--;
                            break;
                    }
                    break;

                case IsometricStyle.Slide:
                    switch (dir)
                    {
                        case CompassDirection.North:
                            p.X++;
                            p.Y -= 2;
                            break;
                        case CompassDirection.NorthEast:
                            p.X++;
                            p.Y--;
                            break;
                        case CompassDirection.East:
                            p.X++;
                            break;
                        case CompassDirection.SouthEast:
                            p.Y++;
                            break;
                        case CompassDirection.South:
                            p.X--;
                            p.Y += 2;
                            break;
                        case CompassDirection.SouthWest:
                            p.X--;
                            p.Y++;
                            break;
                        case CompassDirection.West:
                            p.X--;
                            break;
                        case CompassDirection.NorthWest:
                            p.Y--;
                            break;
                    }
                    break;
                case IsometricStyle.Staggered:
                    switch (dir)
                    {
                        case CompassDirection.North:
                            p.Y -= 2;
                            break;
                        case CompassDirection.NorthEast:
                            p.X += (startTile.Y & 1);
                            p.Y--;
                            break;
                        case CompassDirection.East:
                            p.X++;
                            break;
                        case CompassDirection.SouthEast:
                            p.Y++;
                            p.X += (startTile.Y & 1);
                            break;
                        case CompassDirection.South:
                            p.Y += 2;
                            break;
                        case CompassDirection.SouthWest:
                            p.Y++;
                            p.X += ((startTile.Y & 1) - 1);
                            break;
                        case CompassDirection.West:
                            p.X--;
                            break;
                        case CompassDirection.NorthWest:
                            p.Y--;
                            p.X += ((startTile.Y & 1 )- 1);
                            break;
                    }
                    break;
            }
            return p;
        }
Exemplo n.º 47
0
        protected virtual void ApplyRotation( CompassDirection dir )
        {
            mRotated = true;

            Cube.Face nextFace = CubeFace.AdjacentFace( dir );
            var backDir = nextFace.BackwardsDirectionFrom( CubeFace );

            float mass = Body.Mass;
            Body body = Body.DeepClone( nextFace.World );
            CubeFace.World.RemoveBody( Body );
            Body = body;
            Body.Mass = mass;

            float pastUpDirAngle = UpDir.Angle;
            float rotDif = UpDir.Angle - Rotation;

            UpDir = Cube.GetNextUpDirection( UpDir, dir, backDir );
            CubeFace = nextFace;
            Rotation -= rotDif;

            Body.Position = ComputeFacePosition().ToUnits();

            Velocity = Velocity.Rotate( UpDir.Angle - pastUpDirAngle );

            ReconstructBody();
        }
Exemplo n.º 48
0
        public List<Tuple<ILawnMower, string>> MowersWithMovementInstructions { get; } //string repsresents MovementInstructions

        public void AddLawnMower(int x, int y, CompassDirection initialHeading, string movementInstructions)
        {
            var lawnMower = new LawnMower(x, y, initialHeading, ref _lawn);

            MowersWithMovementInstructions.Add(new Tuple<ILawnMower, string>(lawnMower, movementInstructions));
        }
Exemplo n.º 49
0
 /// <summary>
 /// Returns the direction left of current.
 /// </summary>
 /// <param name="currentFacing"></param>
 /// <returns></returns>
 public CompassDirection TurnLeft(CompassDirection currentFacing)
 {
     var current = (int)currentFacing - 1;
     if (current == -1)
         current = 7;
     return (CompassDirection)current;
 }
Exemplo n.º 50
0
 /// <summary>
 /// Rotates the camera about the cube so that the face adjacent to the current edge in the 
 /// specified face-direction becomes the current face. The input direction is cube 
 /// orientation-agnostic. This is a convenience overload accepting a 
 /// Nullable&lt;CompassDirection&gt; as a parameter.
 /// </summary>
 /// <param name="direction">The direction to rotate towards, relative to the current 
 /// face, or null for no rotation.</param>
 public void Rotate( CompassDirection? direction )
 {
     if ( direction.HasValue )
         Rotate( direction.Value );
 }
 private void CreateRumble(CompassDirection direction)
 {
     var rumble = engine.CreateRumble(direction, RelativeHeight.AnyHeight);
       rumbles.Add((eDirection)direction, rumble);
 }
 private void CreateLight(CompassDirection direction)
 {
     var light = engine.CreateLight(direction, RelativeHeight.AnyHeight);
       lights.Add((eDirection)direction, light);
 }