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 7 – using images


One improvement that certainly comes to mind is the use of pictures instead of colors as shown in the Using images screenshot. How difficult would that be? It turns out that this is surprisingly easy, because we already have the game logic firmly in place!

Note

For the code files of this section, refer to chapter 7\educ_memory_game in the code bundle. This is the master version of the game to be found in the root directory.

In the images folder, we supply a number of game pictures. Instead of the color property, we give the cell a String property (image), which will contain the name of the picture file. We then replace util\color.dart with util\images.dart, which contains an imageList variable with the image filenames. In util\random.dart, we will replace the color methods with the following code:

String randomImage() => randomListElement(imageList); 

The changes to memory.dart are also straightforward: replace the usedColor list with List usedImages = []; and the _getFreeRandomColor...