GamePiece.vb

 ' Storage class for chess piece attributes.

Public Class CGamePiece


    Private mCurrentType As Integer ' this object's type
    Private mPieceImage As Bitmap ' this object's image

    ' default display location
    Private mLocationRectangle As Rectangle = _
       New Rectangle(0, 0, 45, 45)

    ' construct piece
    Public Sub New( _
       ByVal xLocation As Integer, ByVal yLocation As Integer, _
       ByVal sourceImage As Bitmap)

        mLocationRectangle.X = xLocation ' set current x location
        mLocationRectangle.Y = yLocation ' set current y location

        ' obtain pieceImage from section of sourceImage
        mPieceImage = sourceImage.Clone(New Rectangle(1, _
           0, 34, 34), Drawing.Imaging.PixelFormat.DontCare)
    End Sub ' constructor

    ' draw this piece
    Public Sub Draw(ByVal graphicsObject As Graphics)
        graphicsObject.DrawImage(mPieceImage, mLocationRectangle)
    End Sub ' Draw

    ' obtain this piece's location rectangle
    Public ReadOnly Property LocationRectangle() As Rectangle
        Get
            Return mLocationRectangle
        End Get
    End Property ' LocationRectangle

    ' set this piece's location
    Public Sub SetLocation(ByVal xLocation As Integer, _
       ByVal yLocation As Integer)

        mLocationRectangle.X = xLocation
        mLocationRectangle.Y = yLocation
    End Sub ' SetLocation

End Class ' CChesspiece

Project Homepage: