以下snipets来自我的Form1代码。因为我的MessageBox.Show(...),我一直得到格式异常;我的Stop()方法中的声明。为什么?我究竟做错了什么? ...
private TimeSpan iterationDuration = TimeSpan.Zero;
...
public void Stop()
{
IsGameOver = true;
MessageBox.Show(String.Format("Game Over\n\nScore = {0}\n\n Time Duration = {l}", score, iterationDuration));
Application.Exit();
}
public void Start()
{
score = 0;
IsGameOver = false;
currentRedLightX = 0;
currentRedLightY = 0;
currentGreenLightX = width / 2;
currentGreenLightY = height / 2;
double minIterationDuration = SPEED; // 50 frames / sec
//game loop
while (!IsGameOver)
{
if (IsCollision())
{
score += 10;
}
DateTime startIterationTime = System.DateTime.Now;
UpdateGameState();
Render();
DateTime endIterationTime = System.DateTime.Now;
TimeSpan iterationDuration = endIterationTime - startIterationTime;
if (iterationDuration.TotalMilliseconds < minIterationDuration)
Thread.Sleep(Convert.ToInt32(minIterationDuration - iterationDuration.TotalMilliseconds));
Application.DoEvents();
}
}
答案 0 :(得分:6)
这是{l}
(小写L)而非1 ...