示例#1
0
  /**
   * Returns the SquareTile specified by the given string
   *
   * @param s
   * @return SquareTile specified by s
   * @throws FormatException
   */
  public static SquareTile fromString(String s) throws FormatException {
    // TODO change to include tileShip data field
    int i = s.indexOf('(');
    int j = s.indexOf(')');
    if (i == -1 || j == -1)
      throw new FormatException(
          "String must include '(' and ')' to be converted to squaretile: " + s);
    Occupant o = null;
    try {
      o = Occupant.valueOf(s.substring(0, i));
    } catch (IllegalArgumentException e) {
      System.out.println(e);
    }
    SquareCoordinate c = null;
    try {
      String subS;
      subS = s.substring(i, j + 1);
      c = SquareCoordinate.fromString(subS);
    } catch (FormatException e) {
      System.out.println(e);
    }
    Object tileOwner = null;
    // try{
    //	String subS;
    //	subS = s.substring(j+1);
    //	tileShip = Ship.fromString(subS);
    // }
    // catch(FormatException e){
    //	System.out.println(e);
    // }/*

    return new SquareTile(c, o, tileOwner);
  }
示例#2
0
  /** Converts a SquareTile to a String in the form Occupant(x,y)tileShip.toString() */
  @Override
  public String toString() {
    // TODO
    String result = _occupant.toString() + _location.toString(); // + _tileOwner.toString();

    return result;
  }
示例#3
0
 /**
  * Draws this tile to screen based on visibility and enemy status; visiblity 'n' == not visible,
  * 'e' == enemy and in visibility, 'm' == mine not in visibility, 'v' == in visibility
  *
  * @param g, visiblity
  */
 public void draw(Graphics g, char visiblity) {
   Polygon squareTile = _location.toPolygon(WIDTH);
   if (visiblity == 'n') {
     g.setColor(Color.blue.darker());
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   } else if (visiblity == 'e') {
     g.setColor(this.getOccupant().getColor());
     g.fillPolygon(squareTile);
     g.setColor(Color.red);
     g.drawPolygon(squareTile);
   } else if (visiblity == 'm') {
     g.setColor(Color.blue);
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   } else {
     g.setColor(this.getOccupant().getColor());
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   }
 }