The Direction and types...
namespace MarsRover
{
abstract class Direction
{
public abstract Direction GetLeft();
public abstract Direction GetRight();
public abstract Position GetNext(Position pos);
}
class East : Direction
{
public override Direction GetLeft()
{
return new North();
}
public override Direction GetRight()
{
return new South();
}
public override Position GetNext(Position pos)
{
pos.X++;
return pos;
}
public override string ToString()
{
return "East";
}
}
}
The step and steps....
namespace MarsRover
{
abstract class Step
{
public abstract Position GetPosition(Position position);
}
class LeftRotation : Step
{
public override Position GetPosition(Position position)
{
position.Direction = position.Direction.GetLeft();
return position;
}
}
class Move : Step
{
public override Position GetPosition(Position position)
{
return position.Direction.GetNext(position);
}
}
}
namespace MarsRover
{
abstract class Plateau
{
public abstract bool IsPositionOutOfRange(Position pos);
}
class RectPlateau : Plateau
{
readonly int x;
readonly int y;
public RectPlateau(int x, int y)
{
this.x = x;
this.y = y;
}
public override bool IsPositionOutOfRange(Position pos)
{
return ((x < pos.X) || (y < pos.Y))
? true
: false;
}
}
}
No comments:
Post a Comment