Exercise 39.2.1
Develop the program make-city. It manages a collection of traffic lights. The program should provide four services:
After the development of the program is completed, develop a graphical user interface. Solution
Exercise 39.2.2
Develop make-master. The program consumes nothing, creates an
instance of the color-guessing game of section
, and
produces the master-check function as the only result. After the
player has guessed the answer, the function should simply respond with
``game over.'' A typical dialog would proceed as follows:
> (define master1 (make-master)) > (master-check 'red 'red) 'NothingCorrect > (master-check 'black 'pink) 'OneColorOccurs ...Compare this with the first dialogue in section
Add a service to make-master that reveals the hidden colors. That way a player who is tired of playing the game can find out the answer. Solution
Exercise 39.2.3
Develop make-hangman. The program consumes a list of words, creates a hangman game using the list, and produces the hangman-guess function as a result. A player would use the dialogue as follows:
> (define hangman-easy (make-hangman (list 'a 'an 'and 'able 'adler))) > (define hangman-difficult (make-hangman (list 'ardvark ...))) > (hangman-easy 'a) ``You won'' > (hangman-difficult 'a) (list 'head (list '_ '_ '_ '_ '_ '_)) > ...Compare this with the first dialogue in section
Add a service to make-master that reveals the chosen word.
An optional extension is to equip the program with a graphical user interface and a graphical view of the stick figure. Reuse existing solutions as much as possible. Solution
Exercise 39.2.4
Develop make-player. The program abstracts over the functions of
section
. Using the program, we can create several
players that wander through the campus:
(define player1 (make-player 'BioEngineering)) (define player2 (make-player 'MuddBuilding)) ...The argument to make-player specifies the initial position of the player.
Each instance should be able to produce
Extension: Two players may be in the same building at the same time, but they cannot interact. Extend the game so that two players in the same building can interact in some form. Solution
Exercise 39.2.5
Develop the program moving-pictures. It consumes a position and a
picture, that is, a list of shapes as defined in
sections
, and
,
and
. (Also see
for functions on
moving pictures.) It supports two services. First, it can place the shape
at a specific position. Second, it can reset the picture to the initially
given position. Solution