Skip to content

Commit

Permalink
Update Round.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Antenehden authored Aug 6, 2024
1 parent bf4a7c3 commit 262ee7d
Showing 1 changed file with 74 additions and 36 deletions.
110 changes: 74 additions & 36 deletions src/main/java/uta/cse3310/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,47 @@ public class Round {
private static final int TURN_TIME_LIMIT = 100;
private static final int VOWEL_COST = 50;
private WordList wordlist = new WordList();
//private Word words;
private ArrayList<String> wordsforgame;
HashSet<Character> lettersguessed = new HashSet<>();
HashSet<Character> correctguesses = new HashSet<>();
private HashSet<Character> lettersinword;
//ArrayList<String> wordsforgame = new ArrayList<>(wordlist.getArrList());
//HashSet<Character> lettersinword = wordlist.findletters(wordsforgame);
private transient Scanner scanner;

public Round(List<Player> players, String wordFilePath, String stakeFilePath) throws IOException {
@SuppressWarnings("static-access")
public Round(List<Player> players, String wordFilePath, String stakeFilePath, Scanner scanner) throws IOException {
this.players = players;
this.scanner = scanner;
wordlist.gatherwords();
//ArrayList<String> wordsforgame = new ArrayList<>(wordlist.getArrList());
this. wordsforgame = new ArrayList<>(wordlist.getArrList());
this.wordsforgame = new ArrayList<>(wordlist.getArrList());
System.out.println("words chosen" + wordsforgame);
this.lettersinword = wordlist.findletters(wordsforgame);
//HashSet<Character> lettersinword = wordlist.findletters(wordsforgame);
this.word = new Word(wordsforgame);
this.stake = new Stake(stakeFilePath);
this.currentPlayerIndex = 0;
this.isRoundActive = true;
}

public void startRound() {//might be here
@SuppressWarnings("static-access")
public Round(List<Player> players, WordList wordlist, String stakeFilePath, Scanner scanner) throws IOException {
this.players = players;
this.wordlist = wordlist;
this.scanner = scanner;
this.wordsforgame = new ArrayList<>(wordlist.getWords());
System.out.println("words chosen" + wordsforgame);
this.lettersinword = wordlist.findletters(wordsforgame);
this.word = new Word(wordsforgame);
this.stake = new Stake(stakeFilePath);
this.currentPlayerIndex = 0;
this.isRoundActive = true;
}

public void startRound() {
this.isRoundActive = true;
nextTurn();
}

public void nextTurn() {
if (!isRoundActive) {//might be here
if (!isRoundActive) {
System.out.println("Round is not active.");
return;
}
Expand All @@ -53,7 +65,7 @@ public void nextTurn() {
currentPlayer.getTimer().start();
System.out.println("Current player: " + currentPlayer.getName() + " has " + TURN_TIME_LIMIT + " seconds to guess.");

presentOptions(currentPlayer);
//presentOptions(currentPlayer);

new java.util.Timer().schedule(new java.util.TimerTask() {
@Override
Expand All @@ -66,7 +78,8 @@ public void run() {
}
}, TURN_TIME_LIMIT * 1000);
}

/*
@SuppressWarnings("static-access")
private void presentOptions(Player currentPlayer) {
word.getWordProgress(wordsforgame, correctguesses);
System.out.println("\ncurrent word(s) to guess:" + wordsforgame);
Expand All @@ -79,8 +92,9 @@ private void presentOptions(Player currentPlayer) {
}
private int getPlayerChoice() {
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
int choice = scanner.nextInt();
System.out.println("Player choice: " + choice);
return choice;
}
private void handleChoice(Player currentPlayer, int choice) {
Expand All @@ -99,13 +113,13 @@ private void handleChoice(Player currentPlayer, int choice) {
advanceTurn();
break;
}
}
}*/

private void buyVowel(Player currentPlayer) {
boolean validVowel = false;
public void buyVowel(Player currentPlayer, char vowel) {
/*boolean validVowel = false;
while (!validVowel) {
System.out.println("Enter a vowel to buy:");
char vowel = getUserInput();
//System.out.println("Enter a vowel to buy:");
//char vowel = getUserInput();
if ("aeiou".indexOf(vowel) != -1 && currentPlayer.getScore() >= VOWEL_COST && !currentPlayer.hasBoughtVowel(vowel)) {
validVowel = true;
currentPlayer.deductScore(VOWEL_COST);
Expand All @@ -114,47 +128,63 @@ private void buyVowel(Player currentPlayer) {
} else {
System.out.println("Invalid vowel or not enough points or already bought. Try again.");
}
}*/

//System.out.println("Attempting to buy vowel: " + vowel); // Debugging statement
if ("aeiou".indexOf(vowel) != -1 && currentPlayer.getScore() >= VOWEL_COST && !currentPlayer.hasBoughtVowel(vowel)) {
currentPlayer.deductScore(VOWEL_COST);
currentPlayer.buyVowel(vowel);
processGuess(currentPlayer, vowel);
} else {
System.out.println("Invalid vowel or not enough points or already bought. Try again.");
}
}

private void selectConsonant(Player currentPlayer) {
boolean validConsonant = false;
public void selectConsonant(Player currentPlayer, char consonant) {
/*boolean validConsonant = false;
while (!validConsonant) {
System.out.println("Enter a consonant to select:");
char consonant = getUserInput();
//System.out.println("Enter a consonant to select:");
//char consonant = getUserInput();
if ("aeiou".indexOf(consonant) == -1 && !currentPlayer.hasGuessedConsonant(consonant)) {
validConsonant = true;
currentPlayer.guessConsonant(consonant);
processGuess(currentPlayer, consonant);
} else {
System.out.println("Invalid consonant or already guessed. Try again.");
}
}*/

if ("aeiou".indexOf(consonant) == -1 && !currentPlayer.hasGuessedConsonant(consonant)) {
currentPlayer.guessConsonant(consonant);
processGuess(currentPlayer, consonant);
} else {
System.out.println("Invalid consonant or already guessed. Try again.");
}
}

private void solvePuzzle(Player currentPlayer) {
System.out.println("Enter the solution:");
Scanner scanner = new Scanner(System.in);
String solution = scanner.nextLine();
//String solutions = String.join("", solution);
//System.out.println("\nwhat you typed: " + solution);
public void solvePuzzle(Player currentPlayer, String solution) {
//System.out.println("Enter the solution:");
//String solution = scanner.next();
//System.out.println("User solution input: " + solution);
String solutions = solution.replace(" ", "");
if (word.solve(solutions) == true) {
//if(correctguesses.equals(lettersinword)){
if (word.solve(solutions)) {
System.out.println(currentPlayer.getName() + " solved the puzzle!");
currentPlayer.addScore(10);
isRoundActive = false;
System.out.println("going to next round");
} else {
System.out.println("Incorrect solution by player " + currentPlayer.getName());
advanceTurn();
}
}

private char getUserInput() {
Scanner scanner = new Scanner(System.in);
return scanner.next().charAt(0);
char input = scanner.next().charAt(0);
System.out.println("User input: " + input);
return input;
}

@SuppressWarnings("static-access")
private void processGuess(Player currentPlayer, char guessedLetter) {
int isCorrect = word.iscorrect(guessedLetter, lettersinword);
if (isCorrect == 1) {
Expand All @@ -163,7 +193,6 @@ private void processGuess(Player currentPlayer, char guessedLetter) {
currentPlayer.addScore(points);
correctguesses.add(guessedLetter);
System.out.println("Player " + currentPlayer.getName() + " awarded " + points + " points.");
//word.getWordProgress(wordsforgame, correctguesses);
System.out.println("\ncorrect guesses: " + correctguesses);
if (correctguesses.equals(lettersinword)) {
System.out.println("Word guessed correctly! Round over.");
Expand Down Expand Up @@ -205,13 +234,22 @@ public ArrayList<String> getWordsForGame() {
return wordsforgame;
}

public static void main(String[] args) throws IOException {
/*public static void main(String[] args) throws IOException {
List<String> testwords = Arrays.asList("testword");
WordList wordlist = new WordList(testwords);
List<Player> players = new ArrayList<>();
Game game = new Game(players, "src/test/resources/test_words.txt", "src/test/resources/test_stakes.txt", new Statistics());
// Simulated user input for two rounds
String simulatedUserInput = "3\n" + "testword\n" + "3\n" + "testword\n" + "3\n" + "testword\n";
ByteArrayInputStream inputStream = new ByteArrayInputStream(simulatedUserInput.getBytes());
//System.setIn(inputStream);
Scanner scanner = new Scanner(System.in);
Game game = new Game(players, "src/test/resources/test_words.txt", "src/test/resources/test_stakes.txt", new Statistics(), scanner);
game.addPlayer(new Player("Player1", PlayerType.HUMAN));
game.addPlayer(new Player("Player2", PlayerType.HUMAN));
game.startGame();
System.exit(0);
}
}*/
}

0 comments on commit 262ee7d

Please sign in to comment.