6.10

Assignment 6

home work!

Programming Language BSL+

Due Dates: this assignment will be submitted in two parts:
  • Wed 2/21 at 9:00pm: submit functions (and helpers) needed to render the game and move the paddle left and right.

  • Tues 2/27 at 9:00pm Wed 2/28 at 9:00pm: submit fully functioning game

Purpose To practice designing functions on lists, and extending and refining earlier programs.

Finger Exercises

Exercise 1 (Warmup) Consider the following data definition:

(define-struct small-shelled-crab [name color disposition size])
(define-struct large-shelled-crab [name color disposition size])
 
; A HermitCrab is one of:
; - (make-small-shelled-crab String String String PositiveNumber)
; - (make-large-shelled-crab String String String PositiveNumber)
; Interpretation:  A hermit crab either has a small shell or a large shell.  
; Each crab has a name (e.g., "Frank"), a color (e.g, "black"), a
; disposition (e.g., "friendly"), and a size in millimeters

Hermit crabs grow over time, and are also known to change shells. Specifically, if a hermit crab grows larger than 14 mm, it must find a large shell (as it will no longer fit in a small shell).

Design the function grow-crab, which accepts a HermitCrab and returns a HermitCrab that has grown by 1 mm.

Exercise 2 (Trickier) Complete the exercises from the lab on re-implementing Finite State Machines. For corresponding exercises from the book, work through section 12.8, and complete HtDP Exercise 230. The data definitions there are slightly different than the ones from lab. Use the finite state machine from Assignment 3.

Graded Exercises

Breakout!

In the game, Breakout, a player can move a paddle back and forth across the screen to bounce a ball around. Each time a ball hits one of the bricks on the screen it is destroyed. The goal of the game is to destroy all the bricks on the screen. If the ball falls below the bottom of the screen the player loses a life. If the player loses all their lives then they lose the game.

You can find an example of this game to play here.

For this assignment you will implement Breakout. Some code has been given to you to use in order to aid you with the physics of the game. The given code includes some constants, some data definitions, and some functions. You can download it here (right click > Save as ...). Please read over this code so that you know what it does.

Some notes:
  • The player should be able to move the paddle using the left and right arrow keys. The paddle should not be able to move beyond the boundaries of the screen.

  • When the ball hits a brick, it should flip its x-direction if it hits the brick horizontally and it should flip its y-direction if it hits the brick vertically. These things can happen simultaneously (if the ball hits the corner of a brick). If the ball hits more than one brick simultaneously then it should respond to at most one horizontal hit and at most one vertical hit (so never flip the x-direction or y-direction more than once in a given move).

  • You can decide how many lives a player should have. Make it easy to change this number so that people of varying skill levels can play your game.

  • When a player wins they should receive some "win" screen and when they lose they should receive some "lose" screen.

  • For extra credit try implementing one of the following:
    • bricks with different "health" levels (so if you hit them once their health decreases and if you hit them a certain number of times they break)

    • a scoring system or various levels in your game (it should be a finite number so the player can still win the game).

    • allow the player to decide how many rows and columns of bricks there are