To simplify, we will start using colors instead of pictures to show in the grid. Up until now, we didn't implement the cell from the model. Let's do that in model\cell.dart
. We start simple by saying that the Cell
class has the row
, column
, and color
properties, and it belongs to a Memory
object passed in its constructor:
class Cell { int row, column; String color; Memory memory; Cell(this.memory, this.row, this.column); }
Note
For code files of this section, refer to chapter 7\educ_memory_game\spirals\s03
in the code bundle.
Because we need a collection of cells, it is a good idea to make a Cells
class, which contains List
. We give it an add
method and also an iterator, so that we will be able to use a for…in
statement to loop over the collection:
class Cells { List _list; Cells() { _list = new List(); } void add(Cell cell) { _list.add(cell); } Iterator get iterator => _list.iterator; }
We will need colors that are randomly assigned...