diff --git a/src/main/java/uta/cse3310/Game.java b/src/main/java/uta/cse3310/Game.java index 9b28f25..0820452 100644 --- a/src/main/java/uta/cse3310/Game.java +++ b/src/main/java/uta/cse3310/Game.java @@ -92,25 +92,25 @@ public void addPlayers(Player newPlayer) { // Method to update game state public boolean updateGame(ArrayList 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); + } diff --git a/src/test/java/uta/cse3310/GridFieldTest.java b/src/test/java/uta/cse3310/GridFieldTest.java index b7621c9..7dcc0c6 100644 --- a/src/test/java/uta/cse3310/GridFieldTest.java +++ b/src/test/java/uta/cse3310/GridFieldTest.java @@ -21,8 +21,8 @@ public void testGenerateGrid() { @Test public void testCheckWord() { ArrayList 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")); @@ -59,7 +59,7 @@ public void testAddWord() { @Test public void testPlaceRandomWords() { // Create a word list with some words - ArrayList wordList = new ArrayList<>(Arrays.asList("HELLO", "WORLD", "JAVA", "PROGRAMMING")); + ArrayList wordList = new ArrayList<>(Arrays.asList("hello", "world", "java", "programming")); // Create a grid field GridField gridField = new GridField(wordList); @@ -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())); } } } diff --git a/src/test/java/uta/cse3310/gameTest.java b/src/test/java/uta/cse3310/gameTest.java index f3847a4..a0d2aaa 100644 --- a/src/test/java/uta/cse3310/gameTest.java +++ b/src/test/java/uta/cse3310/gameTest.java @@ -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(); @@ -169,6 +170,7 @@ public void testUpdate() { System.out.println(wordList.get(i)); } + System.out.println(wordList.size()); assertTrue(wordList.size()==5); }