程序清单8-11 将游戏区域清空
/// <summary>
/// Remove all of the gems present on the board.
/// </summary>
private void ClearBoard()
{
for (int x=0; x<BOARD_GEMS_ACROSS; x++)
{
for (int y=0; y<BOARD_GEMS_DOWN; y++)
{
// Does this location contain a gem?
if (_gameBoard[x,y] != null)
{
// Yes, so instruct it to terminate and then remove it from the
// board
_gameBoard[x, y].Terminate = true;
_gameBoard[x,y] = null;
}
}
}
}
UpdateForm函数可以将任何所需的信息从游戏引擎复制到游戏窗体中。我们唯一需要复制的是玩家的得分,但以后还有其他信息要添加的话(如生命数、能量、导弹数量等),将它们集中到一个函数中是很有用的。每当这些变量中的一个发生变化时,只需要调用该函数就可以将变化显示给玩家。
当修改了玩家的得分后(将它重置为0),必须从Reset函数中调用UpdateForm函数,UpdateForm函数如程序清单8-12所示。
程序清单8-12 使用游戏中的信息对窗体进行更新
/// <summary>
/// Copy information from the game on to the game form so that it can be
/// seen by the player.
/// </summary>
private void UpdateForm()
{
// Make sure we have finished initializing and we have a form to update
if (_gameForm != null)
{
// Set the player score
_gameForm.SetScore(_playerScore);
}
}