程序清單8-11 將游戲區(qū)域清空
/// <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函數(shù)可以將任何所需的信息從游戲引擎復(fù)制到游戲窗體中。我們唯一需要復(fù)制的是玩家的得分,但以后還有其他信息要添加的話(如生命數(shù)、能量、導(dǎo)彈數(shù)量等),將它們集中到一個(gè)函數(shù)中是很有用的。每當(dāng)這些變量中的一個(gè)發(fā)生變化時(shí),只需要調(diào)用該函數(shù)就可以將變化顯示給玩家。
當(dāng)修改了玩家的得分后(將它重置為0),必須從Reset函數(shù)中調(diào)用UpdateForm函數(shù),UpdateForm函數(shù)如程序清單8-12所示。
程序清單8-12 使用游戲中的信息對(duì)窗體進(jìn)行更新
/// <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);
}
}