BFOIT - Introduction to Computer Programming

Mastermind Project - FAQs

Help With Layout of Display

Figure 17b.1 shows key points in TurtleSpace for the different objects in the Mastermind game.

Pixel Circle Figure 17b.1

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
Table 17b.1

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
  to hafButtonWid
    output quotient buttonWidth 2
  to buttonHeight
    output 25
  to buttonsX
    output difference colorChoicesMiddleX hafButtonWid

  to clearChoiceButtonY
    output -30
  to guessButtonY
    output difference clearChoiceButtonY (sum buttonHeight 5)  
  to newGameButtonY
    output difference guessButtonY (sum buttonHeight 5)

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.

  to guessBoxSiz
    output 20
  to guessBoxesGap
    output 5
  to guessBoxesX
    output -15
  to guessesTopY
    output colorChoicesTopY  
  to maxGuesses
    output 10

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.

  to exactNumX
    output 100

  to inexactNumX  
    output 120

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.

  to youLoseX
    output -85
  to youLoseY
    output -135

  to youWinX
    output -52
  to youWinY
    output -140  

Back to Mastermind Project

Public Domain Mark
This work (BFOIT: Introduction to Computer Programming, by Guy M. Haas),
identified by Berkeley Foundation for Opportunities in IT (BFOIT),
is free of known copyright restrictions.