From d5970b11d87fadadd9272ebdc7817f8b2fb38490 Mon Sep 17 00:00:00 2001 From: 2onefan2 <159247397+2onefan2@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:50:28 -0500 Subject: [PATCH] Ensures that the generateGrid() method generates a grid with random alphabets and places random words on the grid --- src/main/java/uta/cse3310/GridField.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/uta/cse3310/GridField.java b/src/main/java/uta/cse3310/GridField.java index f70c663..da6aae0 100644 --- a/src/main/java/uta/cse3310/GridField.java +++ b/src/main/java/uta/cse3310/GridField.java @@ -17,6 +17,7 @@ public GridField(ArrayList wordList) { public GridField() { this.wordList = WordList.getWordList("Data/words"); this.wordList = WordList.updatedWordList(wordList); + generateGrid(5); // Initialize grid with default size (e.g., 5x5) and place random words } public char[][] getGrid() { @@ -98,7 +99,7 @@ private boolean canPlaceWord(String word, int row, int column, Direction.Directi int dr = direction.getRowIncrement(); int dc = direction.getColumnIncrement(); for (int i = 0; i < len; i++) { - if (row < 0 || row >= grid.length || column < 0 || column >= grid[0].length|| grid[row][column] != 0){ + if (row < 0 || row >= grid.length || column < 0 || column >= grid[0].length || grid[row][column] != 0) { return false; // Check if the word goes out of bounds or overlaps with existing letters } row += dr;