Esempio n. 1
0
  /**
   * Write a string to the specified position with the specified foreground and background colors.
   * This updates the cursor's position but not the default foreground or background colors.
   *
   * @param string the string to write
   * @param x the distance from the left to begin writing from
   * @param y the distance from the top to begin writing from
   * @param foreground the foreground color or null to use the default
   * @param background the background color or null to use the default
   * @return this for convenient chaining of method calls
   */
  public AsciiPanel write(String string, int x, int y, Color foreground, Color background) {
    if (string == null) throw new NullPointerException("string must not be null.");

    if (x + string.length() >= widthInCharacters)
      throw new IllegalArgumentException(
          "x + string.length() "
              + (x + string.length())
              + " must be less than "
              + widthInCharacters
              + ".");

    if (x < 0 || x >= widthInCharacters)
      throw new IllegalArgumentException(
          "x " + x + " must be within range [0," + widthInCharacters + ").");

    if (y < 0 || y >= heightInCharacters)
      throw new IllegalArgumentException(
          "y " + y + " must be within range [0," + heightInCharacters + ").");

    if (foreground == null) foreground = defaultForegroundColor;

    if (background == null) background = defaultBackgroundColor;

    for (int i = 0; i < string.length(); i++) {
      write(string.charAt(i), x + i, y, foreground, background);
    }
    return this;
  }
Esempio n. 2
0
  /**
   * Clear the section of the screen with the specified character and whatever the specified
   * foreground and background colors are.
   *
   * @param character the character to write
   * @param x the distance from the left to begin writing from
   * @param y the distance from the top to begin writing from
   * @param width the height of the section to clear
   * @param height the width of the section to clear
   * @param foreground the foreground color or null to use the default
   * @param background the background color or null to use the default
   * @return this for convenient chaining of method calls
   */
  public AsciiPanel clear(
      char character, int x, int y, int width, int height, Color foreground, Color background) {
    if (character < 0 || character >= glyphs.length)
      throw new IllegalArgumentException(
          "character " + character + " must be within range [0," + glyphs.length + "].");

    if (x < 0 || x >= widthInCharacters)
      throw new IllegalArgumentException(
          "x " + x + " must be within range [0," + widthInCharacters + ")");

    if (y < 0 || y >= heightInCharacters)
      throw new IllegalArgumentException(
          "y " + y + " must be within range [0," + heightInCharacters + ")");

    if (width < 1)
      throw new IllegalArgumentException("width " + width + " must be greater than 0.");

    if (height < 1)
      throw new IllegalArgumentException("height " + height + " must be greater than 0.");

    if (x + width > widthInCharacters)
      throw new IllegalArgumentException(
          "x + width " + (x + width) + " must be less than " + (widthInCharacters + 1) + ".");

    if (y + height > heightInCharacters)
      throw new IllegalArgumentException(
          "y + height " + (y + height) + " must be less than " + (heightInCharacters + 1) + ".");

    for (int xo = x; xo < x + width; xo++) {
      for (int yo = y; yo < y + height; yo++) {
        write(character, xo, yo, foreground, background);
      }
    }
    return this;
  }
Esempio n. 3
0
 public ApplicationMain() {
   super();
   terminal = new AsciiPanel();
   terminal.write("RogueLike", 1, 1);
   add(terminal);
   pack();
 }
Esempio n. 4
0
  public static void displayBorders(int x, int y, int x2, int y2) {
    terminal.write((char) 201, x, y);
    terminal.write((char) 187, x2, y);
    terminal.write((char) 188, x2, y2);
    terminal.write((char) 200, x, y2);

    for (int i = x + 1; i < x2; i++) {
      terminal.write((char) 205, i, y);
      terminal.write((char) 205, i, y2);
    }
    for (int i = y + 1; i < y2; i++) {
      terminal.write((char) 186, x, i);
      terminal.write((char) 186, x2, i);
    }
  }
Esempio n. 5
0
 @Override
 public void displayOutput(@NotNull final AsciiPanel terminal) {
   terminal.write(1, 1, "You won.");
   terminal.writeCenter(22, "-- press [enter] to restart --");
 }
Esempio n. 6
0
 public AppletMain() {
   super();
   terminal = new AsciiPanel();
   terminal.write("rl tutorial", 1, 1);
   add(terminal);
 }
Esempio n. 7
0
 public static void clearArea(int x, int y, int x2, int y2) {
   for (int i = y; i < y2; i++) {
     for (int j = x; j < x2; j++) terminal.write(" ", j, i);
   }
 }