CompSci 108
Spring 2010
The Software Studio

Jotto: Refactoring GUI Code for Extensibility

This project is intended to get you to practice some of the programming and design techniques discussed in class recently, specifically writing GUIs and developing inheritance hierarchies. The problem is to simulate a game of Jotto as given in this previous assignment from CompSci 100. A complete solution to the problem is given in Java as a starting point.

Understanding the Design

Start by reading the given code and making sure you understand it. The following questions should guide your analysis of the design of the current code:

Refactoring

Refactor the JottoGUI class to use basic design principles to make the code more readable and extensible. One of the problems with GUI programming is that people often throw out their basic design sense because they view the GUI as throw away code or simply so alien that it has to be written badly. Your first challenge is to understand how the GUI and the game communicate, then refactor them to make it easier for others maintaining the code later to understand the process. Additionally, refactor the GUI code to use a resource file for all of the text strings shown to the user, either as labels on buttons, prompts, or messages given as feedback. Finally, refactor the GUI code so the number of guesses a player can make is correctly reflected in the number of text fields shown in the GUI, rather than simply reported in an obscure text string.

Refactor the JottoGame class to use an inheritance hierarchy of player types such that it minimizes the amount of new code required to add another computer player. Specifically, the current code uses a variety of conditional statements to determine if the computer or the user is playing. You should create an abstract superclass, Player, that has at least two concrete subclasses, HumanPlayer and ComputerPlayer, each created by the GUI that closes the model code to adding different kinds of players. Additionally, the choice of player should be independent of the choice of the game's difficulty level (e.g., so the computer can play at an easy, medium, or hard level).

Testing

You do not need to write unit tests for the program's GUI, but you do need thoroughly test the logic of the program's game. There are two bugs in the provided code (one in the GUI and one in the game) that you will need to find and fix.

Additionally, you should attempt to bullet-proof the code from bad input from the user. Several cases are already handled, but not all cases. For each case where the user can provide bad input, you should give back specific and constructive feedback to help the user understand and fix the problem.

Improving

Provide the player with two additional options in the GUI:

A player should be able to play as many games as they want, with the number of games won tracked (including the minimum number of guesses needed to find the word). This data should be saved between runs of the program so it keeps track of the history of playing the game. If the user chooses, this data should be cleared so the score history is reset.

The current code includes only one computer player that guesses a word randomly from those that correctly conform to its history of guesses. Add at least one additional computer player that chooses its word to guess each time more intelligently than simply randomly. There are many strategies, and no clear optimal strategy or even one that consistently beats simply choosing randomly; however, that is not the point: being able to code different strategies with as little repeated code is.

For extra credit, consider the following additions:

Grading Criteria

Your grade will be determined primarily by how easy it is to add new kinds of players and how easy it is to change the GUI without having to change the game code.

Note that the amount of extra credit will be in proportion to how clearly it follows the goals of your design. Contorting your main design to add in extra functionality or adding poor code that diminishes the rest of your refactoring efforts will not be rewarded. Thus, a well-tested, perfectly working program that has fewer features (but plenty of clear paths to easy expansion) is always worth more than the leaky kitchen sink. In short, to maximize your grade, you should implement enough variety in your program to clearly demonstrate that your design supports further such extensions.