The game is afoot–and the game is a crossword puzzle.
Dowload your final exercise here and import it to your workspace. It’s a project named Final-Project.
It contains a folder named data.
Inside the folder is a ZIP archive named crossword.zip.
Inside the archive is a directory named data. In this directory in the archive are three files:
- spirit.jpg: an image.
- grid.txt: a file of letters representing the filled and darkened squares of a crossword puzzle.
- clues.txt: a file of clues to the crossword.
File grid.txt
The grid file contains one line of text for each row of the grid. Each character position is either a letter or a blank space in the corresponding position of the grid. The blank spaces represent the black squares of the grid. The letters represent light spaces for which the associated letter is part of the solved puzzle. For example, a line like this:
HERES PUZZLE LINE ONE
would lead to the corresponding row of the grid to have five light squares, a dark square, six lights, one dark, four lights, one dark, and three lights.
The number of squares on each line of the puzzle is determined by the longest line in the file after trimming at the right.
File clues.txt
Each line of this file contains one crossword clue: the number as an arbitrary number of digits, the letter A or D for Across or Down; a tab character; and the text of the clue. For example:
59D\tYou're doing great
Your Assignment
Your job is to read the files grid.txt, clues.txt, and spirit.jpg from the archive data/crossword.zip, and print the crossword puzzle grid, together with the image and clues, followed by the puzzle solution (i.e., the completed grid) on a second page.
And you should do this in two ways: by using Java print services; and by creating a PDF.
Page 1
Leave a one-inch (72pt) margin on each edge of the page.
The image
The first page will have the image in spirit.jpg in the upper left corner, accounting for the margin. Scale the image so it’s 108 points wide and with a height in points proportional to the relationship of height to width in the original image.
The grid
The blank grid appears at the top of the page, 1/2 inch to the right of the image.
The grid squares are 20 points on each side. The grid is a matrix of black rectangles. Dark squares are filled in with black.
The blank grid should have numbers in 5pt sans-serif type in the upper left of squares where clues begin. A square is numbered if:
- It is not a dark square
- It is either in the first row or the first column, or there is a dark square directly above it or to its left.
The clues
Format the clues by dividing the available page width into five columns.
Fill the space beneath both the image, staring in the leftmost column, and the grid with the clues–first ACROSS clues and then DOWN clues, each in numerical order. The first ACROSS clue must be preceded by a separate line reading “ACROSS” and the first DOWN clue must be preceded by a blank line and then a line reading “DOWN”.
Break the clue text at word boundaries as needed so no line of text exceeds the available space in its column. When a column reaches the bottom margin, resume with the next column, forcing a single clue to be divided between two columns if necessary.
The top of any clue column should start as high up the page as possible without overlapping either the image or the grid. (Since the image is not as tall as the grid, columns that fit under the image will start higher than those under the grid.)
Clue text will be in a serif font, as large as possible while still fitting on the page. Starting with 10pt type, test if the clues fit the available space. If not, repeatedly try fonts one-half point smaller until one is found that allows all the clues to fit on the page, finally drawing them when they do.
The clues file is not sorted.
Page 2
Page two is the completed crossword grid, formatted as before but with the letters of the solution in each square in a sans-serif 10pt font, no numbering, and at the upper left corner of the page.
Leave a one-inch (72pt) margin on each edge of the page.
It’s also not considered cheating to crib code from existing projects (like, say, examples and exercises in an online Java course) and adapt them to your current needs. Professional developers to it all the time.
Oh, We Almost Forgot….
This course hasn’t said anything about how to read files from within a ZIP archive using Java. Part of the assignment is to research how to do that. Don’t worry–it’s really quite easy, and you don’t have to download anything new. But in a production environment, you meet many problems it takes a web search to solve. There’s no time like the present to learn how.
Good luck!!!
Don’t forget to enjoy the crossword puzzle once you’ve printed it.
And if you get stuck, here’s the solution.