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

Implementation

In order to track who should play next, we need to store who played last:

private char lastPlayer = '\0';

public void play(int x, int y) {
  checkAxis(x);
  checkAxis(y);
  setBox(x, y);
  lastPlayer = nextPlayer();
}

public char nextPlayer() {
  if (lastPlayer == 'X') {
    return 'O';
  }
  return 'X';
}

You are probably starting to get the hang of it. Tests are small and easy to write. With enough experience, it should take a minute, if not seconds, to write a test and as much time or less to write the implementation.

主站蜘蛛池模板: 宜君县| 黄大仙区| 青海省| 将乐县| 吴江市| 灌云县| 渭源县| 渝北区| 德安县| 伊金霍洛旗| 石首市| 安塞县| 鄯善县| 林口县| 佛学| 汉源县| 高邮市| 隆子县| 丰县| 林周县| 闸北区| 开封市| 西城区| 福泉市| 承德市| 无棣县| 黑山县| 五华县| 双江| 巴林右旗| 鹤壁市| 易门县| 大港区| 白河县| 平山县| 杂多县| 津南区| 当雄县| 云南省| 日土县| 黎川县|