Due date: 11/1 @ 6:00 pm
This problem set covers abstraction and "loops".
HtDP Problems:
19.1.5, 20.2.4 (also see 20.2.2)
The additional problems cover abstraction from the perspective of a game
program.
Problem Background:
In a "space war" game, the player can fire shots at the UFO as it
descends. Visually a shot is a thin, yellow rectangle. The natural data
representation of a shot is a Posn; the position represents
the shot's top-most point.
For full credit, use Scheme loops for the final definitions of these
functions. Recall that you do not have to use loops for the first
draft. Programming is like writing; editing and improving the essay is
everything.
Problem 1:
Design the function shots-create, which consumes a natural
number and produces a list of Shots randomly placed in a 100
x 300 grid.
Problem 2:
Design the function shots-move. It consumes a list of
Shots and produces one. The purpose is to move each shot
upwards on a 100 x 300 scene by 3 pixels per tick of the clock.
Problem 3:
Design the function hit?, which consumes a
Rectangle and a list of shots and determines whether any of
the shots is inside the Rectangle.
(define-struct rectangle (x y width height))
;; A Rectangle is:
;; --- (make-rectangle Number Number Number Number)