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

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.

主站蜘蛛池模板: 深泽县| 中卫市| 蕉岭县| 正镶白旗| 绵阳市| 玉山县| 东丰县| 布尔津县| 东丽区| 桐庐县| 当阳市| 邹平县| 贵定县| 凤凰县| 乐陵市| 元阳县| 楚雄市| 林州市| 长顺县| 永昌县| 瑞安市| 密山市| 黎平县| 清水县| 吉林省| 德惠市| 新兴县| 南乐县| 饶河县| 咸丰县| 灵石县| 普兰县| 日照市| 崇阳县| 湖南省| 三都| 大方县| 灵寿县| 临洮县| 合肥市| 察雅县|