Last active
December 30, 2015 09:59
-
-
Save caspar/7813187 to your computer and use it in GitHub Desktop.
Adds a word to Wordsearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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