home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / orient / zone.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.0 KB  |  50 lines

  1. // Zone.java
  2. // 23.02.96
  3. //
  4. // a zone
  5.  
  6. package cybcerone.orient;
  7.  
  8. import java.awt.Rectangle;
  9.  
  10. import cybcerone.utils.Scaler;
  11.  
  12. /**
  13.  * A named zone on a map.
  14.  */
  15. public class Zone {
  16.   private Rectangle placement;
  17.   private String name;
  18.  
  19.   public Zone (String name, Rectangle placement) {
  20.     this.name = name;
  21.     this.placement = placement;
  22.   }
  23.  
  24.   public Zone (String name, int x1, int y1, int x2, int y2) {
  25.     this (name, Scaler.scale (x1, y1, x2-x1, y2-y1));
  26.   }
  27.  
  28.   /**
  29.    * of the form:  xxxx:yyyy:wwww:hhhh:child
  30.    */
  31.   public Zone (String text) {
  32.     this (text.substring (20),
  33.       Integer.parseInt (text.substring (0, 4)),
  34.       Integer.parseInt (text.substring (5, 9)),
  35.       Integer.parseInt (text.substring (10, 14)),
  36.       Integer.parseInt (text.substring (15, 19)));
  37.   }
  38.  
  39.   public Rectangle getCoords () { return placement; }
  40.   public String getName () { return name; }
  41.  
  42.   public String toString () {
  43.     return ("Zone[" + name + ", " + placement + "]");
  44.   }
  45.  
  46.   public boolean inside (int x, int y) {
  47.     return placement.inside (x, y);
  48.   }
  49. }
  50.