Esempio n. 1
0
        public void ExecuteInstructionWithWayPoint(ShipInstruction instruction)
        {
            switch (instruction.ShipCommand)
            {
            case ShipCommand.GoNorth:
                WayPoint.NorthCoord += instruction.UnitsToMove;
                break;

            case ShipCommand.GoSouth:
                WayPoint.NorthCoord -= instruction.UnitsToMove;
                break;

            case ShipCommand.GoEast:
                WayPoint.EastCoord += instruction.UnitsToMove;
                break;

            case ShipCommand.GoWest:
                WayPoint.EastCoord -= instruction.UnitsToMove;
                break;

            case ShipCommand.TurnLeft:
                WayPoint.RotateWayPointLeftRelToShip(instruction.UnitsToMove);
                break;

            case ShipCommand.TurnRight:
                WayPoint.RotateWayPointRightRelToShip(instruction.UnitsToMove);
                break;

            case ShipCommand.GoForward:
                NorthCoord += WayPoint.NorthCoord * instruction.UnitsToMove;
                EastCoord  += WayPoint.EastCoord * instruction.UnitsToMove;
                break;

            case ShipCommand.UnknownCommand:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        public void ExecuteInstruction(ShipInstruction instruction)
        {
            switch (instruction.ShipCommand)
            {
            case ShipCommand.GoNorth:
                NorthCoord += instruction.UnitsToMove;
                break;

            case ShipCommand.GoSouth:
                NorthCoord -= instruction.UnitsToMove;
                break;

            case ShipCommand.GoEast:
                EastCoord += instruction.UnitsToMove;
                break;

            case ShipCommand.GoWest:
                EastCoord -= instruction.UnitsToMove;
                break;

            case ShipCommand.TurnLeft:
                ShipBearing = ConvertDegreesToShipBearing((int)ShipBearing - instruction.UnitsToMove);
                break;

            case ShipCommand.TurnRight:
                ShipBearing = ConvertDegreesToShipBearing((int)ShipBearing + instruction.UnitsToMove);
                break;

            case ShipCommand.GoForward:
                GoForward(instruction.UnitsToMove);
                break;

            case ShipCommand.UnknownCommand:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }