- Test-Driven Java Development(Second Edition)
- Alex Garcia Viktor Farcic
- 93字
- 2021-06-24 18:31:54
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.
推薦閱讀
- Mastering Entity Framework Core 2.0
- C# Programming Cookbook
- Learning RxJava
- Visual Basic程序設計(第3版):學習指導與練習
- 前端架構:從入門到微前端
- Python金融數據分析
- Mastering Python High Performance
- Linux環境編程:從應用到內核
- C語言程序設計案例式教程
- Bootstrap 4:Responsive Web Design
- Mastering openFrameworks:Creative Coding Demystified
- RealSenseTM互動開發實戰
- Web前端應用開發技術
- 前端架構設計
- 輕松學Scratch 3.0 少兒編程(全彩)