程序清单8-7 CObjGem类的Position属性与Size属性重写
/// <summary>
/// Override the XPos property to calculate our actual position on demand
/// </summary>
public override float XPos
{
get
{
// Determine the position for the gem from 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
{
// Determine the position for the gem from its position within the
// board
return _game.BoardLeft + (_boardXPos * Width);
}
}
/// <summary>
/// Return the Width by querying the gem width from the game engine.
/// This means that if the gem width changes (e.g., the screen orientation
/// is changed resulting in new graphics being loaded), we always return
/// the correct value.
/// </summary>
public override int Width
{
get
{
return _game.GemWidth;
}
}
/// <summary>
/// Return the Width by querying the gem width from the game engine.
/// </summary>
public override int Height
{
get
{
return _game.GemHeight;
}
}