使用案例名称:启动飞机模拟.NET飞机模拟器
范围:飞机飞行模拟器
级别:用户目标
主要演员:用户
- 用户启动飞机模拟器
- 询问用户最大高度(上限)
- 询问用户的最小高度(地板)
- 飞机模拟器从机载位置,没有起飞或着陆
- 飞机开始上升到最大高度
- 飞机下降到minimun高度
- Repeate步骤5和6 ,直到用户结束模拟
这是我的问题。在.NET中,哪个Timer最适合Airplane类,它应该是Windows Forms定时器,基于服务器的定时器还是线程定时器?我试图让飞机以定时器间隔确定的速率上升/下降。希望这是有道理的。
我需要一些解释,请帮助!这里是我的班级
使用系统;使用System.Timers的 ;
命名ConsoleApplication1
{
class Airplane
{
public Airplane()
{
_currentAltitude = 0;
Timer _timer = new Timer();
_timer.Start();
Console.WriteLine("airplane started");
Console.ReadKey();
}
public const int MAXALLOWABLEHEIGHT = 30000;
public const int MINALLOWABLEHEIGHT = 15000;
private int _currentAltitude;
public int CurrentAltitude
{
get
{
return _currentAltitude;
}
set
{
_currentAltitude = value;
}
}
private bool airplaneIsDead = false;
// Define the delegate types
public delegate void GoneTooHigh(string msg);
public delegate void GoneTooLow(string msg);
// Define member variables of the above delegate types
private GoneTooHigh MaxHeightViolationList;
private GoneTooLow MinHeightVioloationList;
// Add members to the invocation lists using helper methods
public void OnGoneTooHigh(GoneTooHigh clientMethod)
{
MaxHeightViolationList = clientMethod;
}
public void OnGoneTooLow(GoneTooLow clientMethod)
{
MinHeightVioloationList = clientMethod;
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (_currentAltitude < MAXALLOWABLEHEIGHT)
{
_currentAltitude++;
}
else
{
_currentAltitude--;
}
}
}
}
我不一定关心等时间间隔。我的目标是'模拟''高度增加或减少的速度'。我的目标是延迟增加或减少。看到我的后续问题进一步澄清, http://stackoverflow.com/questions/1866026/model-view-seperation-airplane-simulator – dannyrosalex 2009-12-08 10:24:24