CS 5010 F '09
 
Pair Programming
The Recipes
The Style
Subversion
Assignments
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12

Problem Set 10

logo

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.


  1. 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.

  2. 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:
    1. move moves all objects in the current state;
    2. react distributes keystrokes to the appropriate objects;
    3. render turns the state of the world into a scene;
    4. win-or-lose? determines whether the game is over; and
    5. 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).


last updated on Wed Dec 2 17:58:10 EST 2009generated with PLT Scheme