Skip to content

Commit

Permalink
Fix word check and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muktar1907 committed Apr 30, 2024
1 parent 538e030 commit 260a82d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
38 changes: 19 additions & 19 deletions src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ public void addPlayers(Player newPlayer) {

// Method to update game state
public boolean updateGame(ArrayList<UserEvent> attempt) {
// if the first action is a click and the last action was a release
//if ((attempt.get(0)).action == 0 && (attempt.get(attempt.size() - 1)).action == 2) {
Player player = (attempt.get(0)).player;
String word = "";
char[][] grid = gridField.getGrid();
Iterator i = attempt.iterator();
// iterate through each event and get the character that was affected
// concatenate each letter until a word is formed
while (i.hasNext()) {
UserEvent U = (UserEvent) i.next();
int index = U.cell;
int row = index / 25;
int column = index % 25;

word = word + grid[row][column];
System.out.println(word);
}
return wordChosen(word, player);
//}

Player player = (attempt.get(0)).player;
String word = "";
char[][] grid = gridField.getGrid();
Iterator i = attempt.iterator();
// iterate through each event and get the character that was affected
// concatenate each letter until a word is formed
while (i.hasNext()) {
UserEvent U = (UserEvent) i.next();
int index = U.cell;
int row = index / 25;
int column = index % 25;

word = word + grid[row][column];
word=word.toLowerCase();
System.out.println(word);
}
return wordChosen(word, player);


}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/uta/cse3310/GridFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void testGenerateGrid() {
@Test
public void testCheckWord() {
ArrayList<String> wordList = new ArrayList<>();
wordList.add("HELLO");
wordList.add("WORLD");
wordList.add("hello");
wordList.add("world");
GridField gridField = new GridField(wordList);
assertTrue(gridField.checkWord("HELLO"));
assertFalse(gridField.checkWord("GOODBYE"));
Expand Down Expand Up @@ -59,7 +59,7 @@ public void testAddWord() {
@Test
public void testPlaceRandomWords() {
// Create a word list with some words
ArrayList<String> wordList = new ArrayList<>(Arrays.asList("HELLO", "WORLD", "JAVA", "PROGRAMMING"));
ArrayList<String> wordList = new ArrayList<>(Arrays.asList("hello", "world", "java", "programming"));

// Create a grid field
GridField gridField = new GridField(wordList);
Expand All @@ -79,7 +79,7 @@ public void testPlaceRandomWords() {

// Check if all words from the word list are placed on the grid
for (String word : wordList) {
assertTrue(gridField.checkWord(word));
assertTrue(gridField.checkWord(word.toLowerCase()));
}
}
}
4 changes: 3 additions & 1 deletion src/test/java/uta/cse3310/gameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public void testUpdate()
{
word=word+ String.valueOf(grid[1][i]);
}
gridField.getWordList().add(word);
gridField.getWordList().add(word.toLowerCase());
System.out.println("GameTest added this word to word list: "+word.toLowerCase());
//user event array
UserEvent U1= new UserEvent();
UserEvent U2= new UserEvent();
Expand Down Expand Up @@ -169,6 +170,7 @@ public void testUpdate()
{
System.out.println(wordList.get(i));
}
System.out.println(wordList.size());
assertTrue(wordList.size()==5);

}
Expand Down

0 comments on commit 260a82d

Please sign in to comment.