This is a command line version of the game Wordle that I recreated as a project to practice programming in java. The game is still a work in progress but is functional.
The goal of this project was to create a java command line game that demonstrated my understanding of object orineted programming with java. The game contains examples of composition, encapsulation, and polymorphism which are the three major components that make java an object oriented language.
I plan to make this project into a fully functional GUI application with the use of jframe in the future. With the addition of a GUI the game will be more user friendly and easier to play rather than just being characters in a console application.
The games concept is simple, the players goal is to guess a random five letter word. Only five guesses are allowed and if the word is not guessed correctly within those five guesses the game ends and the users is asked if they would like to exit the game or play again.
The program first reads a text documnent that contains 58,000 dictionary words. These 58,000 words are then stored in an arrayList, an arrayList was chosen over a standard array because the size that the array needed to be was unknown. An arrayList does not require a size or length parameter so an arrayList best suited the programs needs.
The arrayList is then converted into a String array that is then sorted. Only words that are exactly five characters in length are kept and those words are stored in a new arrayList. The new arrayList contains around 4000 words all exactly five characters in length.
Next, math.random() is used to randomly select a positon in the arrayList and return the contents of that postion in the array. That word that is returned is then stored in a string variable called gameWord and is used as the word that the player will try and guess.
Input is then taken from the player to represent the users guess. That input is stored in a string variable called usersGuess and compared to the string gameWord. If the two strings are equal the player is informed that their guess was correct if the guess was not equal the player is informed their guess was not correct.
The game word and the users guess word are both broken down into two characters arrays. One containing the characters from the game word and the other containing the characters from the users guess word. Each postion in those arrays are then compared with the same postion in the opposite array. If both postions contain the same character that character is then printed on screen for the user to see in the form of a hint.