Lab 5
Get started now

Objectives

  • Design and implement a program with a Graphical User Interface using JLabel, JTextArea and JButton objects.
  • Design and implement event handling methods to handle multiple action events
  • Make use of inner classes to implement action listeners

Video Intro

Video

Assignment

You will create a game called Barnyard Simon. Barnyard Simon is similar to the popular electronic game Simon. The game has four colored buttons (red, green, blue, and yellow). The buttons are activated in a randomly chosen sequence. The player must then mimic the sequence in order to continue playing the game. The sequence begins with just one button and increases in length by one each time the player successfully mimics the sequence.

Traditionally, the activation of each button results in the button being lit and a tone (unique for each button) being played for a short amount of time. Barnyard Simon differs in that the sounds associated with each button are barnyard animal sounds. You may use the .wav files from the previous lab assignment for this.

You can play Simon now if you think you have the willpower to focus on the assignment after you've played the game once or twice.

Details

A class design has been provided for you. You must follow this design unless you have received permission from your instructor to deviate from the given design.

Javadoc for the classes is available and must be followed. That is, your implementation must match the documentation provided as part of the design.

You may wish to begin with the following source files which contain the skeleton code.

Hints

  • Use the WavPlayer class from lab 4 (should not require modification).
  • You may find the GridLayout to work better than the FlowLayout for this game.
  • In order to activate the button, you must call paintComponent(getGraphics()); after setting background color at beginning and after setting the background color at the end of PlayButton.activate(). Warning: this is not the appropriate way to handle this, but given what we know, this is the best way I can come up with to make this happen.
  • If you are using a Mac, you may need to add the following at the beginning of the BarnyardSimon constructor:
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
        System.err.println("Could no load desired look and feel.  Using native instead.");
    }
    

Just For Fun

The basic functionality is described in the documentation and was demostrated at the beginning of lab. There are many additional things that you may wish to do to spice up your game. Here are a couple of ideas:

  • Allow for additional buttons (e.g., 6 buttons instead of 4).
  • Introduce levels so that the buttons flash for a shorter period of time when the sequence length increases. You may find these additional sound files helpful.
  • Deactivate the listeners so that the buttons are only responsive at the appropriate times.

Lab Deliverables

See your professor's instructions for details on submission guidelines and due dates.
Dr. Dennis' students: See Blackboard
See Dr. Rebenitsch for instructions
Dr. Taylor's students: See below
See Prof. Ung for instructions
If you have any questions, consult your instructor.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.

Tuesday, 10-Jan-2017 00:00:29 EST