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.
Grading: | Applet | 100 pts |
---|
int appX = (int) getSize().getWidth(); int appY = (int) getSize().getHeight();
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.