However, wait! Our game can only work if the same color appears in only two cells: a cell and its twin cell. Moreover, a cell can be hidden or not: can the color be seen or not? To take care of this, the Cell
class gets two new attributes:
Cell twin; bool hidden = true;
Note
For the code files of this section, refer to Chapter 7\code\educ_memory_game\spirals\s04
in the code bundle.
The _colorBox
method in the Board
class can now show the color of the cell when hidden
is false
(line (2)
); when hidden = true
(the default state), a neutral gray color will be used for the cell (line (1)
):
static const String COLOR_CODE = '#f0f0f0';
We also gave the gap
variable a better name, boxSize
:
void _colorBox(Cell cell) { var x = cell.column * boxSize; var y = cell.row * boxSize; context.beginPath(); if (cell.hidden) { context.fillStyle = COLOR_CODE; (1) } else { context.fillStyle = colorMap[cell.color]; (2...