GAMES TWO: LESSON TWENTY-FOUR:
CONNECT THE DOTS

We will use the GENERIC_GRID and GENERIC_CELL classes from the last lesson:

GENERIC_GRID class source code
GENERIC_CELL class source code

We will extend these generic classes like so:

CD_GRID class source code
CD_CELL class source code

Here are the rest of the pages associated with this game:

Game Directions
Game Page
Applet class source code

Discussion:

There are two methods which you should pay special attention to in CD_GRID. First of all make sure that you can follow the logic in the collision_check method. A lot of how this method works depends on keeping track of the indexes of the map array and the targets array.

public void collision_check(){ int ploc = row*9+col; if(map[ploc]>0 && ploc != 0 ){ if( map[ploc] == targets[cnt].getValue() ){ targets[cnt].setValue(-1); map[ploc]=-1; cnt++; } else{ miss++; } } }

Also make sure that you understand how drawTargets works. Notice that there is a boolean value added to the call to draw in CD_CELL.

public void drawTargets(Graphics g){ int ploc=row*9+col; for(int i=0; i<targets.length; i++){ if(ploc==targets[i].getLocation() && map[ploc]>0) targets[i].draw(g,true); else targets[i].draw(g,false); } }

ASSIGNMENT:

Add a timer to the game so that the player's final score is based on how long it takes to clear the board. Add a penalty of five seconds for each miss to this score.