From 3396457c676fd69a361a40eb57482831443f81c5 Mon Sep 17 00:00:00 2001 From: Guerrero96 Date: Mon, 15 Apr 2024 22:10:07 -0500 Subject: [PATCH] gamelogic changes --- src/main/java/uta/cse3310/GameLogic.java | 22 ++++++++++++------ src/test/java/uta/cse3310/GameLogicTest.java | 7 ++++-- target/classes/uta/cse3310/GameLogic.class | Bin 3313 -> 3650 bytes .../uta/cse3310/GameLogicTest.class | Bin 2577 -> 2759 bytes 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/uta/cse3310/GameLogic.java b/src/main/java/uta/cse3310/GameLogic.java index f084ef6..f4a3500 100644 --- a/src/main/java/uta/cse3310/GameLogic.java +++ b/src/main/java/uta/cse3310/GameLogic.java @@ -2,8 +2,10 @@ import java.io.BufferedReader; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -37,20 +39,26 @@ public char[][] getWordGrid() { return wordGrid; } - // Method to read words from a file - public void setWordsFromFile(String filePath) { + public void setWordsFromFile(String url) { List wordsList = new ArrayList<>(); - try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { - String line; - while ((line = br.readLine()) != null) { - wordsList.add(line.trim()); + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("GET"); + + try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = br.readLine()) != null) { + wordsList.add(line.trim()); + } } } catch (IOException e) { e.printStackTrace(); } + randomWords = wordsList.toArray(new String[0]); } + // Method to generate random words public void generateRandomWords(int wordCount) { randomWords = new String[wordCount]; diff --git a/src/test/java/uta/cse3310/GameLogicTest.java b/src/test/java/uta/cse3310/GameLogicTest.java index 6dffcac..f3b13bb 100644 --- a/src/test/java/uta/cse3310/GameLogicTest.java +++ b/src/test/java/uta/cse3310/GameLogicTest.java @@ -15,12 +15,15 @@ public void setUp() { } @Test - public void testSetWordsFromFile() { - gameLogic.setWordsFromFile("words.txt"); + 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() { diff --git a/target/classes/uta/cse3310/GameLogic.class b/target/classes/uta/cse3310/GameLogic.class index 58ae0c80d5e14527edc7e28cdf2a38683253ec4b..41e2e6759bffdf4052732cb12bb0f2c6687d93dd 100644 GIT binary patch delta 1840 zcmZWpYjYE26n@@hlTEkVLa}L+UZ67tZF(`#LXotTOD}+JDJ|s^tQ5#k3~BM!L_DsA z^=Kk4P*UaVn(sEZ*CeBn``OLSx<16Xa{w1!5U_7*?^m!20TtdR_yiV?XnLP^JgJT7 z-I{(R5s|Uh_*0ao)(Lp6V9|tsOMED)Z`X&l(6K%(6w!vw5F1o%L@PNCX!<;WK=D(K z|MqNB(1Lce#0~*Z)odC6f%tYRXvSuOY}jI~w|N$KqFY86d0Jdzq4Kb-?J<+>Qn4F70xnh; z>59fR)3`^)ODGg@gky;jTK3_9jQz%p&0{}^kWpf{)HrKzR*$L3g-SZf;h6EWz0s$H=Z&>&Zm9p8n;}WJ#p}kTm9H%a0+)?Z$F((I;F^r90!2wZ zsA9e$JRtF!Qpn|riw3d#n|b*p67;yBIKYLZg>ny z?hvI$h0ARml&c&|;6Q~jE^l&FQd&x>*!WHMi|2?~lDb2iiwFMZG^&GBsO_FcU9e^f z{xnuR#Hy`zi&m$xMg$}ga7?2)IE|KIT^j4B&^Col0p|o3)OzJKUc85GHtg~`)7Tjd z$d6`z^*VnU`E&=`$pXgOB#E*zm+KtRoB|T zN9R2Z*zgd8cM+R}ofoqg`^mQw$M}HU&+`eh{t{~SQ2DN*wT``b9_3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q}!B_O5-wt)}W25SV^LVnr66?4DdFX9-~f1 zTxg{K3bGulNy^Jv;B40G{lJCE5Z+>J4jRJhO3>0jwhwH82M5Tm zm5}90TjJTkJ}@!3i4I+82Z=h|Jxv`|jTBq^L-8(56Wkf218XpgC)tNRv_qIPs(1>C zN??6Our~IcuC$52u{ONTm1rnk4e2q;b*2A-B-HLQv49*u@kDuBbZzNY(B+PXnl@Y; z=~`T0I$%~~)VY8Pc54Is)x}oT`?^rSy;#43XE#_&;9S8T*Xz4r!@EX(0q^ne@UXlg gu#v~d-~CUuh>@=#zEaGmH~Oc>cOu|3!~gUD0G+A-GXMYp diff --git a/target/test-classes/uta/cse3310/GameLogicTest.class b/target/test-classes/uta/cse3310/GameLogicTest.class index 5013e46c63f275547b4318ac68b7b9c019bcef41..1caf39283b6b56cb971aba5819283d8017fc55d8 100644 GIT binary patch delta 1095 zcmZuwOH$QAEYc@KQv@8ruM^w5dtT!w2ZXAK+wx zGd{LD8b(I% zk|a%D2+bsn+3d}%u4pkeZ769Y6jM`D){u208>dp2V!G1S*3ul+Gp+5>8BNV*qMcGo zPNXGWi`kQ;JTF^&ENr<2mKH2mA!E^Sp&IQXj^L>IjFp_7B95WU{K^LX-RR}f!=Omj zW~5{`oiL<6oqQM~P9SVnat%T^PKr2%elx-iG6Uu+=XahL5y1s>gR7&}5fP&pGk~M==p`DCQf-xN}ZKitzb) z5ueV0A64SkiCUnnhpsxd+2}vDzAoFd5t_cs4+)2P%`Oh z@<{Jc@exOCACKcePBqo-vJZH;T_7;0L_@utle;2kgF;MURimNs$_Y4n4qu>@{- zQ4Sx~r8tB#1gL691qx`j!4^Uxp+HY9>e12wh9LXNg%d1o@!&KDi1Z9WiokB6nMVna zY94393}MfiBZAMI;)^E+8$KXFwjx2Y<;75N^U*qnElX_9QYmp-#_~~xVjLh-2dS#g zSt%t9=(}yDnBJDE#Xp|o|Hiw8i#Gpd^B3=p?278i#i*sg0SZw^p6hpU*6hUd;Tooh z(MlqK{f#OvY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