Homework 4a
MUST BE DONE WITH YOUR PARTNER
MUST USE CHECKED-SIGNATURES!
PLEASE INCLUDE THE FOLLOWING AT THE TOP OF YOUR FILE, AFTER YOUR "require"s:
(define Image (signature (predicate image?))) (define KeyEvent (signature (predicate key-event?)))
There may be other built-in types that need similar signatures defined.
Due Date Tues at 9:00pm (Week 4)
Purpose Practice with program design with self-referential data
Exercises
Spelling Bee is a vocabulary game hosted by the New York Times. In this assignment, you will build a miniature version. Before reading any further, you should quickly play the New York Times’ Spelling Bee to understand the rules of the game.
In this very simple version of Spelling Bee, we will make several changes:
1. You will be able to enter nonsensical words,
2. You will not be able to correct mistakes (i.e., backspace will not work).
3. You will be able enter the same word several times, and
4. We won’t keep score.
Restrictions
1. You must not use "substring" or "explode" in this homework.
2. You may only use the "2htdp/image" and "2htdp/universe" libraries.
Exercise 1 Design data called "Letters" that holds the letters that are available for your simplified Spelling Bee. Note that one of the letters is distinguished as the required letter (i.e., the letter displayed at the center).
While there must be a distinguished center letter, your data definition must also support arbitrary many other letters.
Exercise 2 Design a function called "letters->image" to display the letters. The required letter must be distinguished in some way (e.g., by position, color, font, etc).
Exercise 3 A game of Spelling Bee must track the available letters and the partial word that the player has entered. Design data called "World" that holds this data.
Exercise 4 Design a function called "world->image" that displays a world. You can produce any image that you like, but it should clearly show both the available letters and the partial word.
Exercise 5 In a game of Spelling Bee, the player can either enter a letter to add to the current word, or press the "Enter" key to complete the word. Design a function with the following signature:
(: key-pressed (World KeyEvent -> World))
When the key is an available letter, "key-pressed" should produce a new world that adds that letter to the end of the current word. If the key is not an available letter, it should produce the previous world. If the key is the special string ‘"\r"‘ (which stands for the Enter key), it should produce a new world with the empty string for the current word, as long as the current word contains the center letter. If the player presses any other key, produce the previous world unchanged. In other words, your program should not produce an error if the player presses the "wrong" key.
Exercise 6 At this point, you have enough in place to play a basic game. Use the following world program to play spelling bee.
(: play (World -> World)) ; Uses big-bang to play a game of Spelling Bee, given Letters. (define (play w) (big-bang w (to-draw world->image) (on-key key-pressed)))
Exercise 7 In this exercise, you should make a new version of your program that additionally records & displays the words the player has found so far. This will require you to revise many of your definitions / functions, so please make versions of them with the suffix v2; e.g., Worldv2, world->imagev2, etc. While in normal practice, you would simply modify the existing code, this strategy allows us to give you feedback on both the initial version of your program and the modified version.