home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / client / clientapplet / clientcell.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.6 KB  |  73 lines

  1. /*
  2.  * @(#)ClientCell.java
  3.  */
  4.  
  5. package games.Battle.client.ClientApplet;
  6.  
  7. import java.awt.*;
  8.  
  9. import games.Battle.shared.sys.*;
  10.  
  11. /**
  12.  * A cell which is placed inside a ClientBoard. It is responsible for
  13.  * maintaining client-speficic data for the game cell.
  14.  *
  15.  * @author Alex Nicolaou
  16.  * @author Jay Steele
  17.  */
  18. public class ClientCell extends Cell
  19. {
  20.     /**
  21.      * The cached width and height of a board cell
  22.      */
  23.     int width, height;
  24.  
  25.     /**
  26.      * Build a client cell, which is located at the given (r,c) pair
  27.      * @param r the cell's row
  28.      * @param c the cell's column
  29.      */
  30.     public ClientCell(int r, int c) {
  31.         super(r, c);
  32.         width = (int)((float)Symbols.BOARD_W / (float)Rules.cols);
  33.         height = (int)((float)Symbols.BOARD_H / (float)Rules.rows);
  34.     }
  35.  
  36.     /**
  37.      * Return which pipe region the (x,y) tuple is located in. Returns
  38.      * the one of Symbols.NORTH, Symbols.EAST, Symbols.WEST, 
  39.      * Symbols.SOUTH, or -1 if the pair does not fall inside the
  40.      * region of any pipes.
  41.      * @param x the x-coordinate
  42.      * @param y the y-coordinate
  43.      */
  44.     public int pipeRegion(int x, int y) {
  45.         float x0 = (float)0.0;
  46.         float x1 = (float)width / (float)3;
  47.         float x2 = x1 * (float)2;
  48.         float x3 = width;
  49.         float y0 = (float)0.0;
  50.         float y1 = (float)height / (float)3;
  51.         float y2 = y1 * (float)2;
  52.         float y3 = height;
  53.  
  54.         if (x > x1 && x < x2) {
  55.             if (y > y0 && y < y1) {
  56.                 return Symbols.NORTH;
  57.             } else if (y > y2 && y < y3) {
  58.                 return Symbols.SOUTH;
  59.             }
  60.         }
  61.  
  62.         if (y > y1 && y < y2) {
  63.             if (x > x0 && x < x1) {
  64.                 return Symbols.WEST;
  65.             } else if (x > x2 && x < x3) {
  66.                 return Symbols.EAST;
  67.             }
  68.         }
  69.  
  70.         return -1;
  71.     }
  72. }
  73.