On this page:
1 Preparation
2 Many Numbers, Many Shapes
3 Shooting Shots
4 Project submission
6.10

Assignment 5: Many, Many, Many

Due: Friday, September 29, 11:59:59 PM EST.

ATTENTION, ATTENTION, ATTENTION: The following should be completed in cooperation with your assigned partner from lab 7. (Partner assignments are listed on Piazza.) You may not share code for this assignment with your previous partner.

You must use the design recipe and The Style guidelines to receive full credit.

1 Preparation

Make sure you have read and studied chapters 9 and 10 of Part II of HtDP2e.

2 Many Numbers, Many Shapes

Create a file list.rkt for this part of the assignment. Use the standard file header at the top of the file.

You may list your solutions in the order given here.

Exercise 1 Develop a data definition ManyNumbers which can store arbitrarily many numbers. Note, you have to develop your own data definition, you may only use built-in primitive types and you may not use any existing built-in data structures, you have to design your own data structures.

Exercise 2 Develop a data and structure definition for storing pairs of numbers representing x and y coordinates.

Exercise 3 Develop a data definition ManyPairs which can store arbitrarily many pairs of numbers using the data definition from the previous exercise.

Exercise 4 Write the templates for all of the three data definitions you have defined.

Exercise 5 Design a function, which, given ManyPairs, draws all of the points as circles with radius 10 on the same empty scene, producing the resulting image.

Exercise 6 Design a function, which, given ManyPairs and two numbers for x and y coordinates, creates a larger ManyPairs with all of the coordinates plus the new pair of coordinates.

Exercise 7 Using the functions you developed in exercise 5 and 6, design a big-bang program which places a circle on every mouse event at the location of the mouse event.

3 Shooting Shots

Create a file invader-shots.rkt for this part of the assignment. Use the standard file header at the top of the file.

Starting from the simplified Space Invaders game (invaders.rkt), develop a Shots data definition for representing an arbitrary number of Shots.

Design a function any-shots-hit-invader? that takes a Shots and an invader and produces true if any shot in the collection hits the invader. You may find shot-hits-invader? useful when defining this function.

Design a function remove-all-over-top that takes a Shots and removes all of the shots that have gone over the top of the screen. You may find shot-over-top? useful when defining this function.

Design a function shots-tock that takes a Shots and advances each shot upward and eliminates any shot that has gone over the top of the screen. You may find shot-tock useful when defining this function.

Design a function shots-draw-on that draws all of the given shots on the given scene. You may find shot-draw-on useful when defining this function.

Now redesign the simplified Space Invaders game to allow the player to shoot as many shots as they’d like. The representation of a Game can be changed to the following (note there is no longer a need to represent two distinct states for "aiming" and "firing"):

; A Game is a (make-game Invader Base Shots)
(define-struct game (inv base shots))
; Interp: game state with an arbitrary number of shots fired.

Define a main function that consumes an integer i and launches Space Invaders game with the invader in the upper right corner, the base at position i, and no shots fired.

Redesign game-draw, game-tock, game-key, and game-over? and any appropriate helper functions so that a shot is fired any time the player presses "space". The invader should reset to the top left any time a shot hits it. The game is over if the invader reaches the bottom of the scene.

4 Project submission

You should submit all files: list.rkt and invader-shots.rkt.

Submit your files directly to the submit server by uploading them. Select each of these files individually using the “Browse” button. Once you have selected all the files, press the “Submit project!” button. You do not need to put them in a zip file.