CSU211 Assignment 12 - Spring 2004

The Number Guessing Game Revisited

Figure 63 (p. 331) shows most of the code for building a GUI for playing the number guessing game, and you completed this program as part of an earlier assignment (Exercise 22.3.1). Now you are to modify this program further in the following two ways:

  1. Have the program keep track of how many guesses the player has made and display a corresponding message each time a new guess is made. This message can simply say something like "Guesses: 5". Note that you will need to add another message item to the GUI to allow this to be displayed. To keep the model and view parts of the program as separate as possible, develop a function update-guesses that only updates the number of guesses but does not display anything on the GUI. The appropriate callback function will then call this function.
  2. In addition, have the program allow the user to play multiple games in a single session. To do this, the GUI will need to have an additional button on it labeled something like "Play Again". When this button is clicked, the program will need to be reset to start a new game, with a new target number to guess and the number of guesses reset accordingly. (The number of guesses displayed should always be the number in the current game, not the total number across multiple games.) To this end, and also to try to keep the model and view parts of the program separated from each other as much as possible, you should define the following two functions: This latter function should be called when the game first begins and whenever a new game is started (but it should not call create-window).

Be sure to follow the design recipe for designing functions that maintain state (Sections 36.3-36.4), including providing contracts and purposes for all state variables as well as effect statements and tests for all functions that directly initialize or update these state variables. (Do not provide tests for functions that update the GUI.)

Do not comment out the part of your program that creates the GUI. We will run your program when we grade it.