Spiral 7 – using images
One improvement that certainly comes to mind is 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 code files of this section, refer to chapter 7\educ_memory_game
in the code bundle.
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 replace util\color.dart
with util\images.dart
, which contains a variable imageList
with the image filenames. In util\random.dart
, we 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 method _getFreeRandomColor
with _getFreeRandomImage
, which uses the new list and method:
List usedImages...