Displaying Colored Mazes
Learn the code to display colored mazes in Ruby.
We'll cover the following...
We'll cover the following...
The ColoredGrid class
Now we can subclass Grid and create a ColoredGrid class, which will implement our Dijkstra-based coloring rules. The code is shown below:
Code explanation
Lines 5–8: Our subclass implements a writer method that we’ll call distances=(distances). The distances= method simply stores the distances mapping and caches the mapping’s largest distance value as @maximum.
Line 10: Our subclass also implements the method: background_color_for(cell).
Lines 12–14: ...