Warning, lots of code today! I've been making an effort to model my solutions in ways that do not require special branching, or separate solutions for the 2 parts. Today was a fun one, and I think I came up with a good design, even if it's a little verbose!
At this point I think my enterprise development roots are showing. I've got inheritance, interfaces, strategies, factories, and even a DI container in my overall 2020 codebase 🤣
publicclassWaypointFerry:FerryBase{PointWaypoint=newPoint(0,0);publicWaypointFerry(Pointorigin,Pointwaypoint):base(origin){Waypoint=waypoint;}protectedoverridevoidMove(NavInstructioninstruction){if(instruction.Actionis'L'or'R'){Rotate(instruction.Action,instruction.Value);return;}if(instruction.Actionis'F'){for(inti=0;i<instruction.Value;i++){Location=newPoint(Location.X+Waypoint.X,Location.Y+Waypoint.Y);}return;}Waypoint=Move(Waypoint,GetDirection(instruction),instruction.Value);}protectedoverridevoidRotate(charturnDirection)=>Waypoint=turnDirectionswitch{'L'=>newPoint(-1*Waypoint.Y,Waypoint.X),'R'=>newPoint(Waypoint.Y,-1*Waypoint.X),_=>thrownewException($"turnDirection not supported: {turnDirection}")};}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Warning, lots of code today! I've been making an effort to model my solutions in ways that do not require special branching, or separate solutions for the 2 parts. Today was a fun one, and I think I came up with a good design, even if it's a little verbose!
At this point I think my enterprise development roots are showing. I've got inheritance, interfaces, strategies, factories, and even a DI container in my overall 2020 codebase 🤣
Part1
Part 2
FerryBase
Ferry (Part1's Implementation)
WaypointFerry (Part2's Implementation)