![]() |
![]() |
|
Due:
(All times-of-day are start-of-class.)
Your submitted file should be named “hw04.rkt”,
plus any .java files.
Standard instructions for all homeworks:
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).
Give a datatype 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.
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 Pac-Man. We will write our own version, starting with this homework (structs) and finishing with next homework (lists). In our simplified version: We will write a simplified version which only needs to deal with: the pacman, ghosts, a few walls, and optional eating dots. It does not need to deal with: score, number-of-lives, having more than one level, wrapping around, power-dots, or ghosts becoming temporarily vulnerable.
There are three types of things (objects) which our program will need to model: pacmans, ghosts, and walls.
In addition to this datatype-definition, give at least two example pacman objects/structs, and the template for functions-handling-a-pacman (That is, don't ski; the design recipe's steps #2 and #3, in either language).
hint: Thoughts/advice on fields below.
Consistency: Your Java and racket should directly correspond t each other, nearly word-for-word. In particular, use the same field-names (except for idiomatic differences like using camelCase/snake_case for Java vs. kebab-case for racket).
Write glide-pacman which returns a new pacman object/struct one tick of time later, ignoring any exterior factors like walls or key-presses2.
The Java and racket versions should both work in the same way: returning a new object, rather than mutating any fields (Cf. how we did enbiggen in both racket and java).
Note: This method has nothing to do with a gui or drawing. Updating the pacman's fields is about the model, not the view. (Later we will write draw-pacman below, though in racket-only.)
Note: The background passed in might be any image. For example you can test with, which is exported from videogame-helpers.rkt as house-with-flowers.
Note: You are free to use the provided helper-function overlap? in videogame-helpers.rkt. It takes in any two rectangles; your pacman-overlap-wall can be a thin wrapper around overlap?.
You are not required to implement dots or power-dots. But if you want to, make structs and similar draw and overlap? functions for them. (It's not extra credit, but it's not too difficult and will make your game much more fun.)
We still don't have a running game yet. This will entail processing lists of walls and lists of ghosts. We'll deal with lists on the next homework (as an application of union and structure-types working together, rather than any new concept or syntax!).
Btw, one function we'll write on the next homework will be move-ghost, which will take a ghost and a list of walls. It will call glide-ghost, and see if that resulting object is overlapping any wall. If not, it returns that ghost; otherwise it returns the result of ghost-spin.
Many fields have multiple possible representations. For example, for a pacman facing/moving toward the top of the screen, I could see using 'north, or 270°, or 0,-1 as two fields, or a single fields (make-direction 0 -1) (if I defined a new struct direction), or the key-event? "up". These all have their strengths and weaknesses.
One thing guiding our choice might be the libraries that we want to interact with. In this case, we'll be using the 2htdp/image and 2htdp/universe libraries, so I'll point out the following:
According to Wikipedia, the original Pac-Man's color was rgb (251,244,31). This is very close to gold (rather than yellow).
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |