7.4

Week 5 Set a

home work!

Programming Language BSL with List Abbreviations

Due Date Monday 9/30 at 9:00pm (Week 5)

Purpose To begin designing the project.

Finger Exercises

Exercise 1 From HTDP, 132 133 134

Language Change!

As noted above, please submit this assignment in BSL with List Abbreviations as opposed to BSL.

Graded Exercises

Pacman

In 1980, arcade video gaming was forever changed when Namco released the classic game Pac-Man. The player controls the titular character, a yellow circle with an ever-munching mouth, as it whizzes and whirls around a maze, hungry to eat all of the delicious dots within. Players need beware, however, the four terrible phantasms that haunt the game’s hallowed halls: Blinky, Pinky, Inky, and Clyde, each as hungry as Pac-Man, but with appetites far more sinister.

Throughout the semester, you will build increasingly complex iterations of the game, each one increasingly approaching the actual game. The first iteration that you do for this Problem Set will contain four components:
  • Pacman himself

  • the board

  • the dots

  • the power pellets

For now, a power pellet is just a dot that has a bigger size. In our version of the game, Pacman can occupy exactly one cell at a time. All dots and power pellets lie within one cell, and all walls lie along the edges of cells.

To make your lives easier, we have provided you with the file board.rkt (right click > save as), which provides the constants board-tiny and board-big. board-tiny is helpful for test development and debugging, but you should be sure your game works using either board.

board-tiny and board-big are each instances of a GameConfiguration. Note that you should leave the structure definitions commented out; they are provided by the given file.

; A GameConfiguration is a
;   (make-configuration Number Number Board Posn LoP LoP)
; (define-struct configuration [width height board start dots powers])
; Interpretation: A (make-configuration w h b s d p) is a game
; configuration where:
; - w is the width of the board (number of cells),
; - h is the height of the board (number of cells),
; - b is the board itself (which contains information about every
;   cell on the board)
; - s is pacman's initial location (cell position),
; - d provides the locations of dots, and
; - p provides the locations of power pellets.
 
; An LoP is one of
; - '()
; - (cons Posn LoP)
; Interpretation: A list of positions on the board (cell locations).
 
; A Posn is a (make-posn Natural Natural)
; where (0, 0) is in the upper-left hand corner
 
; A Board is one of:
; - '()
; - (cons Cell Board)
; Interpretation: A list of cells on the board.
 
; A Cell is a (make-pair Posn Walls)
; (define-struct pair [fst snd])
; Interpretation: A (make-pair p w) tracks information for a cell,
; where p represents the cell's location (cell position) and
; w represents all the walls adjacent to the cell.
 
; A Walls is one of:
; - '()
; - (cons Dir Walls)
; and represents the directions in which there are adjacent walls.
 
; A Dir is one of:
; - "up"
; - "down"
; - "left"
; - "right"

Exercise 2 Design a data definition for a game of Pacman, which supports and encapsulates all of the four components mentioned above. Note that Pacman himself has a direction he is currently traveling in, and his mouth should be able to open and close.

Exercise 3 Define examples for your data definitions as well as their templates.

Exercise 4 Design a function that given a GameConfiguration will create your initial world state. In this initial state, Pacman’s mouth should be open.

Exercise 5 Design the function for your to-draw handler. Be sure to use graphical constants as needed.

Exercise 6 Design a function for your on-key handler. The direction the player entered on the keyboard should become the direction Pacman is going. All other keystrokes should be ignored.

Exercise 7 Compose all of these functions into your main function, which should just take a GameConfiguration. For now, it’s not a very exciting game, as Pacman doesn’t move at all. This will change soon!