A children's learning facility called "Learn 'Em" has asked you to make a simple program that will help children learn to spell. You decide that you'll make a simple "flower" game.

The Model:

As you should always do, we will begin by creating a model for our application. What is the model for the flower game? Well, it is the flower game itself! So we should first find out how the flower game works. The actual flower game works as follows:

  • A random word is chosen from a huge dictionary (including 1000-2000 words). This word is hidden from the user but its number of letters is shown to the user as "blank spaces" on the user interface somewhere.
  • A list of letters to choose from is given. The user selects a letter from the unused letters list as a "guess". For every match with this letter in the hidden word, that letter is unhidden (shown). If that letter appeared more than once, all occurrences are unveiled at this time.
  • Each time an improper guess is made (i.e., a bad letter is chosen), a petal is added to the flower. After six improper guesses, the user loses if the word is not guessed correctly. If however, the user guesses the whole word and the flower is not fully blossoming, then the user wins.

Create a Flower class to represent the model. The flower model should have at least the following:

  • a variable to hold a random word read from your dictionary.
  • some necessary private instance variables to keep track of the letters that have been guessed, the letters that have not been guessed, the current state of the flower (e.g., number of remaining guesses) and the current state of the hidden word.

The game should also have at least the following methods:

  • a constructor that creates a new flower game with all instance variables initialized to reasonable values necessary for a new game to begin. Note that a new game should begin with a randomly chosen word from the static array as the word to be guessed.
  • a method that allows the user to guess a letter (likely takes a char as a parameter).
  • a method that returns the current state of the flower (i.e., number of remaining limbs).
  • a method that returns the letters that have been guessed and another method for the ones that have not been guessed
  • a method that returns the current state of the hidden word (i.e., a String showing the word with the correct guesses filled in and something such as dashes where the missing letters have not been guessed yet).

Create a simple main method that creates a new Flower game, guesses a few letters and shows the current state of the word and flower.

A Simple User Interface:

Now we will create a simple user interface called SimpleFlowerGUI which will allows us to play the game graphically. We will make use of the GridBagLayoutManager for this interface.

Before beginning, you will need some gif files to represent the flower's different states. Create 7 gif files (all the same dimensions) to represent your different flower states. Note, you can use something else other than a flower if you wish as long as it has 7 states. Here are some gif files that you may want to use: See image.

The interface should have at least the following:

  • a Textfield showing the word being guessed
  • a JTextField in which the user can type in a letter
  • a Guess button to make a guess for the typed in letter
  • a Label indicating the current state of the flower (i.e., showing one of the above pictures).

Here is an example of what your interface may look like: See image.

Here are some hints on how to make this window:

  • Use the GridBagLayoutManager manager
  • The image is actually just a label with no text but with the icon set to a gif file.
  • The letter field used center alignment
  • The text fields had their font set using
    • setFont(new Font("courier", Font.BOLD, 32));

Hook your user interface up to your model so that when the window opens, a new game starts with a random word. The user should be able to type a letter into the text field and then press the Guess button to make the guess. If the letter was a good one, the hidden word at the top should be updated to show the guessed letter location. If the letter guessed was wrong, the flower picture should be updated (i.e., icon changed). If the user loses the game, an appropriate message should appear somewhere on the interface (just make it part of the picture as shown above) and the Guess button and text fields should all be disabled. If the user Wins....the buttons are also all disabled, but the user should see something to indicate that he/she has won: See image.

Make sure that you follow clean GUI coding style. For example, when choosing a letter with the textfield, the user interface model should be changed so that when the guess button is pressed the letter to be used is taken from an instance variable, not directly from the text field. Hence, the event handler for the guess button should not access the textfield directly. Note that your model for your user interface may therefore consist of the Flower game as well as some other private instance variables in the user interface class.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.