Homework 5b
MUST BE DONE WITH YOUR PARTNER
Reminder: whenever a problem says to design a function, we expect to see the full design recipe followed – signatures, purpose statements, relevant data definitions and templates, and sufficient examples, along with your actual solution. This is especially important in this project, since we are not explicitly telling you what data definitions to use!
Due Date Thurs at 9:00pm (Week 5)
Purpose Begin a multi-week project
Exercises
Q*Bert is an old arcade game that was available on lots of different early game platforms (as well as versions for personal computers). In it, the main character jumps up and down along a "3-D" staircase of blocks. Each block the player jumps on changes color, and the goal of the game is to turn all the blocks the same target color...while avoiding enemies, of course!
In this first part of the assignment, you won’t yet be creating a fully working game. In later parts, you’ll be adding game mechanics, as well as implementing new requirements (that this part won’t tell you about yet!), so that you can incrementally enhance your existing designs. Spend time planning your data definitions carefully now, and keep your code cleanly organized, to make those future enhancements easier to add...
A QBert board is a block pyramid of some given size. (The sample image has size 5.) Each block has a current count, and QBert’s goal is to jump on each block to decrease its count by one. In the first level, all the blocks start with a count of 1. In the second level, all the blocks start with a count of 2. As the levels increase, the number of times QBert needs to jump on each block increases as well. The goal of each level is to get the count of each block down to zero. (Stepping on blocks whose current counts are 0 does not make them go negative.)
Exercise 1 Design a data definition QBertBoard to represent the playing field of a particular game level. (You may need auxiliary data definitions, too.) Design a function make-board, that takes a level number and a board size, and constructs a QBertBoard containing the initial state of that level.
Exercise 2 Design a data definition QBertLevel that represents all the information in a given level of the game. You’ll need to keep track of—
at least!— where QBert is, how many steps they’ve taken, and the current board. You may want to track other information as well.
Exercise 3 QBert itself can hop from cell to cell on the board. Design a function that can move-qbert in any of the four diagonal directions.
Exercise 4 Design a function level-won? to detect if QBert has won the current QBertLevel.
Exercise 5 Design a function draw-level that renders a QBertLevel as an image (as in the screenshot above). The exact colors of your cubes do not matter, but your level must look like a pyramid of cubes as in this sample image, and you should have a distinct color for each possible current-count of a cube. (You may want to refer back to Homework 2a and Homework 4a for ideas on how to draw these images...)
Why might we have provided two different images for QBert? How could you usefully use them both...?
You can use and as images for your character.
Exercise 6 Design a simple main function that plays your game. For now, main should have
The ability to take in a size of the block-pyramid, and a level number to start from, and to build the appropriate initial level
A key-handler to move QBert around. (In my implementation, I used the numeric keypad digits 7, 9, 1 and 3 to move QBert in the four diagonal directions; you can choose other keys if you wish, but document them so that the TAs know how to play your game.)
Moving QBert should also cause the board cells to count down to zero. This may be too much to get working in this part of the project, but you are encouraged to start it now. (Document in your submission whether this counting-down actually works or not.)
A drawing handler
A way to detect a game-over condition: either by winning the level or by falling off the board.