官术网_书友最值得收藏!

Time for action – building a GamePiece class: constructors

  1. Add two constructors to your GamePiece.cs file after the declarations:
      public GamePiece(string type, string suffix)
      {
          pieceType = type;
          pieceSuffix = suffix;
      }
    
      public GamePiece(string type)
      {
          pieceType = type;
          pieceSuffix = "";
      }

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.

主站蜘蛛池模板: 大姚县| 大宁县| 兴和县| 台中县| 望谟县| 乐至县| 商南县| 闽清县| 信丰县| 眉山市| 寻乌县| 阿坝| 连城县| 共和县| 永和县| 金川县| 临湘市| 平顺县| 巫山县| 桦川县| 祁阳县| 元谋县| 昌宁县| 博白县| 建瓯市| 上饶县| 三台县| 华亭县| 通山县| 汉川市| 凌源市| 固始县| 昌宁县| 扬州市| 阳曲县| 沁阳市| 泊头市| 阜平县| 万荣县| 龙海市| 肥城市|