Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-11-08

posted Nov 8, 2017, 8:47 AM by Konstantinovich Samuel   [ updated Nov 8, 2017, 1:00 PM ]
Goal: Word search design! 

Puzzles like this are common:

U A I F L Q B I D R T V D S S  

D R H N N N K W R N E A P H F  

U J Y M B O A X U S L O G J N  

N U X D L Z E P C A P X V V I  

B O D S J O T X S C L I X R D  

C A C L Y Y S I O T A N U E B  

K H X N M P P R E S L U E T C  

E K O I K I N T F S T T B S S  

S G D C V C D I U B X Z H B I  

H O N F O Z Y P F K S W J O W  

Z E O W V L E A R H R E R L R  

Q W X A T R A O Z M S J E U N  

Z C N Y M V N T O Z U I F L L  

N T W A Y A S Q E L I D F Q X  

X H N T K S O H J W O P J Z X
	 
FIND THE FOLLOWING WORDS:
FISH        LOBSTER    PIZZA       CHOCOLATE
STEAK       SALAD      POPCORN     THOR
LOKI        ZOD        SUPERMAN



You are writing a word search generator. 

The class should be able to:
1. generate an N by M puzzle 
    (A puzzle includes a list of words, and a grid of letters with those words hidden.)
2. add a bunch of words randomly 
3. show the puzzle , or the solution.

Nice features we can add:
4. Use a plain text file as a list of words to add to the puzzle.
5. Be able to reproduce the same puzzle/solution at a later date. This is a VERY useful feature.



IN CLASS:

 Brainstorm with your neighbors on the following points:
 - How to design a data structure to hold the puzzle, words, solution, etc.
 - How the overall program would place the words and how you could view a solution.
 - What tools in java do you need but not have yet?





HW:
Here is a base set of methods to get you started! Complete them!

public class WordSearch{
    private char[][]data;

    /**Initialize the grid to the size specified 
     *fill all of the positions with '_'
     *@param row is the starting height of the WordSearch
     *@param col is the starting width of the WordSearch
     */
    public WordSearch(int rows,int cols){
    }

    /**Set all values in the WordSearch to underscores'_'*/
    private void clear(){
    }

    /**The proper formatting for a WordGrid is created in the toString.
     *@return a String with each character separated by spaces, and rows
     *separated by newlines.
     */
    public String toString(){
    }


    /**Attempts to add a given word to the specified position of the WordGrid.
     *The word is added from left to right, must fit on the WordGrid, and must
     *have a corresponding letter to match any letters that it overlaps.
     *
     *@param word is any text to be added to the word grid.
     *@param row is the vertical locaiton of where you want the word to start.
     *@param col is the horizontal location of where you want the word to start.
     *@return true when the word is added successfully. When the word doesn't fit,
     * or there are overlapping letters that do not match, then false is returned 
     * and the board is NOT modified.
     */
    public boolean addWordHorizontal(String word,int row, int col){
    }

   /**Attempts to add a given word to the specified position of the WordGrid.
     *The word is added from top to bottom, must fit on the WordGrid, and must
     *have a corresponding letter to match any letters that it overlaps.
     *
     *@param word is any text to be added to the word grid.
     *@param row is the vertical locaiton of where you want the word to start.
     *@param col is the horizontal location of where you want the word to start.
     *@return true when the word is added successfully. When the word doesn't fit,
     *or there are overlapping letters that do not match, then false is returned.
     *and the board is NOT modified.
     */
    public boolean addWordVertical(String word,int row, int col){
    }
}
Comments