From e99381f1baf0b24b88d9ebe60cf8fab65a25bdca Mon Sep 17 00:00:00 2001 From: Guerrero96 Date: Mon, 15 Apr 2024 23:30:16 -0500 Subject: [PATCH] game test test files --- src/main/java/uta/cse3310/GameLogic.java | 101 +++++++++++++++++- src/test/java/uta/cse3310/GameLogicTest.java | 32 +++++- target/classes/uta/cse3310/GameLogic.class | Bin 3650 -> 5233 bytes .../uta/cse3310/GameLogicTest.class | Bin 2759 -> 3386 bytes 4 files changed, 126 insertions(+), 7 deletions(-) diff --git a/src/main/java/uta/cse3310/GameLogic.java b/src/main/java/uta/cse3310/GameLogic.java index f4a3500..6d2cacc 100644 --- a/src/main/java/uta/cse3310/GameLogic.java +++ b/src/main/java/uta/cse3310/GameLogic.java @@ -20,7 +20,7 @@ public class GameLogic { public GameLogic(PlayerType players) { this.players = players; - this.wordGrid = new char[50][50]; + this.wordGrid = new char[50][50]; } public int getGameId() { @@ -39,6 +39,7 @@ public char[][] getWordGrid() { return wordGrid; } + // Method to set words from a file hosted on a URL public void setWordsFromFile(String url) { List wordsList = new ArrayList<>(); try { @@ -58,7 +59,6 @@ public void setWordsFromFile(String url) { randomWords = wordsList.toArray(new String[0]); } - // Method to generate random words public void generateRandomWords(int wordCount) { randomWords = new String[wordCount]; @@ -106,4 +106,101 @@ public double calculateFillerPercentage() { public boolean isValidWord(String word) { return word.startsWith(players.getColor()); } + + // Method to check if the specified word exists in the rows + public boolean checkRows(String word) { + for (int i = 0; i < wordGrid.length; i++) { + String row = new String(wordGrid[i]); + if (row.contains(word)) { + return true; + } + } + return false; + } + + // Method to check if the specified word exists in the columns + public boolean checkColumns(String word) { + for (int i = 0; i < wordGrid[0].length; i++) { + StringBuilder column = new StringBuilder(); + for (int j = 0; j < wordGrid.length; j++) { + column.append(wordGrid[j][i]); + } + if (column.toString().contains(word)) { + return true; + } + } + return false; + } + + // Method to check if the specified word exists in the diagonals +public boolean checkDiagonals(String word) { + // Check main diagonal (top-left to bottom-right) + StringBuilder mainDiagonal = new StringBuilder(); + for (int i = 0; i < wordGrid.length; i++) { + mainDiagonal.append(wordGrid[i][i]); + } + if (mainDiagonal.toString().contains(word)) { + return true; + } + + // Check secondary diagonal (top-right to bottom-left) + StringBuilder secondaryDiagonal = new StringBuilder(); + for (int i = 0; i < wordGrid.length; i++) { + secondaryDiagonal.append(wordGrid[i][wordGrid.length - 1 - i]); + } + if (secondaryDiagonal.toString().contains(word)) { + return true; + } + + return false; +} + + + // Calculate points based on word length + public int calculatePoints(String word) { + int length = word.length(); + switch (length) { + case 3: + return 50; + case 4: + return 60; + case 5: + return 70; + case 6: + return 80; + case 7: + return 90; + case 8: + return 100; + case 9: + return 110; + case 10: + return 120; + case 11: + return 130; + case 12: + return 140; + case 13: + return 150; + case 14: + return 160; + case 15: + return 170; + default: + return 0; // Invalid word length + } + } + + + // Method to check if the highlighted word matches any word in the word list + public int checkWord(String word) { + for (String randomWord : randomWords) { + if (word.equalsIgnoreCase(randomWord)) { + // Calculate points based on word length + int points = calculatePoints(word); + return points; + } + } + return 0; + } } diff --git a/src/test/java/uta/cse3310/GameLogicTest.java b/src/test/java/uta/cse3310/GameLogicTest.java index f3b13bb..f99ee5e 100644 --- a/src/test/java/uta/cse3310/GameLogicTest.java +++ b/src/test/java/uta/cse3310/GameLogicTest.java @@ -16,15 +16,12 @@ public void setUp() { @Test public void testSetWordsFromURL() { - PlayerType player = new PlayerType("PlayerName", "PlayerColor", PlayerType.Status.Waiting); - GameLogic gameLogic = new GameLogic(player); gameLogic.setWordsFromFile("https://raw.githubusercontent.com/utastudents/cse3310_sp24_group_8/main/src/main/java/uta/cse3310/words.txt"); String[] randomWords = gameLogic.getRandomWords(); assertNotNull(randomWords); assertTrue(randomWords.length > 0); } - @Test public void testGenerateRandomWords() { gameLogic.generateRandomWords(10); @@ -58,9 +55,34 @@ public void testCalculateFillerPercentage() { @Test public void testIsValidWord() { - PlayerType player = new PlayerType("Player1", "Red", PlayerType.Status.Waiting); - gameLogic = new GameLogic(player); assertTrue(gameLogic.isValidWord("RedWord")); assertFalse(gameLogic.isValidWord("BlueWord")); } + + @Test + public void testCheckColumns() { + gameLogic.gridGenerator(); // Generate a random word grid + assertFalse(gameLogic.checkColumns("XYZ")); // Assuming "XYZ" does not exist in any column + } + + @Test + public void testCheckDiagonals() { + gameLogic.gridGenerator(); // Generate a random word grid + assertFalse(gameLogic.checkDiagonals("XYZ")); // Assuming "XYZ" does not exist in any diagonal + } + + @Test + public void testCalculatePoints() { + assertEquals(50, gameLogic.calculatePoints("THE")); // 3-letter word + assertEquals(60, gameLogic.calculatePoints("Four")); // 4-letter word + assertEquals(170, gameLogic.calculatePoints("Acclimatization")); // 15-letter word + assertEquals(0, gameLogic.calculatePoints("A")); // Invalid word length + } + + @Test + public void testCheckWord() { + gameLogic.setWordsFromFile("https://raw.githubusercontent.com/utastudents/cse3310_sp24_group_8/main/src/main/java/uta/cse3310/words.txt"); + assertEquals(70, gameLogic.checkWord("APPLE")); // Assuming "APPLE" is in the word list + assertEquals(0, gameLogic.checkWord("XYZ")); // Assuming "XYZ" is not in the word list + } } diff --git a/target/classes/uta/cse3310/GameLogic.class b/target/classes/uta/cse3310/GameLogic.class index 41e2e6759bffdf4052732cb12bb0f2c6687d93dd..10585f6a4e8b29e452659e4f13ef037a72ad37cd 100644 GIT binary patch delta 1681 zcmZ`(T}&KR6#nkc>@IAUGW={Q?JjCeD!(PH1Z|-tg4Pl&7Hf)NG>*F?&@MBuyHFK% zv>`FEs4=ZSjeU?trQ%p=!KFf_+DdI}^{IXCgNZS|`DjzcZ)O+Rrg1js-r0Nax##=7 zbIzO({#EX~^6&g2fCupFDc{RpGdI$wMfN{o97y=kjuU?5;|l?I`O~cxd+n7k{jl(r zKu*NalWM=75ZF}y*gkbct&ORAZ*6Oz8sDQ04QqNtYpm!IkmAMx0l#x?s}UO>&=X#q z5-3^o*^`X->%A?*{jsR2#eJAYkv+`%@eNV}9(8a~)1v~x^45y1P+4wTywUbJ7F5mBxd5qT=F#GRA<`1Znw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