generated from BudDavis/TicTacToe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
160 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package uta.cse3310; | ||
|
||
import java.io.IOException; | ||
import java.io.*; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class WordList { | ||
public static List<String> list; | ||
|
||
public static ArrayList<String> getWordList(String wordsFile) { | ||
ArrayList<String> wordList = new ArrayList<>(); | ||
|
||
try { | ||
List<String> lines = Files.readAllLines(Paths.get(wordsFile)); | ||
if (lines.isEmpty()) { | ||
System.out.println("The file is empty: " + wordsFile); | ||
return wordList; // Return empty list if the file is empty | ||
} | ||
|
||
list = new ArrayList<>(lines); | ||
shuffleWords(); | ||
wordList.addAll(list); | ||
} catch (IOException e) { | ||
System.out.println("Error reading the file: " + wordsFile); | ||
e.printStackTrace(); // Print the stack trace for debugging | ||
} | ||
|
||
return wordList; | ||
} | ||
|
||
public static void shuffleWords() { | ||
Collections.shuffle(list); | ||
} | ||
|
||
public static ArrayList<String> updatedWordList(ArrayList<String> wordBank) { | ||
int totalCharacters = 0; | ||
int index = 0; | ||
ArrayList<String> updatedList = new ArrayList<>(); | ||
|
||
while (totalCharacters < 500 && index < wordBank.size()) { | ||
String word = wordBank.get(index); | ||
if (totalCharacters + word.length() <= 500) { | ||
updatedList.add(word); | ||
totalCharacters += word.length(); | ||
} else { | ||
break; | ||
} | ||
index++; | ||
} | ||
|
||
return updatedList; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.