text
stringlengths
0
897
if tileHit == null or tileHit.selected then continue
addToWord tileHit
trackMouseOnTiles
if scoreWord(wordInProgress) then
sounds.daDing.play
clearUsedTiles
else
sounds.land.play
deselectTiles
end if
wordInProgress = ""
end while
s = "Final Score: " + score
text.row = 2
text.column = 34 - s.len/2
print s
sounds.wow.play
```
This code uses the `time` intrinsic method, which is the number of seconds that have passed since the start of the session, to calculate an `endTime` once, when the program first runs. Then every time the `updateTime` method is called, we can calculate how much time is left, and print that at the top of the screen. A...
The main loop, lines 235-252, is mostly just calling all the other functions you defined and tested yesterday and today. It has a couple of smaller loops inside it. The one on line 236 updates all the tiles, until they have all slid into place. Line 237 checks for the timer running out, and breaks out of the main lo...
Once we know the user has clicked the mouse, we find the tile hit by calling `tileUnderMouse`, just like our old test code. But now there's a check for the case where the user failed to hit any tile (line 240), which is something we ignored before. Remember that `continue` jumps to the next iteration of the loop, ski...
If the user hit a valid tile, then we add it to the word (line 241), and track the mouse until it's released (line 242). Then we call that `scoreWord` function, which both updates the display, and tells us whether the word was valid. Depending on whether it was valid, we either clear the tiles used, or just deselect ...
Finally, we reset our `wordInProgress` variable, end our main loop, repeating all of the above until the timer runs out.
When that happens, the `break` on line 237 will jump down past the `end while`, where we print the final score, and play a "wow" sound to signal the end of the game.
This is a pretty long program — great job hanging in there! You should pause at this point and just play with it a bit. Grab some friends or family and challenge them. I got a score of 170 just now. Can you beat that?
## Taking it further
This is a complete, fun game as it is. But there are certainly ways you could extend it or modify it to make it your own, and I encourage you to try!
You could very easily change the number of rows and columns, since these magic numbers were stored in constants at the top of the program. I just changed mine from 5 columns to 6, and immediately found the word ANIME. What can you find?
One obvious change would be to the scoring formula. Replace `2 ^ word.len` with something else. It could be another formula based on the word length, or you could iterate over the letters of the word, and add a certain score for each letter, like in Scrabble. How does this affect your strategy when you play?
As written, the history (the words and scores previously obtained) always has the newest words at the top. That made sense to me, but maybe you'd like it better if the newest words were at the bottom. Can you figure out how to make that change? (Hint: look for where a new entry is beeing added to the `wordsFound` li...
A somewhat more substantial change would be to add a feature that lets the player destroy letters without making them part of a word. For example, maybe if the user right-clicks a letter, you clear that letter (select it and call `clearUsedTiles`), but subtract 50 points from the score. This really enhances the strat...
Or, consider giving the user some way to clear all the letters at once and get a fresh set, for those times when you feel like you've just gotten rotten luck on the draw. Perhaps detect when a certain key has been pressed (with `key.available` and `key.get`), and in that case, select all tiles and call `clearUsedTiles...
A> **Chapter Review**
A> - You finished a word game, your longest and most sophisticated program yet.
A> - You probably got some practice debugging and tracking down typos. This is an important skill and well worth practicing!
A> - You considered ways to go beyond the code in the book, changing things and adding features to make it your own.
{chapterHead: "Day 25: Tile Display", startingPageNum:305}
{width: "50%"}
![](Chapter25.svg)
Q> Testing leads to failure, and failure leads to understanding.
Q>— Burt Rutan (aerospace engineer and entrepreneur)
A> **Chapter Objectives**
A> - Learn the last type of Mini Micro graphics display, `TileDisplay`.
A> - Get familiar with presenting grid-based data or images.
A> - Learn to draw hexagonal grids as well as rectangular ones.
You've learned a lot about Mini Micro's sophisticated display system by now. To review, it has eight display layers, each of which can be configured to any of the following modes:
| 0 | off | no display |
| 1 | solid color | displays one color over the whole screen |
| 2 | text | 26 row, 68 column text display |
| 3 | pixel | 960 by 640 (by default) pixel display |
| 4 | tile | displays a rectangular grid of small images |
| 5 | sprite | displays a set of scaleable, rotatable, resizable images |
Most of these were covered on Day 19, though pixel displays were covered on Day 18, and sprite displays on Day 22. The only display mode we haven't explored yet is `tile` mode.
So today, let's do that! After today, your training in Mini Micro graphics will be complete.
## TileDisplay
The big idea with a `TileDisplay` is that it takes little rectangular sub-images from a source image called a "tile set," and places them into a grid of locations on the screen.
![Overview of how TileDisplay works. Rectangular portions of a tile set (SimplePlatformTiles.png, *left*) are mapped to rectangular portions of the display (*right*). That happy character standing on the bridge is a Sprite, but everything else on screen is a TileDisplay. Grid lines have been added for reference.](Tile...
{i:"`/sys/demo`,`platformer`"}
The figure above shows one of the built-in images (`/sys/pics/SimplePlatformTiles.png`) on the left, with grid lines added so you can see where the tiles are. Such an image is called a *tile set*. On the right is a screen shot of the platform demo (`/sys/demo/platformer.ms`), also with reference lines added. Each of...
tile set
: an image composed of a rectangular grid of smaller images intended to be used with a tile display
tile
: one of those little images in a tile set
tile display
: a display composed of rectangular cells, each displaying zero or one tiles from a tile set; in Mini Micro, represented by the `TileDisplay` class
cell
: one of those little rectangular areas of the display