July 2015
Intermediate to advanced
286 pages
6h 31m
English
Imagine if we could “draw” our masks in a separate file and feed that file to our program. We could play with all kinds of designs, without having to change our program at all! Let’s make that happen, using simple text files as input. The text files will be formatted something like the following, which shows one possible definition of a 10×10 grid.
| mask.txt | |
| | X........X |
| | ....XX.... |
| | ...XXXX... |
| | ....XX.... |
| | X........X |
| | X........X |
| | ....XX.... |
| | ...XXXX... |
| | ....XX.... |
| | X........X |
Every “X” indicates an “off” cell, and anything else (the “.” characters, in this case) will be an “on” cell.
We’ll implement this by introducing a helper method on our Mask class. Open mask.rb and add the following just after the start of that class, before ...
Read now
Unlock full access