![]() |
![]() |
|
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:
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).
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 super-mario. We will write our own version, starting with this homework (structs) and finishing with next homework (lists). In our combine-yet-very-simplified version:
There are three types of things (objects) which our program will need to model:
players, turtles, and flagsplatforms.
tickis an abstract amount of time, but it’s convenient to declare it as the amount of time between two frames).
Note: No images are involved!
enabling assertions in Java: When running your program, the JVM's default behavior is to entirely ignore assertions (!?!). If using assert for your tests (just as we did in Book.java), run with3 java --enableassertions someClassName, or convince your IDE to do this.
or class: If you use a class, write a boilerplate constructor, but you don't have to deal with equals or hashCode.
Good style: Your racket and Java code should use the exact same field and class names, up to idiomatic differences like camelCase vs. hyphenated-names.
...won't compile.)
Of course: 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).
The following problems only need be done in racket.
Note: We will not use struct-inheritance4 This means some of our functions will essentially be repeating code, which is indeed annoying.
suggestion: To represent a direction, use the strings "left", "down", etc. rather than (say) the symbols like 'west or 'bottom, etc. . This will play nicely with the key-event?s of the 2htdp/universe library.
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: If you 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).
hint: place-image is a handy function; it is similar to overlay/xy except that it crops the result to the background. Another handy function is flip-horizontal.
hint: For test-cases, include drawing a turtle 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 may 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 nor D2L-submit this file, if you make no changes to it.
looking ahead: It is important that your drawing-function take in any background image. Later, when we make an overall game-object, we will initially pass in an empty-scene to draw-turtle, and then use that resulting image as the background for drawing the next turtle, and so on. This is also what we did for the meme-drawing functions, when we wanted to overlay two different strings on the same image.
I suggest using simple shapes (like mere
rectangles 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!
We can approximate collision-detection through a standard practice:
checking whether two rectangles (bounding-boxes) overlap.
To help you with this,
you may download and (require "overlap.rkt")
(but you shouldn't need to modify that file, nor print/D2L-submit it).
Remember, don’t copy/paste a .rkt file; right-click to download,
and then you can open it in DrRacket if you like.
For a future homework: Collisions with platforms will be more nuanced: we'll usually want to know if we're colliding with the top/bottom of a platform (which will halt our vertical-velocity), or if we're colliding with the left/right (which will halt our horizontal-velocity). Writeplayer-collide-platform-vert?. I suggest checking whether the wall overlaps either of two rectangles: a 1-pixel-thin rectangle at the top (or, at the bottom) of the player.
All the above should have their tests, as well as signatures and (brief) purpose statements.
glitchwill fall back to how correctly you handled the physics of turtles! ↩
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |