GAMES TWO: LESSON TWENTY-TWO:
ADD PAIRS: ANOTHER CELL-BASED GAME

To make this game we altered the GENERIC_CELL and GENERIC_GRID classes. We took these classes and made changes to provide us with the game behavior we desired. Inspect the following pages:
Game Directions
Game Page
Applet class source code
Grid class source code
Cell class source code

The most interesting method in this applet is the advance_AC() method found in the GENERIC_GRID class. Study it carefully and then trace how it is connected to the other two classes. The advance_AC() method is at the heart of this game applet.

public void advance_AC(){ active_cell.moveDown(); if(active_cell.y >= 195){ if(col>0 && col<8){ int ac = active_cell.getValue(); int sval = slots[col-1].getValue(); int tval = targets[col].getValue(); if(sval==0){ slots[col-1].setValue(ac); } else if(sval>0){ if(sval + ac == tval){ if(col<4) score++; else if(col<6) score+=2; else if(col<8) score+=3; } else score--; slots[col-1].setValue(0); } } cnt++; if(score<0) score=0; if(score>19) gameOn=false; else new_AC(); } }


ASSIGNMENT:

Rewrite the game so that the target numbers are 20, 25, 30, 35, 40, 45, and 50. You will have to make alterations in several places to make this game work with these target values. Think carefully about what numbers should appear in the falling cells.