Class Cross


public class Cross extends Object
Models a crossword (american). A crossword is a 2-dimensional array, whose elements are letters (of type char[][]). Inside the crossword, there are hidden words, horizontally and vertically, for the user to locate. The class Cross contains the crossword (initially empty) and allows creating a crossword with given words.
Version:
November 2022
Author:
Chrysanthi Raftopoulou
  • Constructor Summary

    Constructors
    Constructor
    Description
    Cross(int noRows, int noCols)
    Constructs a crossword with the given number of rows and columns.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Fills crossword with words from the given list.
    void
    Fill crossword (empty positions) with random characters
    Word
    findLegal(String aWord, int x, int y, char d)
    Finds the first position where the word 'aWord' can be added AFTER the specified position '(x,y)' and in direction 'd'.
    Word
    Finds a position in all crossword where word 'aWord' can be added.
    char[][]
    Returns the crossword table.
    List<Word>
     
    boolean
    isLegal(String aWord, int x, int y, char d)
    Checks if word 'aWord' can put in '(x,y)' position and in Vertical or Horizontal direction.
    void
    placeWord(String aWord, int x, int y, char d)
    Place a word in a spesific position and direction in the crossword.
    void
    Print crossword.
    void
    Print solution.
    void
    Reset crossword by filling it with initial character.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Cross

      public Cross(int noRows, int noCols)
      Constructs a crossword with the given number of rows and columns.
      Parameters:
      noRows - Number of rows
      noCols - Number of cols
  • Method Details

    • fillCrossFromArrayList

      public void fillCrossFromArrayList(ArrayList<String> wordList)
      Fills crossword with words from the given list.
      Parameters:
      wordList - a list with words
    • fillRemaing

      public void fillRemaing()
      Fill crossword (empty positions) with random characters
    • findLegal

      public Word findLegal(String aWord, int x, int y, char d)
      Finds the first position where the word 'aWord' can be added AFTER the specified position '(x,y)' and in direction 'd'.
      Parameters:
      aWord - the word that we want to add in the croosword
      x - the row that we want to add the word
      y - the column that we want to add the word
      d - the direction that we want to add the word (values 'H' for Horizontal 'V' for Vertical)
      Returns:
      a Word object describing the placement of the word or null if there is no legal placement.
    • findLegalInAllCross

      public Word findLegalInAllCross(String aWord)
      Finds a position in all crossword where word 'aWord' can be added. We select a random (x,y) position and a random direction and we use findLegal method to find if the word can be added.
      Parameters:
      aWord - the word that we want to add in the crossword
      Returns:
      a Word object describing the placement of the word or null if there is no legal placement.
    • getCross

      public char[][] getCross()
      Returns the crossword table.
      Returns:
      the crossword (char[][])
    • isLegal

      public boolean isLegal(String aWord, int x, int y, char d)
      Checks if word 'aWord' can put in '(x,y)' position and in Vertical or Horizontal direction.
      Parameters:
      aWord - the word that we want to add in the crossword
      x - the row that we want to add the word
      y - the column that we want to add the word
      d - the direction that we want to add the word (values 'H' for Horizontal 'V' for Vertical)
      Returns:
      'true' if the word can be added in else 'false'
    • placeWord

      public void placeWord(String aWord, int x, int y, char d)
      Place a word in a spesific position and direction in the crossword.
      Parameters:
      aWord - the word that we want to place in Cross
    • printCross

      public void printCross()
      Print crossword.
    • printSolution

      public void printSolution()
      Print solution.
    • resetCross

      public void resetCross()
      Reset crossword by filling it with initial character.
    • getWords

      public List<Word> getWords()