Exemplo n.º 1
0
  /**
   * removeWordFromSlot()
   *
   * <p>Clears each position in the slot it's passed, but ONLY those positions containing letters
   * NOT used by any other words according to the letterUsage array. Also marks the word that used
   * to be in the slot as UNUSED.
   */
  private void removeWordFromSlot(CrosswordWord w, CrosswordSpace slot) {
    Point position = new Point(slot.getStart());

    for (int i = 0; i < slot.getLength(); i++) {

      // One fewer word is now using the letter at this position:

      letterUsage[position.x][position.y]--;

      // If no words are now using this letter, clear it:

      if (letterUsage[position.x][position.y] == 0) {
        puzzle[position.x][position.y] = BLANK;
      }

      // Advance to the next position in the slot:

      position.x += slot.getDirection().x;
      position.y += slot.getDirection().y;
    }

    // Mark the word as UNUSED -- ie., available to be placed
    // elsewhere in the puzzle:

    w.setUsed(false);
  }
Exemplo n.º 2
0
  /**
   * putWordInSlot()
   *
   * <p>Puts each letter from the word it's passed into the slot it's passed, and marks the word
   * USED. Also increments the positions in the letterUsage array corresponding to the slot to
   * indicate that one more word is now using these letters.
   */
  private void putWordInSlot(CrosswordWord w, CrosswordSpace slot) {
    Point position = new Point(slot.getStart());

    for (int i = 0; i < slot.getLength(); i++) {

      // Put each letter from the word into this slot of
      // the puzzle:

      puzzle[position.x][position.y] = w.getWord().charAt(i);

      // Record the fact that one more word is now using the
      // letter at this position:

      letterUsage[position.x][position.y]++;

      // Advance to the next position in the slot:

      position.x += slot.getDirection().x;
      position.y += slot.getDirection().y;
    }

    // Mark the word as USED:

    w.setUsed(true);
  }