home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / enxle1f6 / src / games / battle / server / serverboard / servercell.java < prev   
Encoding:
Java Source  |  1996-08-14  |  3.4 KB  |  162 lines

  1. /*
  2.  * @(#)ServerCell.java
  3.  */
  4. package games.Battle.server.ServerBoard;
  5.  
  6. import games.Battle.shared.sys.*;
  7.  
  8. /**
  9.  * ServerCell implements functionality for game squares  that is specific to
  10.  * the server's needs.
  11.  *
  12.  * @version 1.00
  13.  * @author Jay Steele
  14.  * @author Alex Nicolaou
  15.  */
  16.  
  17. public class ServerCell extends Cell
  18. {
  19.     /**
  20.      * a boolean list of which players can see this cell. visible[player] is
  21.      * true if the given player can see the cell.
  22.      */
  23.     boolean visible[] = {false, false, false, false, false};
  24.  
  25.     /**
  26.      * the number of troops in each direction that are in combat. each turn
  27.      * if troops from an incoming pipe survive they are accumulated here to
  28.      * fight again on the following turn.
  29.      */
  30.     int fighting[] = { 0, 0, 0, 0};
  31.  
  32.     /**
  33.      * number of incoming paratroops from each opponent
  34.      */
  35.     int paratroops[] = { 0, 0, 0, 0, 0 };
  36.  
  37.     /**
  38.      * number of incoming shells from each opponent
  39.      */
  40.     int shells[] = { 0, 0, 0, 0, 0 };
  41.  
  42.     /**
  43.      * construct a new server cell at the given location
  44.      * @param r the row
  45.      * @param c the column
  46.      */
  47.     public ServerCell(int r, int c) {
  48.         super(r,c);
  49.     }
  50.  
  51.     /**
  52.      * return true if the given player can see this cell, false
  53.      * otherwise
  54.      */
  55.     public boolean isVisible(int player)     { return visible[player]; }
  56.  
  57.     /**
  58.      * set the visibility state for this cell
  59.      */
  60.     public final void setVisible(int player, boolean state) {
  61.         setModified();
  62.         visible[player] = state;
  63.     }
  64.  
  65.     /**
  66.      * tell us how many fighters are coming in from direction "d". These armies
  67.      * are "leftovers" from the last turn's combat.
  68.      * @param d the direction
  69.      */
  70.     public final int getFighters(int d) {
  71.         int f = fighting[d];
  72.         fighting[d] = 0;
  73.  
  74.         return f;
  75.     }
  76.     /**
  77.      * sets how many fighters are left over on a particular direction's pipe.
  78.      * @param d the direction
  79.      * @param f the number of units
  80.      */
  81.     public final void setFighters(int d, int f) {
  82.         if (f > 0)
  83.             fighting[d] = f;
  84.         else
  85.             fighting[d] = 0;
  86.     }
  87.  
  88.     /**
  89.      * set paratroops coming into the cell from a particular player.
  90.      * @param player the player number
  91.      * @param num ignored
  92.      */
  93.     public final int paratroop(int player, int num) {
  94.         if (paratroops[player] == 0) {
  95.             paratroops[player] = 5;
  96.             return 5;
  97.         }
  98.         else if (paratroops[player] < 15) {
  99.             paratroops[player] = 15;
  100.             return 10;
  101.         }
  102.         else if (paratroops[player] < 30) {
  103.             paratroops[player] = 30;
  104.             return 15;
  105.         }
  106.  
  107.         return 0;
  108.     }
  109.  
  110.     /**
  111.      * set shells coming into the cell from a particular player.
  112.      * @param player the player number
  113.      * @param num ignored
  114.      */
  115.     public final int artillery(int player, int num) {
  116.         if (shells[player] == 0) {
  117.             shells[player] = 5;
  118.             return 5;
  119.         }
  120.         else if (shells[player] < 15) {
  121.             shells[player] = 15;
  122.             return 10;
  123.         }
  124.         else if (shells[player] < 30) {
  125.             shells[player] = 30;
  126.             return 15;
  127.         }
  128.  
  129.         return 0;
  130.     }
  131.  
  132.     /**
  133.      * empty out all incoming paratroops
  134.      */
  135.     public final void clearParatroops() {
  136.         for (int i = 0; i < paratroops.length; i++) 
  137.             paratroops[i] = 0;
  138.     }
  139.  
  140.     /**
  141.      * empty out all incoming shells
  142.      */
  143.     public final void clearArtillery() {
  144.         for (int i = 0; i < shells.length; i++) 
  145.             shells[i] = 0;
  146.     }
  147.  
  148.     /**
  149.      * return how many paratroops of player p are incoming
  150.      */
  151.     public final int getParatroops(int p) {
  152.         return paratroops[p];
  153.     }
  154.  
  155.     /**
  156.      * return how many shells from player p are incoming
  157.      */
  158.     public final int getShells(int p) {
  159.         return shells[p];
  160.     }
  161. }
  162.