Снова затык. Вроде результат верен. Помогите, пожалуйста, советом. Спасибо
package com.javarush.task.task20.task2027;
public class test {
//---------------------------------------start of my prev solution-----------
/*
private static int startLine;
private static int startCol;
private static int endLine;
private static int endCol;
private static boolean wordFound = false;
private enum Direction {
RIGHT,
LEFT,
UP,
DOWN,
DIAG_UP_LEFT,
DIAG_UP_RIGHT,
DIAG_DOWN_LEFT,
DIAG_DOWN_RIGHT
}
private static void find(char symbol, String word, Direction direction, int line, int col, int[][] crossword){
int crossMaxCol = crossword.length;
int crossMaxLine = crossword[0].length;
switch (direction){
case RIGHT: {
if (++col > crossMaxCol) return;
break;
}
case LEFT: {
if (--col < 0) return;
break;
}
case UP: {
if (--line < 0) return;
break;
}
case DOWN: {
if (++line > crossMaxLine) return;
break;
}
case DIAG_UP_LEFT: {
if (--line < 0 || --col < 0) return;
break;
}
case DIAG_UP_RIGHT: {
if (--line < 0 || ++col > crossMaxCol) return;
break;
}
case DIAG_DOWN_LEFT: {
if (++line > crossMaxLine || --col < 0) return;
break;
}
case DIAG_DOWN_RIGHT: {
if (++line > crossMaxLine || ++col > crossMaxCol) return;
break;
}
}
if (symbol == crossword[line][col]) { // symbol found
if (word.length() == 0) { //last symbol
endLine = line;
endCol = col;
wordFound = true;
} else { // move the same direction
if (!word.equals("")) {
find(word.charAt(0), word.substring(1), direction, line, col, crossword);
}
}
}
}
public static List<Word> detectAllWords(int[][] crossword, String... words) {
List<Word> list = new ArrayList<>();
for (int arrI = 0; arrI < words.length; arrI++) {
String word = words[arrI];
startLine = -1;
endLine = -1;
startCol = -1;
endCol = -1;
wordFound = false;
for (int i = 0; i < crossword.length; i++) {
for (int j = 0; j < crossword[0].length; j++) {
if (word.charAt(0) == crossword[i][j]) {
if (word.length() == 1) {
wordFound = true;
startLine = i;
startCol = j;
endLine = i;
endCol = j;
break;
} else {
for (Direction direction : Direction.values()) {
find(word.charAt(1), word.substring(2), direction, i, j, crossword);
if (wordFound) {
startLine = i;
startCol = j;
break;
}
}
}
}
}
if (wordFound) {
break;
}
}
if (wordFound) {
Word objWord = new Word(word);
objWord.setStartPoint(startCol, startLine);
objWord.setEndPoint(endCol, endLine);
list.add(objWord);
}
}
return list;
}
*/
//---------------------------------------end of my prev solution-----------
}