Skip to content

Commit

Permalink
Ensures that the generateGrid() method generates a grid with random a…
Browse files Browse the repository at this point in the history
…lphabets and places random words on the grid
  • Loading branch information
2onefan2 committed Apr 29, 2024
1 parent 23f0a41 commit d5970b1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/uta/cse3310/GridField.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public GridField(ArrayList<String> 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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d5970b1

Please sign in to comment.