Homework 8
Skills: Interfaces, Abstract Classes, Polymorphism, Class Design, GUIs, Event Handling
Classes: Color, Random, String, ArrayList, Components, Events
Due Week 12: Saturday by 10pm.
In this program you will write a GUI program to play the game Hangman.
Design
- We will work on the design in class.
- Questions to consider:
- What are the pieces needed to solve this problem?
Think in terms of "What if I had code to do this ..."
- What classes that you have already written can you re-use?
- Since it is a GUI, how should the screen be layed out?
- What are the action-points, or Events that need to be handled?
Think about this in terms of "When the user does this the GUI should do this."
- In what order should you work on the code pieces?
This will become your Action Plan. Your Action Plan should list the parts and what order you plan to work on them in. It should NOT specify how to write the code.
For instance, one part may be to draw the hanged man. One part of that is to draw a gallows.
Note: this is already showing an outline format.
Algorithm, Action Plan, and Implementation
- I recommend that you work on these parts in tandem - start with a
very high-level algorithm and a very high-level action plan.
- Write up a basic Algorithm for your program to follow (be sure to use an outline format).
- Write up a basic Action Plan for you to follow in order to solve the problem (be sure to use
an outline format, with mostly bullets).
- Note: Your first-draft of an Algorithm and your Action Plan is due at the end of
of the week (Friday). Please to show it to one of your TAs by the end of Recitation on Thursday or during office hours on Friday.
- Once you have enough in any area to start on the code, start writing it.
- This may be to write a method, or design a class, or write a bit of main(),
or write a small test program, ...
- Return to your Action Plan and Algorithm to further refine them as you code and to plan
your next steps.
- Work on coding the easiest things first, and focus on that specific task and not the
big-picture.
Deliverables
- HangmanAlgorithm.pdf
- HangmanActionPlan.pdf
- PlayGame.java (main program, based on the HelloWorldSwing.java example from Oracle.)
- HangmanGUI.java (Hangman GUI and code to play the game)
It should implement the StringHandler (code is below):
public class HangmanGUI extends LayoutGUI implements StringHandler
- JSecretString.java (copy SecretString from HW4)
- PhraseList.java (from HW4) - have your main() take the file name for the phrases as a command-line argument.
- SingleUseButton.java - Class for the letter-buttons (A-Z). Note: this code is provided for you; use it for the buttoms I have instructed you to - no more and no less!
- StringHandler.java - Interface to use with the SingleUseButton class. This insterface defines a class that processes a string received form clicking on a SingleUseButton. Note: this code is provided for you; use it!
- HangedMan.java - Class that graphically represents the hanged man. Note: this code is provided for you; use it!
- Are there any more classes??
Hangman Game Design During Lecture:
Note that this is a suggestion to give you an idea of the components. You may change the
way components are layed out on the screen if you wish. For instance, it is fine to put the
hanged-man on the right side or middle of the screen if you prefer.
A pop-up showing the result of the game is optional, but you msut find a way to indicate that the
game is over (and if they won or lost).
Also, selecting the internal layout is up to you, as long as you use each one
(Flow, Grid, and Border)
and try to get a reasonable placement of your components.
I have given you a LetterButton class to use - use it in the
the Grid layout for your graphical "keyboard". Figure out how to get the letters in the Grid
layout and how to label each one with the letter of the alphabet it represents.
Below is a picture of ideas to get you started on your GUI layout-design. Do include a label that shows your name and Andrew ID and make sure it is visible on the screen.