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

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.

主站蜘蛛池模板: 林西县| 常宁市| 雷州市| 南阳市| 格尔木市| 新建县| 上蔡县| 名山县| 连山| 霍林郭勒市| 花莲县| 安泽县| 调兵山市| 延寿县| 嫩江县| 苏尼特左旗| 铁岭市| 扶风县| 苍溪县| 罗源县| 福鼎市| 华池县| 吉木萨尔县| 桑日县| 保康县| 邵阳县| 南通市| 同德县| 安丘市| 台中市| 化州市| 白城市| 遵义县| 清水河县| 余庆县| 磐石市| 桂阳县| 安乡县| 巍山| 徐州市| 夏邑县|