CS 110 Introduction to Computing

Project #8: Dr Who moves ... Dr. Who dies!


In this portion of building the Dr. Who game you will do 2 things: make Dr. Who move and allow Dr. Who to die. Each is described below.

Dr. Who is allowed to move 1 square in any direction from where he is. The direction is determined by a keystroke. So your program will need to implement the KeyListener interface. For example, the following switch statement within the keyPressed method in my version of the code determines the direction of Dr. Who's move.

        int xdir=0;
        int ydir=0;
	switch (ke.getKeyChar())
	    {
	    case 'a':
	    case 'A': xdir=-1;
		break;
	    case 'd':
	    case 'D': xdir=1;
		break;
	    case 'w':
	    case 'W': ydir=-1;
		break;
	    case 'x':
	    case 'X': ydir=1;
		break;
	    case 'q':
	    case 'Q': xdir=-1; ydir=-1;
		break;
	    case 'e':
	    case 'E': xdir=1; ydir=-1;
		break;
	    case 'z':
	    case 'Z': xdir=-1; ydir=1;
		break;
	    case 'c':
	    case 'C': xdir=1; ydir=1;
		break;
	    }
The remaining work to be done to to actually perform the move of Dr. Who -- being sure to keep him on the board. Also, Dr. Who may not move into a location that is currently occupied by either a Dalek or a rock. (If you do not currently do so, you will likely find it very useful to create variables like whoX and whoY that hold the current location of Dr. Who.)

After Dr. Who has has moved, you need to check whether or not Dr. Who can live in his new location. The rules for Dr. Who to remain alive are simple ... if a Dalek is within one square of Dr. Who, then the Dalek can touch him and he dies. Once Dr. Who is dead, he remains dead and cannot move. Show the fact that Dr. Who is dead somehow in your applet. For example, write in really big letters "R.I.P" across your applet, or turn the background color of your applet red, etc.


Due Date: November 23, at the beginning of class.
Submit:
Grading: Applet 100 pts

Notes

Recall that you can obtain the size of an applet by putting the following into your paint method:
int appX = (int) getSize().getWidth();
int appY = (int) getSize().getHeight();

The Future

There will be two more programming assignments to complete the Daleks game. In the first one, you will be giving Daleks the ability to move. Specifically, after each move made by Dr. Who every Dalek takes 1 step toward Dr. Who. The steps have the following possible results.
  1. The step causes a Dalek to walk on Dr. Who. Dr. Who dies and the game is lost.
  2. The step causes a Dalek to collide with a rock. The Dalek dies and disappears from the board.
  3. The step causes a Dalek to bump into another Dalek. Both Daleks die and a rock appears at the point where the Daleks bumped.
Note that this list is ordered. If 2 Daleks collide on Dr Who, then Dr. Who dies before the Daleks die.

The second assignment gives Dr. Who two new abilities: the "sonic screwdriver" and "hyperspatial jump". Both can be done only once per game. At any given time Dr. Who can unleash the "sonic screwdriver" which causes everything within 3 spaces of Dr. Who to disappear. "Hyperspatial jump" allows Dr. Who to jump from where he is on the board to somewhere else. Unfortunately the technology is random -- Dr. Who never knows where he will end up. Hence, he could jump and be right next to a Dalek, and therefor die.