RU beehive logo ITEC dept promo banner
ITEC 380
2009spring
ibarland

homeinfolecturesexamshwsarchive

displayDeprecationNoticeAsOf(2009,05,31+01, "http://www.radford.edu/itec380/")

hw02
scheme structs

Due in class Feb.091.
Turn in on WebCT. In addition, if you're local, bring a hardcopy to class.

Over the course of a few homeworks, we'll develop a the fire-fighting-game, where a plane flies back and forth on the screen, trying to drop water onto fires which steadily grow bigger unless doused.

We design a program by identifying what types of data/objects the game needs, and then follow the design recipe for each one.

  1. Water-droplets have two pieces of information: the x- and y- coordinate of their location.

    1. (5pts) Develop a structure to represent droplets.
    2. (5pts) Make at least three examples of this type of data. (If you're clever, you can make examples which can double as either test-cases or expected-test-case-results, for the function(s) mentioned below. I suggest using define to name your examples “drop1”, “drop2”, “drop3”.)
    3. (5pts) Write a function move-droplet : droplet → droplet which takes in a droplet, and returns another droplet whose location is slightly below the previous. (This is reminiscent of grow-boa from lecture.)

      Include at least two test cases. By the way, in my solution, one of my test cases is (check-expect (fall-droplet drop1) drop2), since I'd previously “happened” to make my drop2 be just like drop1 but a bit lower.

    4. Read the info below, about creating scenes.

      (5pts) Write a function draw-droplet : droplet scene → scene which takes two inputs: a droplet and a scene, and returns a new scene with a blue-circle placed on it, representing the droplet.

      Include (at least) one test case. My test case was:

      (check-expect (draw-droplet drop2 (empty-scene 200 100))
                    (place-image (make-circle 10 'solid 'blue)
                                 50
                                 11
                                 (empty-scene 200 100))
            
      (To think about: What would be needed in Java, to create an automated test-case for a function which draw parts of a videogame?)

  2. Fires have two pieces of information: their intensity, and their location. (Fires are always located at the bottom of the screen.)

    1. (5pts) Develop a structure to represent fires.
    2. (5pts) Make at least three examples of this type of data.
    3. (5pts) Write a function grow-fire : fire → fire which takes in a fire, and returns another fire whose location is the same but whose intensity is a small amount higher.
    4. (5pts) Write a function fire->image : fire → image, which takes in a fire and returns an image. (Just the individaul image -- not an image-drawn-onto-a-scene.) (You can use the three various-sized images from the game assignment, or your own images.

      To get a gif/jpeg into DrScheme IDE, use Insert > Insert image…. You'll want to pass that image as one of the arguments to place-image.

      Use if or cond to select which image to return, based on the fire's intensity.) Include at least three test-cases.

    5. (5pts) Write a function draw-fire : fire scene → scene, analagous to draw-droplet. Include (at least) one test case. (Because fire->image has already been tested, I don't need to include test-cases here which verify that the fire's image is chosen correctly.)

How to create a scene (using scheme)

Recall from hw01, how we created images, and could even compose new images by using overlay or overlay/xy.

For this assignment, we'll use the same notion, but with one difference: We'll start with a scene, which is just an image except that when you put other images on top of it, they are clipped to the boundaries of the scene. Instead of overlay/xy, we'll use place-image (whose first input is any image, and the second input must be a scene).

(Here are docs for empty-scene and place-image.)

For example, you can evaluate the following expressions:

(empty-scene 200 100)


(define my-painting
  (place-image (rectangle 20 30 'solid 'blue)
               50
               60
               (empty-scene 200 100)))

my-painting


(place-image (circle 15 'solid 'orange)
             190
             40
             my-painting)

my-painting
Notice how place-image returns a new image; it doesn't modify its input values.

See also scheme-resources—ITEC380 Scheme resources.


Bored?

The following problems will be on future homeworks, but are not due as part of this homework.


1If you need an extra 24hrs, it will be granted, but try to have it completed by Monday.      

2You are not being asked to make one plane object and then change its fields -- we're making three different plane structs which are all similar to each other.      

homeinfolecturesexamshwsarchive

displayDeprecationNoticeAsOf(2009,05,31+01, "http://www.radford.edu/itec380/")
©2009, Ian Barland, Radford University
Last modified 2009.Feb.14 (Sat)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme