Mastermind Project
FAQs
- Where do I start?
- How about some help with the layout of things on the display?
- How does the program determine which box to fill?
- Can I use the Grid Toolkit for the Guess Boxes?
- How are the secret code and current guess data represented?
- How do I choose a secret code?
- How about some help with the inexact match count?
- Help me find the bug in my program!
Mastermind Project - FAQs
Help With Layout of Display
Figure 17b.1 shows key points in TurtleSpace for the different objects in the Mastermind game.
So, how do you read this? Although the figure does not include all of the points, e.g., individual points for guess boxes and color choice squares, it does have key information. Table 17b.1 contains some key points to give you a feel for how to read the layout.
Coordinates | Description |
---|---|
|
Top-left corner of red choice square |
|
Top-left corner of [ClearChoice] button |
|
Bottom-left corner of "Sorry, You Lose." |
|
Bottom-left corner of "You Win!" |
|
Top-left corner of top-left guess box |
|
Bottom-left corner of first exact match feedback |
|
Bottom-left corner of first inexact match feedback |
|
More Help - Symbolic Constants
Since entering all of the symbolic constants for the many different objects that are displayed is not challenging, just takes time, I'll give you some of my symbolic constant definitions.
As I mentioned in the FAQ, Starting Out, back in lesson 12 (What If? - Predicates) there was a user-interface project that is a start at Mastermind. To help you get started with this project I gave you symbolic constants for the color choices strip. The size and location of the color choices strip is different for the game you are writing, but this demonstrates the power of symbolic constants. All you need to do is tweak a few of them and everything involved with the color choices strip will still work. Reread Looking Back which wraps up the UI project; in it I mention changing symbolic constants.
Symbolic Constants - Buttons
Where the Mastermind UI project only had a single button, the full game has three. In my program, I centered them with the centerline of the color choices strip. Here are the symbolic constants I used.
to buttonWidth output 100 end to hafButtonWid output quotient buttonWidth 2 end to buttonHeight output 25 end to buttonsX output difference colorChoicesMiddleX hafButtonWid end to clearChoiceButtonY output -30 end to guessButtonY output difference clearChoiceButtonY (sum buttonHeight 5) end to newGameButtonY output difference guessButtonY (sum buttonHeight 5) end |
Symbolic Constants - Guess Boxes
The top-left corner of each box must be computed. When you draw a new set of boxes, their Y coordinate will depend upon a guess number. Specifically, how many guesses have been made so far. You will iterate through four X coordinates, the left side of each box. When you are filling a box, you need to compute both the Y coordinate, just as when drawing all of the boxes, but the X coordinate will depend upon the number of boxes already filled. These coordinates can be computed from a top-left point and the sizes of a box and the gap between boxes.
Here are the symbolic constants I used.
|
Symbolic Constants - Hints, Exact and Inexact Match Counts
The Y coordinate for both the exact and inexact numbers (hints) must be computed just like the Y coordinate for the current set of guess boxes. To make things simple, I used the same procedure that I wrote for the guess boxes. But, given this, you need to subtract off the height of a guess box. This is because the guess boxes are drawn using the top-left corner as the starting point but label draws characters from a starting point of the lower-left corner of the text.
The symbolic constants I used for the X coordinates are straight-forward.
|
Symbolic Constants - Win/Lose Messages
The locations of the messages that notify the player that she has won or lost are just constants that I thought looked reasonable.
Here are the symbolic constants I used.
|