Prog 4: LineWord
Prof. Reed, CS 102, Fall 2011
Due at 11:59pm on the date indicated in the Course Schedule
You may work with a partner on this project.
This is a word-guessing game called LineWord. The objective of the game is to find the most valid dictionary words possible within three minutes. When the game is started up it looks like the image shown below. In this particular image the user has already selected 3 letters for the word MAR:
Only the graphical representation is used, however input can be given either using the mouse or using the keyboard. The display consists of a 5 x 5 display of letters. At the beginning of the game only the top row of letters is enabled for use. User input is given in the console by typing in words. After clicking on or typing in the first word ("mar") within the time limit the game would look like:
Play progresses, where the number of points as well as the number of rows displayed depends on the number of correct words the user finds. Take a look at the following video that shows this process in action:
http://www.youtube.com/watch?v=Hxo-BGigJu8
You need to know the following concepts in order to write this program:
Everything from the previous programs (variables, if statements, loops, input/output, Strings, Objects and Classes)
Using an array, and in particular for this program a 2D array of Square
How to use the Dictionary class (provided with this program), which includes downloading a dictionary file. How to use the MouseAndKeys.java program that handles mouse input and keyboard input, connecting to methods in the Board.java class.
Steps:
Consider writing the program a step at a time, using the following order. The number of points for each item are shown, out of the 55 possible points for program execution.
(0 points) Download all the files from Prog4Archive.zip, or see them individually: Canvas.java, Square.java, Dictionary.java, dictionary.txt, MouseAndKeys.java and Board.java. [These are all attachments shown at the bottom of this page.] Of these 4 files Board.java is the only one you will need to change and turn in.
Create a project in Eclipse, then drag each of the .java files into the src folder for that project. Drag dictionary.txt into the root directory for the project, at the same level as thesrc and bin directories. Run it and familiarize yourself with the sample code provided, which implements a timer, dictionary lookup, updating a String on the screen and a start for the screen layout, including finding random characters to place inside Squares on the screen. You should use the 2D array that is already there, but will need to make it the correct size.
In the main loop write code to test for each of the following, in the following order:
(0 points, however 5 point deduction if not present) Make sure the 3 minutes are not yet up for the game.
(0 points, however 5 point deduction if not present) Check the word length, making sure it is 3 or greater.
(10 points) Have your program handle both keyboard input as well as mouse input. To do this have both the mouse handling code and the keys handling code call the same methods.
(10 points) Ensure the word can be formed using only the letters on the highlighted line. You will probably want to have a variable keep track of how many rows are highlighted. Use that variable to go through the array of Squares, creating a String with all the labels appended from all the Squares that are highlighted. When you finish this you should have a single String with all the letters from the highlighted row(s). Now compare the user input word against this String. (Note that this is very similar to what we did in program #2.)
(0 points, however 10 point deduction if not present) Ensure the word is a valid dictionary word.
(5 points) Ensure the word has not been previously used. (Note that this is very similar to what we did in program #2.)
(5 points) Validate that if the word length is 3 then the input was given within 5 seconds.
(10 points) While going through the above tests keep track if any of the tests fails.
If the word passes all the tests, then increment the number of rows displayed. As mentioned previously you should have a variable indicating how many rows are valid to use. Use this variable to go through your array of Squares, setting the color for each row according to whether or not it is enabled.
(5 points) For any tests that failed, update the graphical message on the board.
(5 points) You should also update the score. Points are awarded according the the word length as follows:
Length Points
3-4 1
5 2
6 4
>6 6
(5 points) .Implement the functionality for 'r' to reset the board. This should leave the score the same, but should randomize all the board letters and set it back so only the top row is enabled for use.
Turn in your program into Blackboard, into the Program 4 assignment. You can turn it in multiple times, but only the most recent version turned in will be graded.
(10 points) Extra Credit: for a user input of 'c' (for "cheat") have your program display on the console all the possible valid dictionary words that can be formed at the current point in the game, excluding the ones you have already found.