コード例 #1
0
 public string NoIntersectionPoint(pointCoordinates point)
 {
     string text = " ";
     if (point.intersectionPoint == false)
         text = "There is no intersection!";
     return text ;
 }
コード例 #2
0
        public pointCoordinates GetFirstIntersection(pointCoordinates origin, Direction[] listOfMoves)
        {
            pointCoordinates[] jointPoints = new pointCoordinates[listOfMoves.Length+1];
            pointCoordinates intersectionPoint = new pointCoordinates { x = origin.x, y = origin.y, intersectionPoint=false };
            jointPoints[0].x = origin.x;
            jointPoints[0].y = origin.y;
            int i = 1;
            while (i <= listOfMoves.Length && intersectionPoint.intersectionPoint == false)
            {
                jointPoints[i].x = jointPoints[i - 1].x + move(origin,listOfMoves[i - 1]).x;
                jointPoints[i].y = jointPoints[i - 1].y + move(origin,listOfMoves[i - 1]).y;
                int j = i - 1;
                while (j >= 0)
                {
                    if (jointPoints[i].x == jointPoints[j].x && jointPoints[i].y == jointPoints[j].y)
                    {
                        intersectionPoint.x = jointPoints[i].x;
                        intersectionPoint.y = jointPoints[i].y;
                        intersectionPoint.intersectionPoint = true;
                    }
                    j--;
                }
                i++;
            }
            if (intersectionPoint.x == jointPoints[i - 3].x && intersectionPoint.y == jointPoints[i - 3].y)
            {
                intersectionPoint.x = jointPoints[i - 2].x;
                intersectionPoint.y = jointPoints[i - 2].y;
                intersectionPoint.intersectionPoint = true;
            }

            return intersectionPoint;
        }
コード例 #3
0
 public pointCoordinates move(pointCoordinates point, Direction direction)
 {
     switch (direction)
     {
         case Direction.up:
             point.y = point.y + 3;
             break;
         case Direction.down:
             point.y = point.y - 3;
             break;
         case Direction.left:
             point.x = point.x - 3;
             break;
         case Direction.right:
             point.x = point.x + 3;
             break;
     }
     return point;
 }
コード例 #4
0
 public void TestMethodForMoveFunctionRight()
 {
     pointCoordinates origin = new pointCoordinates { x = 0, y = 0 };
     Assert.AreEqual(new pointCoordinates { x = 3, y = 0 }, move(origin, Direction.right));
 }
コード例 #5
0
 public void TestMethodForMoveFunctionDown()
 {
     pointCoordinates origin = new pointCoordinates { x = 0, y = 0 };
     Assert.AreEqual(new pointCoordinates { x = 0, y = -3 }, move(origin, Direction.down));
 }
コード例 #6
0
 public void TestMethodWithTwoIntersections()
 {
     pointCoordinates origin = new pointCoordinates { x = 0, y = 0, intersectionPoint = false };
     Direction[] listOfDirections = new Direction[] { Direction.up, Direction.right, Direction.right, Direction.up, Direction.left, Direction.down, Direction.down, Direction.right, Direction.up };
     Assert.AreEqual(new pointCoordinates { x = 3, y = 3, intersectionPoint = true }, GetFirstIntersection(origin, listOfDirections));
 }
コード例 #7
0
 public void TestMethodWhereWeHaveNoIntersection()
 {
     pointCoordinates origin = new pointCoordinates { x = 0, y = 0, intersectionPoint = false };
     Direction[] listOfDirections = new Direction[] { Direction.up, Direction.right, Direction.up };
     Assert.AreEqual("There is no intersection!", NoIntersectionPoint(GetFirstIntersection(origin, listOfDirections)));
 }
コード例 #8
0
 public void TestMethodWhereWeGoBackwardsOnFourthMove()
 {
     pointCoordinates origin = new pointCoordinates { x = 0, y = 0, intersectionPoint = false };
     Direction[] listOfDirections = new Direction[] { Direction.up, Direction.right, Direction.up, Direction.down };
     Assert.AreEqual(new pointCoordinates { x = 3, y = 6, intersectionPoint = true }, GetFirstIntersection(origin, listOfDirections));
 }