Chapter 14. A Simple Game
This example involves refactoring and test-driven design.
Suppose we've decided to develop a system to play games in the tic-tac-toe family: squares occupied by different markers. In tic-tac-toe, you have a 3 × 3 grid, and you try to put your mark in three boxes in a row. In Connect Four by Hasbro, you have a rectangular grid and try to get four boxes in a row, but columns have to be filled from bottom to top. We'll start with a simplified version of tic-tac-toe and work our way up to the general case.
Here are some tests and the first version of the code (online at www.xp123.com/rwb).
import junit.framework.*; public class GameTest extends TestCase { public GameTest(String s) {super(s);} public void testDefaultMove() { ...
Get Refactoring Workbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.