Skip to content

Instantly share code, notes, and snippets.

@caspar
Last active December 30, 2015 09:59
Show Gist options
  • Save caspar/7813187 to your computer and use it in GitHub Desktop.
Save caspar/7813187 to your computer and use it in GitHub Desktop.
Adds a word to Wordsearch.java
public boolean AddWord (int r, int c, int dx, int dy, String word){
if (dx == 0 && dy == 0)
return false; //this would mean that the word was not sprouting in any direction. Only the first letter would render.
int i = 0;
//dx: "X-Direction" -- (-1) for Left, (1) for Right, (0) for neither;
//dy: "Y-Direction" -- ditto;
try{
while (int i < word.length()){
if (board[r + (dy*i)][c + (dx*i)]
return false;
i++;
}
}catch (Exception e){
return false;
}
int i = 0;
while (int i < word.length()){
board[r + (dy*i)][c + (dx*i)] = word.charAt(i);
i++;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment