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

  1. // Unite.java
  2. // 18.03.96
  3. //
  4. // a room in a building
  5.  
  6. package cybcerone.utils;
  7.  
  8. import java.awt.Graphics;
  9. import java.awt.image.ImageObserver;
  10. import java.io.DataInputStream;
  11. import java.io.IOException;
  12.  
  13. /**
  14.  * A room in the main building, though it's flexible enough
  15.  * to be a room in any building.
  16.  */
  17. public class Unite implements Paintable, Literate, Mapable {
  18.   private String name;
  19.   private String buildingName;
  20.   private String levelName;
  21.   private String zoneName;
  22.  
  23.   private static final int xOffset = Scaler.scale (15);
  24.  
  25.   public Unite (String name, String building, String level, String zone) {
  26.     this.name = name;
  27.     this.buildingName = building;
  28.     this.levelName = level;
  29.     this.zoneName = zone;
  30.   }
  31.  
  32.   /** for reading */
  33.   public Unite () {
  34.   }
  35.  
  36.   public String getName () { return name; }
  37.   public String getBuildingName () { return buildingName; }
  38.   public String getLevelName () { return levelName; }
  39.   public String getZoneName () { return zoneName; }
  40.  
  41.   public String toString () {
  42.     return ("Unite[" + name + ", " + buildingName + ", "
  43.         + levelName + ", " + zoneName + "]");
  44.   }
  45.  
  46.   public void paint (Graphics g, int x, int y, ImageObserver observer) {
  47.     g.drawString (name, x + xOffset, y);
  48.   }
  49.  
  50.   public String getMapName () {
  51.     return (buildingName + "_" + levelName);
  52.   }
  53.   
  54.   public MapInfoPanel getMapInfoPanel (Appletlike app) {
  55.     UniteInfoPanel thePanel = new UniteInfoPanel (app);
  56.     thePanel.setData (this);
  57.     return thePanel;
  58.   }
  59.  
  60.   /** Right now this assumes all rooms are in BFSH2 */
  61.   synchronized public Object read (DataInputStream inStream) 
  62.     throws IOException {
  63.     
  64.     String line = inStream.readLine ();
  65.     
  66.     if (line == null) return null;
  67.  
  68.     int endOfName = line.indexOf (" ");
  69.     int endOfLevel = line.indexOf (" ", endOfName + 1);
  70.  
  71.     name = line.substring (0, endOfName);
  72.     buildingName = "BFSH2";
  73.     levelName = line.substring (endOfName + 1, endOfLevel);
  74.     zoneName = line.substring (endOfLevel + 1);
  75.  
  76.     return new Unite (name, buildingName, levelName, zoneName);
  77.   }
  78.  
  79. }
  80.   
  81.