Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
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 the code file for this section, refer to Chapter 7\code\educ_memory_game\spirals\s05 in the code bundle.

All of this is coded in the mouseDown event handler and we also need a lastCellClicked variable of the Cell type in the Board class. Of course, this is exactly the cell we get in the mouseDown event handler. So, we will set it 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...