RU beehive logo ITEC dept promo banner
ITEC 380
2012fall
ibarland
tlewis32

homelecturesexamshwsbreeze (snow day)

hw-ec-astr-finish
finishing asteroids
higher order functions

Due ...
In this assignment, we'll finish off the asteroids game (by adding bullets and detecting collisions), using higher-order functions like map, filter, and foldl as appropriate.

All non-drawing functions require at least two test cases! Good test cases and signature are worth about half the points for a function.

As mentioned on the discussion board:


  1. (4pts) Read the documentation for foldl and foldr (in DrRacket, hit F1 while the cursor is on each of those words; look at the version provided by racket3).
    1. What is the difference between what each function does?
    2. What is a difference in the resources used internally, when calling foldl or foldr?
    3. What term from lecture presumably accounts for the difference?
    4. If you have a task where either function will provide an acceptable answer, which version should you prefer?
  2. (0pts) Copy your previous solution to a new directory. Make sure your language level is “Intermediate plus lambda”.
  3. (6pts) Update move-asteroids so that it is a one-line call to map.
    Update draw-asteroids so that it is a one-line call to foldl.
  4. (3pts) Write a structure to represent a bullet. Note that in the original game, bullets time out after a while; what does that require as far as the information needed to represent a bullet?
  5. (2pts) Write move-bullet, which simply updates a bullet by one tick passing (but does not worry about collisions). Include test cases.
  6. (2pts) Write move-bullets. Include test cases.
  7. (3pts) Write a function representing the ship firing. It should return just one bullet. Include test cases.
  8. (1pt) Write draw-bullet, similar to how draw-astr worked.
  9. (2pts) Write draw-bullets.
  10. (3pts) Update your world structure, as well as move-world, draw-world and handle-keypress (or whatever you called the functions that did these tasks), to handle bullets.
    First just update the code and test to handle the extra field; we'll worry about all of firing, collisions, and bullets timing out later.
Now we will start to handle collisions of bullets and asteroids.

1Or at the least, all code except for possibly one-to-two line snippets that are straightforward.      

3except that the intermediate-student version only folds a single list at a time, which is the only way we've seen it in class.      

2 The version functions are provided by the intermediate-language is actually the same3, but the documentation/explanation is better for the racket version.      

4 I was also going to mention just the simple hack of using on-release (rather than on-key) to slow the player's rate of firing. Alas, on-release isn't working; a bug report has been submitted, and this has been fixed in the experimental nightly-build.      

homelecturesexamshwsbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2012.Oct.24 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme