![]() |
![]() |
|
Due:
Standard instructions for all homeworks:
Complete the short fill-in-the-blank questions on the D2L quiz hw04a
.
Your answers should be valid racket expressions.
Do be sure to answer what the question is asking.
A team is:
- a name (non-empty string), AND
- an offense rating (real number), AND
- a defense rating (real number).
(5pts) Give a data definition (including examples of the data, and the template for any function which processes a team), as per steps 1-3 of the design recipe. Give at least three examples of a team.
(5pts) We’ll say one team is “greater” than another if its offense is higher than the other’s defense, and its defense is higher than the other’s offense. Write the function team>? to implement this. Follow all the steps of the design recipe1. As always, be sure to think about enough test-cases to cover the interesting situations (half of the pts). (In this case, six or seven should suffice, if they each cover a different situation.)
Familiarize yourself with the
arcade game
Galaga,
such as
this example.
We will write our own version,
starting with this homework (structs)
and finishing with next homework (lists).
Our simplified version need only deal with:
aliens parading back and forth,
diving (in an straight-line, perhaps angled or perhaps just vertical)
the player's ship ("ship"), and the missiles (both the player's and the alien's).
It does not need to deal with:
score,
having more than one level,
number-of-lives,
nor the “entrance” phase of the aliens.
Also, after an alien dives past the bottom of the screen,
any of the following are totally fine:
(a) keep diving forever (wrapping around),
(b) warp back to somewhere in the fleet,
(c) go into a gently travel back to fleet-position
mode, or
(d) disappear off the bottom.
Note that the first three options are checked by move-alien's unit tests;
the last option would be implemented as part of next week's assignment.
There are three types of things (objects) which our program will need to model: ships, missiles, and aliens. Code for each of these is similar in spirit to the Book functions (racket & java) we wrote in lecture). Here is our recording zoom-lect about figuring what fields we want.
tickis an abstract amount of time, but it’s convenient to declare it as the amount of time between two frames).
Remember to include both field-names and their types, in racket as well as Java.
API: Represent a key-event as a String, e.g. "x" or "right". In racket, you can compare two key-event?s with string=?, but key=? (from (require 2htdp/universe)) is more appropriate. Equal credit will be awarded, either way.
hint: Playing the demo above, we see there are only three key-presses that actually do anything, and firing is not something that changes the ship, so there are only two key-events that will have an effect. …Of course, you must always return some ship, even if it's the same as the one passed in.The Java and racket versions should work in the same way: returning a new object, rather than mutating any fields (Cf. enbiggened books, in the lecture notes).
hint: You'll want to handle stopping at the left/right edges (or perhaps, wrapping around). To do that, you need to know the size of the board. Use named-constants for that. Your unit-tests can refer to those named-constants; for convenience they can also assume that each dimension will be at least 100 pixels — i.e. they can assume values less than 100 aren't near the right-edge. Also, note that modulo can help handle wrapping (or, if not using integers, modulo/real as provided in student-extras.rkt).
The following problems only need be done in racket.
(5pts) In racket (only), write the function ship-handle-key, which takes a ship and a key-event? (e.g. "right" (which moves the ship to the right) or "y" (which does nothing)), and returns a new ship which has responded to that keypress.
hint: Playing the demo above, we see there are only three key-presses that actually do anything.
API: In racket, you can compare two key-event?s with string=?, but key=? (from (require 2htdp/universe)) is more appropriate. Equal credit will be awarded, either way.
Note: We will not use struct-inheritance3 This means some of our functions will essentially be repeating code, which is indeed annoying.
tickof time (one frame) passing. Do not take into account collisions with other objects, but do take into account wrapping around (if allowed).
hint: place-image is a handy function; it is similar to overlay/xy except that it crops the result to the background.
hint: For test-cases, include drawing a alien that is: (a) near the center of a small image; and (b) one that is mostly off the left-edge but has just a few pixels showing.
Note: Here’s an image you can (modify to) use in your test-cases, in addition to a solid rectangle or whatever else you might choose: house-with-flowers.rkt. If you place this file in the same directory as other functions, you can just (require "house-with-flowers.rkt"), and then use its exported id (house-with-flowers, coincidentally). You don’t need to submit, but do submit it on D2L so that I can run your program.
Note: My own version of draw-alien took in a second parameter — the "fleet's" location. Your version does not need to do this.
Note: If you want a diving-alien to be drawn differently — at an angle perhaps — you may, but that complication is certainly not required.
I suggest using simple shapes (like mere
isosceles-triangles or star-polygons) for
all your drawing-functions for the game.
You are welcome to be much fancier, though it won’t earn you additional credit.
You are welcome to use jpg/png/bitmaps, but make sure
you have the legal right to copy them —
e.g. from sites like
classroomclipart.com
or libraries like
planetcute
.
Please cite your source, of course!
All the above should have their tests, as well as signatures and (brief) purpose statements.
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |