home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / shared / sys / board.java next >
Encoding:
Java Source  |  1996-08-14  |  2.0 KB  |  88 lines

  1. /*
  2.  * @(#)Board.java
  3.  */
  4. package games.Battle.shared.sys;
  5.  
  6. /**
  7.  * Board is an abstract base class for the 
  8.  * client and server's representations of the
  9.  * game board. It defines the minimal interface that the board must
  10.  * have in any client or server.
  11.  *
  12.  * @version 1.00
  13.  * @author Jay Steele
  14.  * @author Alex Nicolaou
  15.  */
  16.  
  17. public abstract class Board
  18. {
  19.     /**
  20.      * A way to access the single dimensional array as a two dimensional
  21.      * array when it is convenient to do so.
  22.      */
  23.     Grid grid;
  24.  
  25.     /**
  26.      * Builds a generic board and fills it with cells. The abstract
  27.      * method makeCell(r,c) is called to actually obtain a cell. This
  28.      * method must be defined in derived classes to return a particular
  29.      * (client vs. server) cell type.
  30.      */
  31.     public Board() {
  32.         grid = new Grid(Rules.rows, Rules.cols);
  33.         for (int r=0; r< Rules.rows; r++) {
  34.             for (int c=0; c< Rules.cols; c++) {
  35.                 Cell cell = makeCell(r, c);
  36.                 grid.setCell(r, c, cell);
  37.             }
  38.         }
  39.     }
  40.  
  41.     /**
  42.      * Return a reference to this board's grid object
  43.      */
  44.     public Grid getGrid() {
  45.         return grid;
  46.     }
  47.  
  48.     /**
  49.      * implemented in derived classes, returns an 
  50.      * instance of a cell for a particular board class
  51.      * @param r the row
  52.      * @param c the column
  53.      */
  54.     public abstract Cell makeCell(int r, int c);
  55.  
  56.     /**
  57.      * return a reference to the cell at the given
  58.      * row and column
  59.      * @param r the row
  60.      * @param c the column
  61.      */
  62.     public Cell getCell(int r, int c) {
  63.         return (Cell)grid.getCell(r, c);
  64.     }
  65.  
  66.     /**
  67.      * clear the modified flag for all cells on the board
  68.      */
  69.     public void clearModified() {
  70.         for (int r=0; r<Rules.rows; r++) {
  71.             for (int c=0; c<Rules.cols; c++) {
  72.                 ((Cell)grid.getCell(r,c)).clearModified();
  73.             }
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * clear the terrainModified flag for all cells on the board
  79.      */
  80.     public void clearTerrainModified() {
  81.         for (int r=0; r<Rules.rows; r++) {
  82.             for (int c=0; c<Rules.cols; c++) {
  83.                 ((Cell)grid.getCell(r,c)).clearTerrainModified();
  84.             }
  85.         }
  86.     }
  87. }
  88.