BaseRobot というクラスがあります。次のコードを含む:
//=== Defines the possible orientation of the robot.
//=== Note the order is important to allow cycling to be performed in a meaningful manner.
public enum Compass
{
North, East, South, West
};
//=== The basic robot.
public class BaseRobot
{
//--- The behaviour properties that were identified, together with associated state.
//--- The robot identification number.
private int mId;
public int id
{
get { return mId; }
}
//--- the direction in which the robot is currently facing.
private Compass mOrientation;
public Compass Orientation
{
get { return mOrientation; }
set { mOrientation = value; }
}
//--- The robot's current position.
private Point mPosition;
public Point Position
{
get { return mPosition; }
}
//--- the robot's home position, where it was originally created.
public Point mHome;
public Point Home
{
get { return mHome; }
}
//--- Turn the orientation left (anti-clockwise) or right (clockwise).
//--- Implementation relies on the N, E, S, W ordering of the enumeration values to allow the arithmetic to work.
public void TurnLeft()
{
--mOrientation;
if (mOrientation < 0) mOrientation = Compass.West;
} // end turnLeft method.
public void TurnRight()
{
mOrientation = (Compass)(((int)mOrientation + 1) % 4);
} // end turnRight method.
//--- Move one unit forward in the current orientation.
public void Move()
{
switch (mOrientation)
{
case Compass.North: mPosition.Y++; break;
case Compass.East: mPosition.X++; break;
case Compass.South: mPosition.Y--; break;
case Compass.West: mPosition.X--; break;
}
} // end Move method.
//--- Constructor methods.
public BaseRobot(int aId)
{
mId = aId;
mHome.X = 0;
mHome = new Point(0, 0);
mPosition = mHome;
}
public BaseRobot(int aId, int aX, int aY)
{
mId = aId;
mHome = new Point(aX, aY);
mPosition = mHome;
} // end BaseRobot constructor methods.
}
プログラム クラスでは、このコードからオブジェクト、メソッド、およびプロパティを呼び出して、ロボットのホーム、向き、位置などのロボットのステータスに関する情報を表示しようとしています。次のようなものを表示するコンソールを探しています。
ロボットのホームは <0,0> 北向きで、現在 <0,0> にあります
これを達成する方法についてのアイデアはありますか?