Created
August 13, 2012 19:51
-
-
Save paniclater/3343604 to your computer and use it in GitHub Desktop.
Fill Board function for PHP Word Search app
This file contains hidden or 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
| function fillBoard() { | |
| //fill board with list by calling addWord for each word | |
| //or return false if failed | |
| global $word; | |
| $direction = array("N", "S", "E", "W"); | |
| $itWorked = TRUE; | |
| $counter = 0; | |
| $keepGoing = TRUE; | |
| while ($keepGoing) { | |
| $dir = rand(0,3); | |
| $result = addWord($word[$counter], $direction[$dir]); | |
| if ($result == FALSE) { | |
| // print "failed to place $word[$counter]"; | |
| $keepGoing = FALSE; | |
| $itWorked = FALSE; | |
| } //end if no result check | |
| $counter++; | |
| if ($counter >= count($word)) { | |
| $keepGoing = FALSE; | |
| } // end if | |
| } // end while | |
| return $itWorked; | |
| } // end fill board |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment