All pastes #984347 Raw Edit

DANtheMAN

public java v1 · immutable
·published 2008-04-14 03:37 UTC
rendered paste body
    public int findDIR(int col, int row, String word){    	int DIR = 0;    	if(puzzle[(row+1+puzzle.length)%puzzle.length][col]==word.charAt(1)){    		DIR = 1;    	}    	if(puzzle[(row-1+puzzle.length)%puzzle.length][col]==word.charAt(1)){    		DIR = 2;    	}    	if(puzzle[row][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 3;    	}    	if(puzzle[row][(col-puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 4;    	}    	if(puzzle[(row+1+puzzle.length)%puzzle.length][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 5;    	}    	if(puzzle[(row+1+puzzle.length)%puzzle.length][(col-1+puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 6;    	}    	if(puzzle[(row-1+puzzle.length)%puzzle.length][(col-1+puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 7;    	}    	if(puzzle[(row-1+puzzle.length)%puzzle.length][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){    		DIR = 8;    	}    	return DIR;    }    	int count = 0;    	int DIR = 0;    	int incrow = 0;    	int inccol = 0;    	int i = 0;    	int j = 0;    	boolean foundStart = false;    	while(i < puzzle.length && j < puzzle.length && foundStart != true){    			if(puzzle[i][j] == word.charAt(0)){    				foundStart = true;    				DIR = findDIR(i, j, word);    				switch (DIR) {    					case 0:    						break;    					case 1:    						incrow = 1;    						break;    					case 2:    						incrow = -1;    						break;    					case 3:    						inccol = 1;    						break;    					case 4:    						inccol = -1;    						break;    					case 5:    						incrow = 1;    						inccol = 1;    						break;    					case 6:    						incrow = 1;    						inccol = -1;    						break;    					case 7:    						incrow = -1;    						inccol = -1;    						break;    					case 8:    						incrow = -1;    						inccol = 1;    						break;    				}    			}    			i++;    			j++;    			if(j == puzzle.length-1){    				j = 0;    			}    	}    	i = wordLocation.getStartRow();    	j = wordLocation.getStartCol();    	while(count < word.length()){    		if(puzzle[(i+incrow+puzzle.length)%puzzle.length][(j+inccol+puzzle[i].length)%puzzle[i].length]==word.charAt(0)){    			count++;    			wordLocation.setStartRow(i);    			wordLocation.setStartCol(j);    		}    	}