Computer Programming 2 - SY 2223 - 2T | 06 File Input and Output (Midterm) | 06 Task Performance - ARG
The program is a simple text-based guessing game in Java. It randomly selects a word from a list of words loaded from a file, and the player has to guess the word by providing letters or guessing the whole word. The program keeps track of the player's attempts and provides feedback on whether the guessed letters or words are correct or incorrect. The player has the option to play again after each round.
The program flow is as follows:
-
It loads words from a file using the loadWordsFromFile() method, which reads the words from a file and stores them in an ArrayList called wordsList.
-
It checks if the wordsList is empty, and if so, it prints an error message and exits the program.
-
It enters a loop that allows the player to play the game multiple times until they choose to stop.
-
For each round of the game, it selects a random word from wordsList using the getRandomWord() method, initializes the guessedWord with "?" for each letter in the selected word, and sets the number of attempts to 0.
-
It enters a nested loop that takes input from the player and compares it with the selected word.
-
If the input is a single letter, it checks if the letter is present in the selected word, updates the guessedWord with the correct letter(s), and provides feedback to the player.
-
If the input is a whole word, it checks if the guessed word matches the selected word, and if so, ends the round and proceeds to the next round.
-
If the input is invalid (neither a single letter nor a whole word), it provides an error message.
-
It asks the player if they want to play again after each round, and if not, exits the loop and ends the program.
Get my Code on Github: https://github.com/ashleypogi/Pogi-nang-code----06-File-input-and-Output/blob/main/TaskPerformance6