![]() |
![]() |
|
Due:
Your submitted file should be named “hw04.rkt”, plus any .java files.
Standard instructions for all homeworks:
(This is the completion of hw04a, from D2L.) Consider the following information, which might be part of a sports-simulation:
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
Familiarize yourself with the arcade game Galaga, such as this example. We will write a simplified version which only needs to deal with: aliens parading back and forth, diving (in an angled-but-perhaps-straight line), 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, or the “entrance” phase of the aliens.
There are three types of things (objects) which our program will need to model: ships, missiles, and aliens.
(10pts)
Give a data-definition for a missile in Java — that is, a
hints: General tips for deciding what fields an object needs:
Imagine a friend is playing your game, and paused+saved it mid-play. When they later re-open that save-file, what info needs to be in there about a particular ball, so the program can exactly re-construct the ball how it was the moment your friend saved it?
Do not include information that is not part of the object itself.
Do NOT include information which never changes (is “invariant”) for a class. For example, if all instances of an object are always the same color, you wouldn’t have a field for the color. (You wouldn’t want 1000 objects, each with their own field, which all necessarily hold the exact same value.)
Sometimes x,y coordinates suffice to describe something’s position. However, sometimes more context might be needed. For example: what is the latitude and longitude of Virginia?
On a related note: For a problem below, you might be using
place-image , which places the center of an image at specified coordinates. If your internal representation is consonant with libraries you use, it can make things a smidgen easier.
Since this is Java, you will also need to create:
a constructor,
Note: You do not need to create getters/setters (and moreover, you should not). Moreover, for this homework and course, we will use immutable data, so you should not reassign to any fields2
enabling assertions in Java: When running your program, the JVM’s default behavior is to entirely ignore assertions (!?!). You should run with3java -enableassertions someClassName , or convince your IDE to do this.
The remaining functions are to be in racket (not Java); the Java version is just to compare and emphasize how similar the immutable-Java and racket programs will be.
Note: Although full racket does support struct-inheritance, we will not use it here
hint:place-image is a handy function; it is similar tooverlay/xy except that it crops the result to the background.
hint: For test-cases, include drawing a missile 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 print this file, but do submit it on D2L so that I can run your program.
Note: My own version ofdraw-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 rectangles) 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
.
Please site your source, of course!
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |