jeudi 12 décembre 2019

Actually find the words within my word search

I have managed to read the puzzle and print of the contents of within the file. Now i come face with the task of trying to see if the puzzle actually contains my words. Currently let's say the word red is the word we are trying to find; it will tell me it is not there when it is.The word search puzzle My code down below is what I have so far.

public static void play(  String word,  char[][] puzzle) {
    //created char array and then made "word" which is a string into a char array
    char[] letter = word.toCharArray();
    int count = 0;
    //created a boolean flag for a while loop
    boolean flag = true;
    int row=0;
    int column=0;


    //while(count < letter.length) {

    //for(int row = 0; row < puzzle.length; row++){

    //for(int column = 0; column < puzzle.length; column++){

    //if (letter[count] == puzzle[row][column]) {
    while(flag == true) {
        if (checkUp(puzzle, word, row, column) == true) {
            row = row -1;
            //count ++;
            System.out.println(letter[count]);
        }
        else if (checkDown(puzzle, word, row, column) == true) {
            //if (checkDown(puzzle, word, row, column) == true) {
            row = row + 1;
            //count ++;
            System.out.println(letter[count]);
        }
        else if (checkLeft(puzzle, word, row, column) == true) {
            //if (checkLeft(puzzle, word, row, column) == true) {
            column = column + 1;
            //count ++;
            System.out.println(letter[count]);
        }
        else if (checkRight(puzzle, word, row, column) == true){
            //if (checkRight(puzzle, word, row, column) == true) {
            column = column -1;
            //count ++;
            System.out.println(letter[count]);
        }
        else {
            System.out.println("This word is not in the puzzle: " + word);
            System.out.println();
            //count = letter.length;
            break;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire