Beispiel #1
0
        public void CardinalDirections()
        {
            Vector2 northPoint     = new Vector2(0, -1);
            Vector2 northEastPoint = new Vector2(1, -1);
            Vector2 northWestPoint = new Vector2(-1, -1);
            Vector2 southPoint     = new Vector2(0, 1);
            Vector2 southEastPoint = new Vector2(1, 1);
            Vector2 southWestPoint = new Vector2(-1, 1);
            Vector2 eastPoint      = new Vector2(1, 0);
            Vector2 westPoint      = new Vector2(-1, 0);

            List <Vector2> points = new List <Vector2>()
            {
                northPoint, northEastPoint, northWestPoint,
                southPoint, southEastPoint, southWestPoint,
                eastPoint, westPoint
            };



            Vector2 initialPoint = new Vector2(0, 0);

            Vector2?actualPoint = Hole.GetClosestHole(initialPoint, Direction.South, points);

            Assert.IsTrue(actualPoint.HasValue);
            Assert.AreEqual(southPoint, actualPoint.GetValueOrDefault());
        }
Beispiel #2
0
        public void WraparoundAngle()
        {
            Vector2 initialPoint = new Vector2(0, 0);

            List <Vector2> points = new List <Vector2>()
            {
                new Vector2(2, 0),
                new Vector2(1, -0.2f)
            };

            Vector2 actualPoint = Hole.GetClosestHole(initialPoint, Direction.East, points).GetValueOrDefault();

            Assert.AreEqual(new Vector2(1, -0.2f), actualPoint);
        }
Beispiel #3
0
        public void NoViablePoints()
        {
            Vector2 initialPoint = new Vector2(0, 0);

            List <Vector2> points = new List <Vector2>()
            {
                new Vector2(2, 0),
                new Vector2(1, 0),
                new Vector2(3, 0)
            };

            Vector2?actualPoint = Hole.GetClosestHole(initialPoint, Direction.NorthEast, points);

            Assert.IsFalse(actualPoint.HasValue);
        }
Beispiel #4
0
        public void DifferentiatesBetweenDistance()
        {
            Vector2 initialPoint = new Vector2(0, 0);

            List <Vector2> points = new List <Vector2>()
            {
                new Vector2(2, 0),
                new Vector2(1, 0),
                new Vector2(3, 0)
            };

            Vector2 actualPoint = Hole.GetClosestHole(initialPoint, Direction.East, points).GetValueOrDefault();

            Assert.AreEqual(new Vector2(1, 0), actualPoint);
        }
Beispiel #5
0
    private void HandleKeyboard()
    {
//		foreach (KeyValuePair<KeyCode, Vector2> pair in m_keymap)
//		{
//			if (Input.GetKeyDown(pair.Key))
//			{
//				m_player.Destination = pair.Value;
//			}
//		}

        foreach (KeyValuePair <KeyCode, Direction> pair in m_keymap)
        {
            if (Input.GetKeyDown(pair.Key))
            {
                Vector2 currentPosition = m_player.Position;
                Vector2?closestHole     = Hole.GetClosestHole(currentPosition, pair.Value, m_holes);

                if (closestHole.HasValue)
                {
                    m_player.Destination = closestHole.GetValueOrDefault();
                }
            }
        }
    }