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

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.

主站蜘蛛池模板: 大名县| 浪卡子县| 汽车| 略阳县| 永丰县| 蓬安县| 罗甸县| 鄱阳县| 沅陵县| 皮山县| 威海市| 建水县| 金川县| 西昌市| 萨嘎县| 玛纳斯县| 临城县| 连江县| 涟源市| 莱芜市| 海淀区| 巴楚县| 秦安县| 新乐市| 铜陵市| 丹阳市| 安平县| 望都县| 游戏| 平遥县| 河间市| 商丘市| 桐庐县| 平顺县| 错那县| 灯塔市| 宣武区| 新竹县| 江陵县| 金乡县| 大同县|