Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
2onefan2 committed Apr 29, 2024
1 parent 729c89c commit 2df8d6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/uta/cse3310/GridField.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public GridField(ArrayList<String> wordList) {
public GridField() {
this.wordList = WordList.getWordList("Data/words");
this.wordList = WordList.updatedWordList(wordList);
this.remainingWords = wordList.size();
generateGrid(5); // Initialize grid with default size (e.g., 5x5)
}

public char[][] getGrid() {
Expand Down Expand Up @@ -103,12 +105,12 @@ 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;
column += dc;
}
return true;
}
}
}
4 changes: 2 additions & 2 deletions src/test/java/uta/cse3310/GridFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testRevealWord() {
public void testAddWord() {
ArrayList<String> wordList = new ArrayList<>();
GridField gridField = new GridField(wordList);
gridField.addWord("HELLO", 0, 0, Direction.Directions.HORIZONTAL); // Adjusted here
gridField.addWord("HELLO", 0, 0, Direction.Directions.HORIZONTAL);
assertEquals(1, gridField.getRemainingWords());
assertTrue(gridField.checkWord("HELLO"));
}
Expand Down Expand Up @@ -82,4 +82,4 @@ public void testPlaceRandomWords() {
assertTrue(gridField.checkWord(word));
}
}
}
}

0 comments on commit 2df8d6c

Please sign in to comment.