/* Written by Jeremiah McLeod Email: xdebugx@hotmail.com webpage: http://www.angelfire.com/il/xdebugx/ */ import java.awt.*; import java.awt.image.*; import java.applet.*; import java.io.*; import java.net.*; import java.util.*; import java.awt.event.*; public class wordSearch extends Applet implements MouseMotionListener,MouseListener { Graphics grBuffer; //main graphics object int height,width; //height and width of applet Image imgBuffer; char board[] = new char [750]; boolean boardColor[] = new boolean [750]; boolean tempBoardColor[] = new boolean [750]; boolean wordFound[] = new boolean[25]; char words[] [] = new char [10] [25]; int wordDirection[] = new int [10]; int wordPlace[] = new int [10]; final int boardXOffset = 100; final int boardYOffset = 25; final int numWords=10; String strWords[] = new String [1000]; int lettersPerWord [] = new int [14]; int numWordsInFile; String backwards,forwards; int mouseDestinationX,mouseDestinationY,mouseSourceX,mouseSourceY; boolean isMouseDown=false; String whichWords="RANDOM"; static int randomNumber (int low, int high) { // returns a random number between low and high, inclusive return (int)(java.lang.Math.random() * (high - low + 1) + low); } // randomNumber public void init () { int p,t,g; int directionAddition; String fileName; boolean foundPlace; StringTokenizer st; String line; p=0; // get parameters fileName = getParameter("fileName"); whichWords = getParameter("whichWords"); whichWords=whichWords.toUpperCase(); //read file //setup mouse addMouseMotionListener (this); addMouseListener (this); try { URL url = new URL(getCodeBase(), fileName); try { BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); do {// start of DO WHILE LOOP line= in.readLine(); st=new StringTokenizer (line,"+"); while (st.hasMoreTokens()) { strWords[p]=st.nextToken(); if (strWords[p]!=null) { strWords[p]=strWords[p].toUpperCase(); p+=1; } //if } //while more tokens } while (strWords[p] != null); in.close (); } catch (IOException e) { } } catch (MalformedURLException e) { } numWordsInFile=p-1; // put file words to words array if (whichWords.equals("FIRST")) { for (p=0;p<10;p++) { for (t=0;t=0) foundPlace=true; //up if (wordDirection[p]==1 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) foundPlace=true; //down if (wordDirection[p]==2 && wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; // left if (wordDirection[p]==3 && wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; // right if (wordDirection[p]==4 && (int) (wordPlace[p]/15)-lettersPerWord[p]>=0) if (wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; // up left if (wordDirection[p]==5 && (int) (wordPlace[p]/15)-lettersPerWord[p]>=0) if (wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; //up right if (wordDirection[p]==6 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) if (wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; //down left if (wordDirection[p]==7 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) if (wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; //down right //check if char already written doesnt match if (foundPlace==true) for (g=0;g abs (mouseDestinationY-mouseSourceY)) { whichPlus = true; plus = (double) ((double) (abs (mouseDestinationY-mouseSourceY)) / (double) (abs (mouseDestinationX-mouseSourceX))); } //if XmouseDestinationX+3 || currentYmouseDestinationY+3) { if (whichPlus==true) { if (mouseDestinationX>mouseSourceX) dcurrentX=dcurrentX+1d; if (mouseDestinationXmouseSourceY) dcurrentY=dcurrentY+plus; if (mouseDestinationYmouseSourceX) dcurrentX=dcurrentX+plus; if (mouseDestinationXmouseSourceY) dcurrentY=dcurrentY+1d; if (mouseDestinationYboardXOffset+(t*30) && currentXboardYOffset+(p*30)-20) { charnum=t+(p*15); tempBoardColor[charnum]=true; }//if charnum } // while forwards=""; backwards=""; wordSelectedIndex=0; for (p=0;p<195;p++) if (tempBoardColor[p]==true) { wordSelected[wordSelectedIndex]=board[p]; wordSelectedIndex++; } // for p if (wordSelectedIndex>0) { for (p=0;p=0;p--) backwards=backwards+wordSelected[p]; for (p=0;p=0) foundPlace=true; //up if (wordDirection[p]==1 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) foundPlace=true; //down if (wordDirection[p]==2 && wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; // left if (wordDirection[p]==3 && wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; // right if (wordDirection[p]==4 && (int) (wordPlace[p]/15)-lettersPerWord[p]>=0) if (wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; // up left if (wordDirection[p]==5 && (int) (wordPlace[p]/15)-lettersPerWord[p]>=0) if (wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; //up right if (wordDirection[p]==6 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) if (wordPlace[p]%15-lettersPerWord[p]>=0) foundPlace=true; //down left if (wordDirection[p]==7 && (int) (wordPlace[p]/15)+lettersPerWord[p]<=12) if (wordPlace[p]%15+lettersPerWord[p]<=14) foundPlace=true; //down right //check if char already written doesnt match if (foundPlace==true) for (g=0;g=560 && y>=20 && x<=640 && y<=50) newSearch (); if (x>=560 && y>=70 && x<=640 && y<=100) solve (); } public void mousePressed (MouseEvent me) { } public void mouseReleased (MouseEvent me) { } public void mouseEntered (MouseEvent me) { } public void mouseExited (MouseEvent me) { } } //class wordSearch
Site hosted by Angelfire.com: Build your free website today!