7.0

Week 5 Set a

home work!

Programming Language BSL with List Abbreviations

Due Date Monday 10/1 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

You and your partner are starting a new game studio, and you’ve come up with what you think might be a new hit game called "Minicraft". It’s a 2D block-based game where players place and smash different material, mine for gold, and blow things up with TNT. You’re pretty sure this is a clever new idea that no-one has thought of before, and think you can release the first version by the end-of-year holiday season.

The game is based on a 20x20 grid of squares, each of which might have different materials stacked up on them: grass, water, rock, gold, wood, or TNT. The player can move around the grid, but can’t walk on any block that has rock on it. The player is always facing a certain direction, which is based on the direction they last moved, and they can smash the top-most material that is in the square that is in front of them (not on the square that they are on, but on the one that is adjacent in the direction they are facing). They can also place new materials down, except only rock can be put on top of rock and only rock can be put on water.

The player has an infinite supply of all materials except gold. Gold only appears naturally on the map, and it always appears underneath existing materials. If the player smashes down to gold and then smashes the gold, they get a point. Gold appears periodically, and TNT, if it is placed, will explode after a certain amount of time, destroying all materials in the cell with the TNT and all cells immediately surrounding the TNT. Any gold destroyed by TNT does not earn points!

You have other exciting ideas for this game, but want to start small. You’ve identified a few critical aspects of the game:

  • Initial grid: The initial grid will have one element placed in every cell. The element will be randomly chosen for each cell, and will be either water, grass, or rock. The player should start in the upper-left hand corner, with a material selected and facing a direction of your choosing.

  • Movement: the arrow keys (Left, Right, Up, Down) move the player around the board, except you can’t move over spaces with rock on it.

  • Smashing/placing: the player can smash materials (using SPACE) that are in front of them, which means they need to have an orientation. Smashing gold earns points! The player can rotate through materials (using M) except gold and place (using P) them down on the space in front of them. Only rock can be put on rock and water; any material can be put on anything other than rock and water.

  • Gold: gold appears periodically (every 5 seconds), at a random position on the board, but only if that position has at least one material on it. If the random position has been mined down to bare earth, no gold is placed at that time interval.

  • TNT: TNT, once placed, starts ticking down from 30 seconds. Once it hits 0, it explodes, removing all materials from the space where the TNT was placed and all immediately surrounding spaces. Note that it explodes even if other materials have been placed on top of it.

In a past life, you were a designer, and have thought a bit about the user interface. In particular, you’ve decided that while on the grid of squares only the top material will be visible, with your character on top of them, on the side of the grid will be a stack showing the materials below you. It’s fine to truncate the stack to only show the top four materials, as intrepid players may place many materials down! You should also display the count of how many points have been collected by smashing gold, an arrow indicating which direction your player is facing, and what material is currently selected to be placed. That material will be changed by the M key, as mentioned above.

Exercise 2 Design however many data definitions (and related interpretations) you need which will allow you to build this game.

Hint: we’ve now seen two mappings; one in homework 4b and one in lab 4. Mappings are excellent ways of associating one kind of data with another, and with a grid system this complex, that kind of structure may prove incredibly useful.

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

Exercise 4 Design your main function. This will involve designing a wishlist of all of your main handlers and rendering function as well as writing a signature, purpose statment, and stub for each of them. A function stub is one with a proper function header but with a bogus output that matches the type of the signature’s output. You do not need to write tests for these functions on this assignment.

Defining the main function will also involve the next exercise. Note that your main function should be able to launch a square grid of any size and return the player’s score.

Exercise 5 Design a function that will create the initial state of your game. As random elements are involved, this will be tricky to test. You will learn ways to test large lists of data in a sane way shortly, so, for now, it is ok to not have totally exhaustive testing. You should still have total test coverage, but for helpers that output lists of random elements, it is ok to just test the length of the output as well as properties of just the first element in the output with check-satisfied and/or check-member-of.

Think about what a good argument to this function will be; it clearly must support making a 20x20 grid. Remember that 20 is a natural number; this should give you an idea of how your grid-generating code should be structured.