Class Cross
java.lang.Object
Cross
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
ConstructorsConstructorDescriptionCross
(int noRows, int noCols) Constructs a crossword with the given number of rows and columns. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fillCrossFromArrayList
(ArrayList<String> wordList) Fills crossword with words from the given list.void
Fill crossword (empty positions) with random charactersWord
Finds the first position where the word 'aWord' can be added AFTER the specified position '(x,y)' and in direction 'd'.Word
findLegalInAllCross
(String aWord) Finds a position in all crossword where word 'aWord' can be added.char[][]
getCross()
Returns the crossword table.List<Word>
getWords()
boolean
Checks if word 'aWord' can put in '(x,y)' position and in Vertical or Horizontal direction.void
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.
-
Constructor Details
-
Cross
public Cross(int noRows, int noCols) Constructs a crossword with the given number of rows and columns.- Parameters:
noRows
- Number of rowsnoCols
- Number of cols
-
-
Method Details
-
fillCrossFromArrayList
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
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 crooswordx
- the row that we want to add the wordy
- the column that we want to add the wordd
- 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
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
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 crosswordx
- the row that we want to add the wordy
- the column that we want to add the wordd
- 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
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
-