Time for action – GamePiece class methods – part 1 – updating

  1. Add the following methods to the GamePiece class:
      public void SetPiece(string type, string suffix)
      {
          pieceType = type;
          pieceSuffix = suffix;
      }
      
      public void SetPiece(string type)
      {
          SetPiece(type,"");
      }
    
      public void AddSuffix(string suffix)
      {
          if (!pieceSuffix.Contains(suffix))
              pieceSuffix += suffix;
      }
    
      public void RemoveSuffix(string suffix)
      {
          pieceSuffix = pieceSuffix.Replace(suffix, "");
      }

The first two methods are overloads with the same name, but different parameter lists. In a manner similar to the GamePiece constructors, code that wishes to update a GamePiece can pass it a piece type, and optionally a suffix.

Additional methods have been added to modify suffixes without changing the ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.