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 5 – game logic (bringing in the time element)


Our app isn't playable yet:

  • When a cell is clicked, its color must only show for a short period of time (say one second)

  • When a cell and its twin cell are clicked within a certain time interval, they must remain visible

Note

For code file for this section, refer to chapter 7\educ_memory_game\spirals\s05 in the code bundle.

All of this is coded in the mouseDown event handler, and we also need a variable lastCellClicked of type Cell in the Board class. Of course, this is exactly the cell which we get in the mouseDown event handler. So, we set this in line (5) in the following code snippet:

void onMouseDown(MouseEvent e) {
  // same code as in Spiral 4 - 
 if (cell.twin == lastCellClicked && lastCellClicked.shown) { (1)
   lastCellClicked.hidden = false;                            (2)
     if (memory.recalled)   memory.hide();                    (3)
   } else {
     new Timer(const Duration(milliseconds: 1000), () =>     cell.hidden...