XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
上QQ阅读APP看书,第一时间看更新

Time for action – building a GamePiece class – constructors

  1. Add two constructors to your GamePiece.vb file after the declarations:
    Public Sub New(type As String, suffix As String)
      _pieceType = type
      _pieceSuffix = suffix
    End Sub
    
    Public Sub New(type As String)
      _pieceType = type
      _pieceSuffix = ""
    End Sub

What just happened?

A constructor is run when an instance of the GamePiece class is created. By specifying two constructors, we will allow future code to create a GamePiece, by specifying a piece type with or without a suffix. If no suffix is specified, an empty suffix is assumed.

Updating a GamePiece

When a GamePiece is updated, you can change the piece type, the suffix, or both.