有人告诉我要把我的类设为抽象类:
public abstract class Airplane_Abstract
让一个名为move的方法成为虚方法
public virtual void Move()
{
//use the property to ensure that there is a valid position object
double radians = PlanePosition.Direction * (Math.PI / 180.0);
// change the x location by the x vector of the speed
PlanePosition.X_Coordinate += (int)(PlanePosition.Speed * Math.Cos(radians));
// change the y location by the y vector of the speed
PlanePosition.Y_Coordinate += (int)(PlanePosition.Speed * Math.Sin(radians));
}
还有4个方法应该是“纯虚拟方法”,这是什么意思?
它们现在都是这个样子:
public virtual void TurnRight()
{
// turn right relative to the airplane
if (PlanePosition.Direction >= 0 && PlanePosition.Direction < Position.MAX_COMPASS_DIRECTION)
PlanePosition.Direction += 1;
else
PlanePosition.Direction = Position.MIN_COMPASS_DIRECTION; //due north
}