2015-11-30

posted Nov 30, 2015, 6:35 AM by Samuel Konstantinovich   [ updated Nov 30, 2015, 8:03 AM ]
Goal: Unification of addWord commands

PartI:
You will write one add method to rule them all.

/**
 *@param word The word you want to add
 *@param row the row where you start the word
 *@param col the column where you start the word
 *@param dr the change in row between letters. Should be -1,0, or 1.
 *@param dc the change in column between letters. Should be -1,0, or 1.
 *@return true when added successfully, false if not.
 */
private boolean addWord(String word, int row, int col, int dr, int dc)
a. dr and dc determine the +1,-1, or no change(+0 but you don't normally write this) you apply to your row/col every time you loop to the next letter.
b. In your previous add methods, you added or subtracted to the starting point, different ways in each function. Using this function you can add in any direction!
c. When dr and dc are both 0, you should return false to avoid issues.



PartII
Overview of new main behavior:
java Driver [rows cols [randomSeed [answers]]]  //square brackets mean optional
1. If no command line arguments are specified, print directions to tell the user how to run the program.
2. rows and cols are the dimension of the puzzlem, if they are the only parameters passed, you cannot generate an answer to the puzzle. 
3. The randomSeed can be changed to force the same puzzle to occur again, so you can print the puzzle and the answers later.
4. If the randomSeed is provided, you can have a 4th parameter to display answers. You trigger answer mode by passing the value 1 into the answers parameter. Omitting the answers parameter, or passing any other values will just display the normal puzzle, and not show the answer.


so:

java Driver 20 30 124850
//would print the 20x30 puzzle seeded by 124850
java Driver 20 30 124850 0 
//would print the 20x30 puzzle seeded by 124850
java Driver 20 30 124850 1 
//would print the 20x30 answer key for the puzzle seeded by 124850    (all 3 of these will match)

java Driver 10 20 8230 123 
//would print the 10x20  puzzle seeded by 8230
java Driver 10 20 8230     
//would print the 10x20  puzzle seeded by 8230  (both of these will match, neither are answer keys)

Changing the seed, dimensions of the puzzle, or quantity of words, even by a single number/word, will cause a completely different puzzle to occur. 
Comments