我們還沒有對(duì)當(dāng)寶石的下落距離達(dá)到0時(shí)發(fā)生的情況進(jìn)行規(guī)定。游戲自身必須進(jìn)行檢測(cè)并對(duì)這種情形做出處理。稍后您將看到結(jié)果。
為了使下落距離具有一點(diǎn)視覺效果,我們需要對(duì)YPos屬性進(jìn)行修改。不只是根據(jù)_boardYPos來計(jì)算位置,現(xiàn)在還要考慮_fallDistance,這樣就可以將下落過程中寶石的最終位置計(jì)算出來。
接下來要對(duì)顯示在Nextpiece中的寶石進(jìn)行處理。由于它們不顯示在游戲區(qū)域中,對(duì)其XPos屬性及YPos屬性都進(jìn)行修改可以使寶石顯示在游戲窗體的右邊,就在窗體設(shè)計(jì)時(shí)創(chuàng)建的lblNextPiece標(biāo)簽下方。對(duì)于這種類型的寶石,令其YPos屬性根據(jù)_boardYPos值進(jìn)行計(jì)算,這樣可以指定一個(gè)寶石位于另一個(gè)寶石的下方。
修改后的XPos及YPos屬性如程序清單8-16所示。
程序清單8-16 修改后的YPos屬性考慮了_fallDistance及_gemType
/// <summary>
/// Override the XPos property to calculate our actual position on demand
/// </summary>
public override float XPos
{
get
{
switch (_gemType)
{
case GemTypes.NextGem:
// This is a "next piece" gem so determine its position
// within the form
return ((MainForm)(_game.GameForm)).ClientRectangle.
Width - Width;
default:
// This is an "in-board" gem so determine its position
// within the board
return _game.BoardLeft + (_boardXPos * Width);
}
}
}
/// <summary>
/// Override the YPos property to calculate our actual position on demand
/// </summary>
public override float YPos
{
get
{
switch (_gemType)
{
case GemTypes.NextGem:
// This is a "next piece" gem so determine its position
within the form
return ((MainForm)( _game.GameForm)).lblNextPiece.
ClientRectangle.Bottom
+ (_boardYPos * Height);
default:
// This is an "in-board" gem so determine its position
within the board
return _game.BoardTop + ((_boardYPos - _fallDistance)
* Height);
}
}
}