- 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.
推薦閱讀
- Data Visualization with D3 4.x Cookbook(Second Edition)
- Spring 5.0 Microservices(Second Edition)
- Apache Spark 2.x Machine Learning Cookbook
- NLTK基礎教程:用NLTK和Python庫構(gòu)建機器學習應用
- 實用防銹油配方與制備200例
- Java編程指南:基礎知識、類庫應用及案例設計
- JavaScript動態(tài)網(wǎng)頁開發(fā)詳解
- SQL Server 2016數(shù)據(jù)庫應用與開發(fā)習題解答與上機指導
- 精通Linux(第2版)
- HTML5從入門到精通 (第2版)
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- RSpec Essentials
- C#實踐教程(第2版)
- OpenCV 4計算機視覺項目實戰(zhàn)(原書第2版)
- RealSenseTM互動開發(fā)實戰(zhàn)