21. Worksheet C

Create a new struct to hold a number and a posn.

You are going to create a new struct np that remembers both a number and a posn.

  1. Data definition: write a human-understandable description for np.

  2. Write the Racket code to define the np structure.

  3. Write two check-expect to verify that you get out the same information that you put in to the structure.

  4. Design and test np-set-num: np(old) number -> np(new) that sets the number in a given number-position structure.

  5. Design and test np-set-posn: np(old) posn -> np(new) that makes the posn of the np into the given posn.

Animation

Exercise 21.6.3 asks you to make a game where you try to click on a circle. The game counts the number of clicks until you succeed. The circle teleports randomly around the screen (not too quickly). Show the number of clicks when the game ends.

Use an np structure for the model.

Write a signature and two check-expects for each function in this section.

  1. Create two variables with different np structures to use later in your check-expects. Make sure the difference is obvious visually.
  2. Draw handler.
  3. Stopping: how will you decide to stop? Write a should-stop? function and modify your draw handler if necessary.
  4. Mouse handler.
  5. If you don’t have one already, add a check-expect for your mouse handler showing that clicking near the center of the circle, but not on it, still counts as a hit.
Last modified August 18, 2023: 2022-2023 End State (7352e87)