Tic-Tac-Toe Design
This is part of ../../Examples/TicTacToe-JavaFX-UnRedo
1 Overview
In this case of TicTacToe, the design is very close to the implementation because the needed non-GUI abstractions (the grid as an array of arrays of cells, etc.) are readily available in Java.
2 Design of Interactive GUI
We are not aiming to design for two players who are two different users with different UIDs. We aim only for the one user playing the game will be forced to fill X/O alternately. We intend to use GUI as provided by JavaFX.
2.1 Abstracted Primitives of JavaFX
- Association of Actions. User clicks on a cell. Depending on whose
turn it is this draws either an O or an X. JavaFX has
setOnMouseClicked
for such use. - JavaFX is rich in geometrical drawing primitives.
- We do not need to think about how the mouse moves, clicks, etc. All taken care of by OS, and Java + JavaFX libraries.
2.2 Forbidden Moves
- Only a cell that is a blank can become an O or an X.
- If a cell is already an X or an O, it must not be allowed to change.
- From these we can deduce that if nFilled == 9, no cell changes (i.e., moves) are possible.