Book Image

Learning Dart

Book Image

Learning Dart

Overview of this book

Table of Contents (19 chapters)
Learning Dart
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 * boxSize;
    var y = cell.row * boxSize;
    context.beginPath();
    if (cell.hidden) {
      context.fillStyle = COLOR_CODE;                     (1)
    } else {
      context.fillStyle = colorMap[cell.color];           (2)
  ...