| Due date: n/a; Thanksgiving; the solutions will be a part of problem set 11
Purpose:
This problem set will be released in two stages.
The goal of this problem set is to get to know the PLT class system and
to re-design the solutions for two prior problem sets as a class-oriented
design.
Drill:
HtDC: 2.2, 3.1, 4.6, 5.6, 5.7
HtDC: 10.1, 10.9, 11.1, 14.2, 14.3, 14.4, 14.5, 15.7, 15.11
HtDC:
18.7--18.13, 19.8/9, 19.12-19.15, 20.7--12, 21.1--3, 21.4,
23.9--13, 24.4, 24.10--14, 26.4/5, 27.6.1--4, 27.8 (all), 28.1, 28.2, 28.3,
28.4--6
Ignore all problems that ask you to draw things.
Required Problems:
Note: You must use the Module language level in
DrScheme and you must use the language #lang scheme.
-
Develop a class-based data representation for Exprs:
;; Expr is one of:
;; -- numbers;
;; -- an infix or prefix addition expression
;; with at least two sub-expressions; or
;; -- an infix or prefix multiplication expression
;; with at least two sub-expressions.
For a structure-oriented data representation, see problem 7.2. Use a class
to represent the occurrence of numbers in Exprs!
Design the method render for the
representation of Exprs. The
method consumes a number denoting the width available space and it
produces an image of the given Expr that fits within the
given space. For details of the algorithm, see again problem 7.2.
You may use the teachpacks htdp/image and
image-ops.ss but noting else to
create the images.
-
Re-design your space invader game using a class-oriented data
representation. Start with the class
space-invader-state% and
then design methods to it that support the following main function:
;; space-invader-state% -> state-invader-state%
;; launch a space invader game, use sis0 as initial state
(define (main sis0)
(big-bang sis0
(on-tick (lambda (sis) (send sis move)))
(on-key (lambda (sis ke) (send sis react ke)))
(on-draw (lambda (sis) (send sis render)))
(stop-when (lambda (sis) (send sis win-or-lose?))
(lambda (sis) (send sis last)))))
The methods mentioned perform the following computations:
move moves all objects in the current state;
react distributes keystrokes to the appropriate objects;
render turns the state of the world into a scene;
win-or-lose? determines whether the game is over; and
last turns a final state into a text image announcing the outcome.
The last image should announce the outcome of the game, and it should stay
up long enough so that the player sees it.
You may use the teachpack htdp/universe but noting else in
your program.
Your class-oriented design may use lists (but no other data structure) to
create compound pieces of data. If you need to compound data otherwise,
use classes to represent the data.
When you discover similarities of code within one class,
abstract over the patterns with a define/private
method. For similarities of code across different
classes, do not abstract (yet).
|
|