This project is similar -- in many ways -- to the grid walker, seed spreader program that we did in class on November 4. However, rather than playing the "Game of life" we will be starting to play the game of "Daleks". Worry not, you will be building this program for several weeks so each step will be relatively small.
For this assignment you will create the board on which the Daleks game is played. To do this you will need to draw a grid, then randomly populate the grid with 3 types of objects ... Daleks, rocks and Dr. Who. Here is how you should do that.
Probably the best way to start is to set up a 2-D array of ints. E.g.,
int board[][] = new int[20][20];
Each spot on the grid then corresponds to one rectangle on the board.
Into this grid you will put rocks, Daleks and Dr. Who, by assigning each a number. For example rocks might be 1; Daleks, 2; and Dr. Who, 3. Any location with a different value has nothing in it.
First put in rocks, about 5% of the squares on your applet should get rocks. The squares getting rocks should be selected randomly.
E.g., to put in one rock into a random location on the board you could do the following
board[(int)(Math.random()*board.length)][(int)(Math.random()*board[0].length)] = 1;
(You should be able to easily change the number of rocks, e.g., changing one or 2 characters in your program you should be able to change from 5% rocks to 22% rocks.)
Second, put in Daleks. About 10% of the squares should get Daleks. The squares getting Daleks should be selected randomly. If a square already has a rock, simply change that square to a Dalek. As with rocks, you should be able to easily change the number of Daleks.
Third, put in Dr. Who. There should be exactly 1 Dr. Who. The position of Dr. Who should be selected randomly. As with Daleks, if Dr. Who is put in the place where a rock is he should simply replace the rock. If Dr Who is put where a Dalek is, he should simply replace the Dalek.
The grid on which you set up this game should be at least 20 by 20, but any size greater than that would be fine also. In practice, your grid should not be too big because the spaces in the grid will be small..
Anything would be fine to represent rocks, Daleks and Dr. Who. (For instance, rocks could be black circles, Daleks red circles, and Dr. Who a blue Circle.) However, it is more fun to pick representations that suggest each. For instance, you might make a Dalek look like the ghosts from the midterm. Rocks could be the spirals we did in class for polar coordinates. Dr Who could be a stick figure. Alternately, you could dig out one of the lab assignments and put little pictures in for each. Note that there is extra credit involved here.
Here are some example images from my reference implementation. Note that I made the board 10 x 10 only to make the images below clearer. In my implementation, Daleks are like the midterm's ghosts, rocks are 3-lobed things and Dr. Who is a stick figure.
A board with about 5% rocks and 10% Daleks and 1 Dr Who. | A board with about 25% rocks, 50% Daleks and 1 Dr Who. |
Grading: | Applet | 100 pts |
---|
int appX = (int) getSize().getWidth(); int appY = (int) getSize().getHeight();
5 points | Have all of your characters automatically rescale as the size of the applet and the number of spaces on the board changes. All of your characters should always fit into their spaces regardless of how the board looks. |
---|---|
5 points max | Really interesting / artistic rocks, Daleks and Dr. Who. |