- 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.
推薦閱讀
- WildFly:New Features
- Designing Machine Learning Systems with Python
- Android 應(yīng)用案例開發(fā)大全(第3版)
- MongoDB權(quán)威指南(第3版)
- Rust Essentials(Second Edition)
- C#程序設(shè)計
- Java Web開發(fā)就該這樣學(xué)
- Angular Design Patterns
- INSTANT Apache ServiceMix How-to
- WordPress Search Engine Optimization(Second Edition)
- 你真的會寫代碼嗎
- 大話代碼架構(gòu):項目實戰(zhàn)版
- Mastering ArcGIS Server Development with JavaScript
- Android熱門應(yīng)用開發(fā)詳解
- Flask Web開發(fā)實戰(zhàn):入門、進(jìn)階與原理解析