program10 - 15-100 PROGRAM 10 - FALL 2007 Due: Friday,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-100 PROGRAM 10 - FALL 2007 Due: Friday, December 7 by 11:59PM u sing electronic hand-in BACKGROUND Crossword puzzles consist of a grid of white spaces for letters and black spaces that cannot be filled in, as shown in Figure 1. In addition, a crossword puzzle contains clues for each word that is represented in the puzzle across and down. In this assignment, you will complete a Java project named Crosswords that will allow a player to fill in a crossword puzzle on the computer screen. Your puzzle window will look something like the picture in Figure 2. Figure 1: A crossword puzzle Figure 2: The Crosswords Game Window If the player enters a wrong letter, you will show a red bar (Figure 3). If all letters in the puzzle are correct so far, you will show a green bar (Figure 4). Figure 3: An incorrect letter Figure 4: All letters correct so far ASSIGNMENT Download the Crosswords.zip project from the course website and load it into Eclipse. This project contains a program with two classes: CrosswordGame - Contains a main method that asks the user for a puzzle # (e.g. 29), reads in the answers for that puzzle from a text file and the clues from another text file. You may assume that the puzzle is always 9 X 9. The answer for each box in the puzzle is stored in a two-dimensional array of characters named initialBoard and the clues are output to the screen. The main method finally creates a CrosswordBoard object to start the game. CrosswordBoard - Contains a constructor that creates a window for the user to play the crossword puzzle. The window consists of a grid layout that is 10 X 9, containing 81 JComboBox objects arranged in a 9 X 9 pattern (just like in the Sudoku game discussed in lecture) and one empty section along the bottom that shows the background of the window. In addition to the two Java files, there are four text files containing information (clues and answers) for 2 puzzles. The code in the two classes is incomplete, so you will need to complete the code to get this program to run correctly. 1. Each answer file has a name "puzzle##answers.txt" and each clue file has a name "puzzle##clues.txt", where ## is the puzzle number. In the CrosswordGame class, complete the missing code to read in the answers and clues for one of the supplied puzzles from the associated text files. For the answer file, read in each line one at a time, and store each character of that line in the corresponding cell of the initialBoard array, row by row. For the clues file, read in each line and output it to the screen (in the Console area). If either file is not found, the code will just output a warning message and exit. Although you are only given two puzzles (29 and 30), we could test your program on another puzzle. 2. In the CrosswordBoard class, initialize the letterChoices array so that it contains an array of Strings as follows: 0 "" 1 "A" 2 "B " 3 "C " 4 "D" 5 "E" 6 "F " 7 "G" 8 "H" ... ... 24 "X" 25 "Y" 26 "Z" 3. In the CrosswordBoard class, create a JComboBox for each position in the puzzle and add it to the window pane. You will do this by looking at each character in the board array to see if it is a letter or an asterisk ('*'). (a) If the character is a letter, then create a JComboBox using the letterChoices array, initially set to the empty string, and a background color of white. (b) If the character is an asterisk, then create a JComboBox using a String array with only one choice, a red dash ("-"), and a background color of black. Do not worry about putting in the crossword puzzle word numbers. 4. In the isBoardValid method of the CrosswordBoard class, complete the method so that it returns true if all of the letters that are currently selected are correct based on the answers in the board array, or false otherwise. Positions in the puzzle that are not filled in yet should not be considered. HINT: For any row and column in the comboBoxArray, you can find out the index of the letter selected by calling the getSelectedIndex method on that combo box. For example, to find out the letter selected for the top left combo box in the game (row 0, column 0), we could write index = comboBoxArray[0][0].getSelectedIndex(); If index is 2, then we know the user selected "B". If index is 0, then we know there is no letter selected for that box. Be careful. The Board array has characters, not Strings. BONUS! (2 points) Once you get the first four steps done, you may want to modify the program so that it includes the word numbers at the start of each word as shown in Figure 2. HINT: As you initialize the comboBoxArray, keep a counter with the number for the next word in the puzzle. When you get to each position in the board, check to see if that position starts a new word. It does if the cell to its left is black and the cell to its right is white, or if the box above is black and the box below is white. Be careful when you're on the boundary of the puzzle. If you find the start of a new word, replace the empty string in position 0 of the letterChoices array with the counter (as a string, not an int) and increase the counter by 1 for the next word. Don't forget to use proper programming style (indentation, variable names, comments including one with your name and section). This is still worth 1 point. TESTING & SAVING YOUR PROGRAM You should test your program after each step is completed. You should have a functioning program after each step, although it won't be correct until you've completed the first four steps successfully. Once you get this done, save your program code somewhere else on your computer before you begin to modify it for the bonus if you choose to proceed. This way, if you can't get the bonus to work, you can still submit your working program that you saved earlier in another place. PLEASE NOTE: WEAN 5419 MAY NOT BE OPEN ON FRIDAY EVENINGS SO PLEASE PLAN ACCORDINGLY. ...
View Full Document

This note was uploaded on 01/25/2010 for the course CS 15100 taught by Professor Tom during the Fall '07 term at Carnegie Mellon.

Ask a homework question - tutors are online