O'Reilly logo

Learning Dart by Ivo Balbaert, Dzenan Ridjanovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Spiral 4 – implementing the rules

But wait, our game can only work if the same color only appears in two cells: a cell and its twin cell. Moreover, a cell can be hidden or not, that is, the color can be seen or not? To take care of this, the Cell class gets two new attributes:

  Cell twin;
  bool hidden = true;

Note

For code files of this section, refer to chapter 7\educ_memory_game\spirals\s04 in the code bundle.

The method _colorBox 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 that 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required