php row and col problem
- jamesbond
- Novice


- Joined: Aug 22, 2011
- Posts: 19
- Status: Offline
Im making a word search pgm or modifying an existing one but im haveing trouble with one diagonal part but getting the opposite done has got stuck. Im only posting the switch that has the moves i have made already the problem im having is the case "NW" and case "SE"
Code: [ Select ]
switch ($dir){
case "E":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow][$newCol + $i];
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol + $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "W":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "west:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol - $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "S":
//col from 0 to board width
//row from 0 to board height - word length
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
//print "south:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "N":
//col from 0 to board width
//row from word length to board height
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(strlen($theWord), $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow - $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow - $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NE":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i]
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "SW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow+$i][$newCol-$i] = $wordLetter;
}else{
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NW"://<--this is for forward NW words
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"]-1);
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
$wordLetter = substr($theWord, $i, 1);
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol + $i] = $wordLetter;
}else{
$itWorked = FALSE;
}
}
break;
case "SE"://<--for backward NW word
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"]-1)
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol + $i] = $wordLetter;
}else{
$itWorked = FALSE;
}
}
break;
} // end switch
case "E":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow][$newCol + $i];
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol + $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "W":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "west:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol - $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "S":
//col from 0 to board width
//row from 0 to board height - word length
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
//print "south:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "N":
//col from 0 to board width
//row from word length to board height
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(strlen($theWord), $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow - $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow - $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NE":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i]
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "SW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow+$i][$newCol-$i] = $wordLetter;
}else{
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NW"://<--this is for forward NW words
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"]-1);
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
$wordLetter = substr($theWord, $i, 1);
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol + $i] = $wordLetter;
}else{
$itWorked = FALSE;
}
}
break;
case "SE"://<--for backward NW word
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"]-1)
$newRow = rand(0, $boardData["height"]-1);
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol + $i] = $wordLetter;
}else{
$itWorked = FALSE;
}
}
break;
} // end switch
- switch ($dir){
- case "E":
- //col from 0 to board width - word width
- //row from 0 to board height
- $newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
- $newRow = rand(0, $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //new character same row, initial column + $i
- $boardLetter = $board[$newRow][$newCol + $i];
- $wordLetter = substr($theWord, $i, 1);
- //check for legal values in current space on board
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow][$newCol + $i] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "W":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"] -1);
- $newRow = rand(0, $boardData["height"]-1);
- //print "west:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow][$newCol - $i];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow][$newCol - $i] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "S":
- //col from 0 to board width
- //row from 0 to board height - word length
- $newCol = rand(0, $boardData["width"] -1);
- $newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
- //print "south:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow + $i][$newCol];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow + $i][$newCol] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "N":
- //col from 0 to board width
- //row from word length to board height
- $newCol = rand(0, $boardData["width"] -1);
- $newRow = rand(strlen($theWord), $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow - $i][$newCol];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow - $i][$newCol] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "NE":
- //col from 0 to board width - word width
- //row from 0 to board height
- $newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
- $newRow = rand(0, $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //new character same row, initial column + $i
- $boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i
- $wordLetter = substr($theWord, $i, 1);
- //check for legal values in current space on board
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i]
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "SW":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"] -1);
- $newRow = rand(0, $boardData["height"]-1);
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow + $i][$newCol - $i];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow+$i][$newCol-$i] = $wordLetter;
- }else{
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "NW"://<--this is for forward NW words
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"]-1);
- $newRow = rand(0, $boardData["height"]-1);
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
- for($i = 0; $i < strlen($theWord); $i++){
- //check for legal move
- $boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
- $wordLetter = substr($theWord, $i, 1);
- $wordLetter = substr($theWord, $i, 1);
- if(($boardLetter == $wordLetter)||
- ($boardLetter == ".")){
- $board[$newRow - $i][$newCol + $i] = $wordLetter;
- }else{
- $itWorked = FALSE;
- }
- }
- break;
- case "SE"://<--for backward NW word
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"]-1)
- $newRow = rand(0, $boardData["height"]-1);
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
- for($i = 0; $i < strlen($theWord); $i++){
- //check for legal move
- $boardLetter = $board[$newRow - $i][$newCol + $i];//<--having trouble here getting row and col
- $wordLetter = substr($theWord, $i, 1);
- if(($boardLetter == $wordLetter)||
- ($boardLetter == ".")){
- $board[$newRow - $i][$newCol + $i] = $wordLetter;
- }else{
- $itWorked = FALSE;
- }
- }
- break;
- } // end switch
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
November 1st, 2011, 3:49 pm
- jamesbond
- Novice


- Joined: Aug 22, 2011
- Posts: 19
- Status: Offline
- jamesbond
- Novice


- Joined: Aug 22, 2011
- Posts: 19
- Status: Offline
ok im just posting the php part (sorry it took so long work has been busy) I added the diagnal lines in the switch statement but now i need to use random letters from the users list of words to fill the puzzle up instead of just random letters. fyi im useing the book php6/mysql to learn and this is one of the challenges in chaptor five. Please just point me in the right direction do not solve it. its the addfoils function im trying to change. I tried making a array from the $wordList var and then useing that to make the fill letters but it didnt work and ive working on this for two days and cant get it to work. if you look at the top i added the $_REQUEST array to see if they printing and they are but i cant figure out how to get them to print in the $foil function. do i need to split the array ? or trim ? any help would be appriciated
thank you
thank you
PHP Code: [ Select ]
<?php
foreach ($_REQUEST as $key => $value) {//added this just to see if words were printing
print <<<HERE
$value<br>
$key<br>
HERE;
}
//modded for diagnals 10/28/11 by samuel mckenna
// word Find
// by Andy Harris, 2003
// for PHP/MySQL programming for the Absolute Beginner
// Generates a word search puzzle based on a word list
// entered by user. User can also specify the size of
// the puzzle and print out an answer key if desired
//check for a word list
if (!filter_has_var(INPUT_POST, "wordList")){
print <<< HERE
<p>
This program is meant to be run from the
<a href = "battleShip.html">wordFind</a>
page.
</p>
HERE;
} else {
//get puzzle data from HTML form
$boardData = array(
"width" => filter_input(INPUT_POST, "width"),
"height" => filter_input(INPUT_POST, "height"),
"name" => filter_input(INPUT_POST, "name")
);
//try to get a word list from user input
if (parseList() == TRUE){
$legalBoard = FALSE;
//keep trying to build a board until you get a legal result
while ($legalBoard == FALSE){
clearBoard();
$legalBoard = fillBoard();
} // end while
//make the answer key
$key = $board;
$keyPuzzle = makeBoard($key);
//make the final puzzle
addFoils();
$puzzle = makeBoard($board);
//print out the result page
printPuzzle();
} // end parsed list if
} // end word list exists if
function parseList(){
//gets word list, creates array of words from it
//or return false if impossible
global $word, $wordList, $boardData;
$wordList = filter_input(INPUT_POST, "wordList");
$itWorked = TRUE;
//convert word list entirely to upper case
$wordList = strtoupper($wordList);
//split word list into array
$word = split("\n", $wordList);
//$currentWord = split(NULL, $wordList);//////////////////
foreach ($word as $currentWord){
//take out trailing newline characters
$currentWord = rtrim($currentWord);////
//stop if any words are too long to fit in puzzle
if ((strLen($currentWord) > $boardData["width"]) &&
(strLen($currentWord) > $boardData["height"])){
print "$currentWord is too long for puzzle";
$itWorked = FALSE;
} // end if
} // end foreach
return $itWorked;
} // end parseList
function clearBoard(){
//initialize board with a . in each cell
global $board, $boardData;
for ($row = 0; $row < $boardData["height"]; $row++){
for ($col = 0; $col < $boardData["width"]; $col++){
$board[$row][$col] = ".";
} // end col for loop
} // end row for loop
} // end clearBoard
function addWord($theWord, $dir){
//attempt to add a word to the board or return false if failed
global $board, $boardData;
//remove trailing characters if necessary
$theWord = rtrim($theWord);
$itWorked = TRUE;
switch ($dir){
case "E":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow][$newCol + $i];
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol + $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "W":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "west:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol - $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "S":
//col from 0 to board width
//row from 0 to board height - word length
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
//print "south:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "N":
//col from 0 to board width
//row from word length to board height
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(strlen($theWord), $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow - $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow - $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NE":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i sam
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i] sam
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "SW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);// modded sam
$newRow = rand(0, $boardData["height"]-1);//modded sam
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol - $i];//modded to + and -
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol - $i] = $wordLetter;//modded to + and -
}else{
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
$newRow = rand(0, $boardData["height"]-1);//modded sam
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol - $i];//modded to - and -
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol - $i] = $wordLetter;// modded to - and -
}else{
$itWorked = FALSE;
}
}
break;
case "SE":
//col from word width to board width
//row from 0 to board height
$newCol = rand(0, $boardData["height"]-1 - strlen($theWord));//modded
$newRow =rand(strlen($theWord), $boardData["width"]-1); //modded
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow + $i][$newCol + $i];//changed to + and +
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow + $i][$newCol + $i] = $wordLetter;// changed to + and +
}else{
$itWorked = FALSE;
}
}
break;
} // end switch
return $itWorked;
} // end addWord
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","NE","SW","NW","SE");//added diagnals sam
$itWorked = TRUE;
$counter = 0;
$keepGoing = TRUE;
while($keepGoing){
$dir = rand(0, 7);//add one for each dir
$result = addWord($word[$counter], $direction[$dir]);
if ($result == FALSE){
//print "failed to place $word[$counter]";
$keepGoing = FALSE;
$itWorked = FALSE;
} // end if
$counter++;
if ($counter >= count($word)){
$keepGoing = FALSE;
} // end if
} // end while
return $itWorked;
} // end fillBoard
function makeBoard($theBoard){
//given a board array, return an HTML table based on the array
global $boardData;
$puzzle = "";
$puzzle .= "<table>\n";
//check logic here
for ($row = 0; $row < $boardData["height"]; $row++){
$puzzle .= "<tr>\n";
for ($col = 0; $col < $boardData["width"]; $col++){
$puzzle .= " <td>{$theBoard[$row][$col]}</td>\n";
} // end col for loop
$puzzle .= "</tr>\n";
} // end row for loop
$puzzle .= "</table>\n";
return $puzzle;
} // end printBoard;
//////////////////
//$samWord = filter_input(INPUT_POST, "wordList");
$value = strtoupper($value);
$value = rtrim($value);
/////////////////
function addFoils(){
//add random dummy characters to board
global $board, $boardData;
for ($row = 0; $row < $boardData["height"]; $row++){
for ($col = 0; $col < $boardData["width"]; $col++){
if ($board[$row][$col] == "."){
$newLetter = rand(65,90);//xxxxxxxxxxxxxxxxxxxxxxxxx
$board[$row][$col] = chr($newLetter);
} // end if
} // end col for loop
} // end row for loop
} // end addFoils
function printPuzzle(){
//print out page to user with puzzle on it
global $puzzle, $word, $keyPuzzle, $boardData;
//print puzzle itself
print <<<HERE
<h1>{$boardData["name"]}</h1>
$puzzle
<h3>Word List</h3>
<ul>
HERE;
//print word list
foreach ($word as $theWord){
$theWord = rtrim($theWord);
print "<li>$theWord</li>\n";
} // end foreach
print "</ul>\n";
$puzzleName = $boardData["name"];
//print form for requesting answer key.
//save answer key as session var
$_SESSION["key"] = $keyPuzzle;
$_SESSION["puzzleName"] = $puzzleName;
print <<<HERE
<form action = "wordP_Key.php"
method = "post"
id = "keyForm">
<div>
<input type = "submit"
value = "show answer key" />
</div>
</form>
HERE;
} // end printPuzzle
?>
foreach ($_REQUEST as $key => $value) {//added this just to see if words were printing
print <<<HERE
$value<br>
$key<br>
HERE;
}
//modded for diagnals 10/28/11 by samuel mckenna
// word Find
// by Andy Harris, 2003
// for PHP/MySQL programming for the Absolute Beginner
// Generates a word search puzzle based on a word list
// entered by user. User can also specify the size of
// the puzzle and print out an answer key if desired
//check for a word list
if (!filter_has_var(INPUT_POST, "wordList")){
print <<< HERE
<p>
This program is meant to be run from the
<a href = "battleShip.html">wordFind</a>
page.
</p>
HERE;
} else {
//get puzzle data from HTML form
$boardData = array(
"width" => filter_input(INPUT_POST, "width"),
"height" => filter_input(INPUT_POST, "height"),
"name" => filter_input(INPUT_POST, "name")
);
//try to get a word list from user input
if (parseList() == TRUE){
$legalBoard = FALSE;
//keep trying to build a board until you get a legal result
while ($legalBoard == FALSE){
clearBoard();
$legalBoard = fillBoard();
} // end while
//make the answer key
$key = $board;
$keyPuzzle = makeBoard($key);
//make the final puzzle
addFoils();
$puzzle = makeBoard($board);
//print out the result page
printPuzzle();
} // end parsed list if
} // end word list exists if
function parseList(){
//gets word list, creates array of words from it
//or return false if impossible
global $word, $wordList, $boardData;
$wordList = filter_input(INPUT_POST, "wordList");
$itWorked = TRUE;
//convert word list entirely to upper case
$wordList = strtoupper($wordList);
//split word list into array
$word = split("\n", $wordList);
//$currentWord = split(NULL, $wordList);//////////////////
foreach ($word as $currentWord){
//take out trailing newline characters
$currentWord = rtrim($currentWord);////
//stop if any words are too long to fit in puzzle
if ((strLen($currentWord) > $boardData["width"]) &&
(strLen($currentWord) > $boardData["height"])){
print "$currentWord is too long for puzzle";
$itWorked = FALSE;
} // end if
} // end foreach
return $itWorked;
} // end parseList
function clearBoard(){
//initialize board with a . in each cell
global $board, $boardData;
for ($row = 0; $row < $boardData["height"]; $row++){
for ($col = 0; $col < $boardData["width"]; $col++){
$board[$row][$col] = ".";
} // end col for loop
} // end row for loop
} // end clearBoard
function addWord($theWord, $dir){
//attempt to add a word to the board or return false if failed
global $board, $boardData;
//remove trailing characters if necessary
$theWord = rtrim($theWord);
$itWorked = TRUE;
switch ($dir){
case "E":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow][$newCol + $i];
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol + $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "W":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1);
//print "west:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow][$newCol - $i];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow][$newCol - $i] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "S":
//col from 0 to board width
//row from 0 to board height - word length
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
//print "south:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "N":
//col from 0 to board width
//row from word length to board height
$newCol = rand(0, $boardData["width"] -1);
$newRow = rand(strlen($theWord), $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow - $i][$newCol];
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow - $i][$newCol] = $wordLetter;
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NE":
//col from 0 to board width - word width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
$newRow = rand(0, $boardData["height"]-1);
for ($i = 0; $i < strlen($theWord); $i++){
//new character same row, initial column + $i
$boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i sam
$wordLetter = substr($theWord, $i, 1);
//check for legal values in current space on board
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i] sam
} else {
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "SW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(strlen($theWord), $boardData["width"] -1);// modded sam
$newRow = rand(0, $boardData["height"]-1);//modded sam
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
for ($i = 0; $i < strlen($theWord); $i++){
//check for a legal move
$boardLetter = $board[$newRow + $i][$newCol - $i];//modded to + and -
$wordLetter = substr($theWord, $i, 1);
if (($boardLetter == $wordLetter) ||
($boardLetter == ".")){
$board[$newRow + $i][$newCol - $i] = $wordLetter;//modded to + and -
}else{
$itWorked = FALSE;
} // end if
} // end for loop
break;
case "NW":
//col from word width to board width
//row from 0 to board height
$newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
$newRow = rand(0, $boardData["height"]-1);//modded sam
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow - $i][$newCol - $i];//modded to - and -
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow - $i][$newCol - $i] = $wordLetter;// modded to - and -
}else{
$itWorked = FALSE;
}
}
break;
case "SE":
//col from word width to board width
//row from 0 to board height
$newCol = rand(0, $boardData["height"]-1 - strlen($theWord));//modded
$newRow =rand(strlen($theWord), $boardData["width"]-1); //modded
//print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
for($i = 0; $i < strlen($theWord); $i++){
//check for legal move
$boardLetter = $board[$newRow + $i][$newCol + $i];//changed to + and +
$wordLetter = substr($theWord, $i, 1);
if(($boardLetter == $wordLetter)||
($boardLetter == ".")){
$board[$newRow + $i][$newCol + $i] = $wordLetter;// changed to + and +
}else{
$itWorked = FALSE;
}
}
break;
} // end switch
return $itWorked;
} // end addWord
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","NE","SW","NW","SE");//added diagnals sam
$itWorked = TRUE;
$counter = 0;
$keepGoing = TRUE;
while($keepGoing){
$dir = rand(0, 7);//add one for each dir
$result = addWord($word[$counter], $direction[$dir]);
if ($result == FALSE){
//print "failed to place $word[$counter]";
$keepGoing = FALSE;
$itWorked = FALSE;
} // end if
$counter++;
if ($counter >= count($word)){
$keepGoing = FALSE;
} // end if
} // end while
return $itWorked;
} // end fillBoard
function makeBoard($theBoard){
//given a board array, return an HTML table based on the array
global $boardData;
$puzzle = "";
$puzzle .= "<table>\n";
//check logic here
for ($row = 0; $row < $boardData["height"]; $row++){
$puzzle .= "<tr>\n";
for ($col = 0; $col < $boardData["width"]; $col++){
$puzzle .= " <td>{$theBoard[$row][$col]}</td>\n";
} // end col for loop
$puzzle .= "</tr>\n";
} // end row for loop
$puzzle .= "</table>\n";
return $puzzle;
} // end printBoard;
//////////////////
//$samWord = filter_input(INPUT_POST, "wordList");
$value = strtoupper($value);
$value = rtrim($value);
/////////////////
function addFoils(){
//add random dummy characters to board
global $board, $boardData;
for ($row = 0; $row < $boardData["height"]; $row++){
for ($col = 0; $col < $boardData["width"]; $col++){
if ($board[$row][$col] == "."){
$newLetter = rand(65,90);//xxxxxxxxxxxxxxxxxxxxxxxxx
$board[$row][$col] = chr($newLetter);
} // end if
} // end col for loop
} // end row for loop
} // end addFoils
function printPuzzle(){
//print out page to user with puzzle on it
global $puzzle, $word, $keyPuzzle, $boardData;
//print puzzle itself
print <<<HERE
<h1>{$boardData["name"]}</h1>
$puzzle
<h3>Word List</h3>
<ul>
HERE;
//print word list
foreach ($word as $theWord){
$theWord = rtrim($theWord);
print "<li>$theWord</li>\n";
} // end foreach
print "</ul>\n";
$puzzleName = $boardData["name"];
//print form for requesting answer key.
//save answer key as session var
$_SESSION["key"] = $keyPuzzle;
$_SESSION["puzzleName"] = $puzzleName;
print <<<HERE
<form action = "wordP_Key.php"
method = "post"
id = "keyForm">
<div>
<input type = "submit"
value = "show answer key" />
</div>
</form>
HERE;
} // end printPuzzle
?>
- <?php
- foreach ($_REQUEST as $key => $value) {//added this just to see if words were printing
- print <<<HERE
- $value<br>
- $key<br>
- HERE;
- }
- //modded for diagnals 10/28/11 by samuel mckenna
- // word Find
- // by Andy Harris, 2003
- // for PHP/MySQL programming for the Absolute Beginner
- // Generates a word search puzzle based on a word list
- // entered by user. User can also specify the size of
- // the puzzle and print out an answer key if desired
- //check for a word list
- if (!filter_has_var(INPUT_POST, "wordList")){
- print <<< HERE
- <p>
- This program is meant to be run from the
- <a href = "battleShip.html">wordFind</a>
- page.
- </p>
- HERE;
- } else {
- //get puzzle data from HTML form
- $boardData = array(
- "width" => filter_input(INPUT_POST, "width"),
- "height" => filter_input(INPUT_POST, "height"),
- "name" => filter_input(INPUT_POST, "name")
- );
- //try to get a word list from user input
- if (parseList() == TRUE){
- $legalBoard = FALSE;
- //keep trying to build a board until you get a legal result
- while ($legalBoard == FALSE){
- clearBoard();
- $legalBoard = fillBoard();
- } // end while
- //make the answer key
- $key = $board;
- $keyPuzzle = makeBoard($key);
- //make the final puzzle
- addFoils();
- $puzzle = makeBoard($board);
- //print out the result page
- printPuzzle();
- } // end parsed list if
- } // end word list exists if
- function parseList(){
- //gets word list, creates array of words from it
- //or return false if impossible
- global $word, $wordList, $boardData;
- $wordList = filter_input(INPUT_POST, "wordList");
- $itWorked = TRUE;
- //convert word list entirely to upper case
- $wordList = strtoupper($wordList);
- //split word list into array
- $word = split("\n", $wordList);
- //$currentWord = split(NULL, $wordList);//////////////////
- foreach ($word as $currentWord){
- //take out trailing newline characters
- $currentWord = rtrim($currentWord);////
- //stop if any words are too long to fit in puzzle
- if ((strLen($currentWord) > $boardData["width"]) &&
- (strLen($currentWord) > $boardData["height"])){
- print "$currentWord is too long for puzzle";
- $itWorked = FALSE;
- } // end if
- } // end foreach
- return $itWorked;
- } // end parseList
- function clearBoard(){
- //initialize board with a . in each cell
- global $board, $boardData;
- for ($row = 0; $row < $boardData["height"]; $row++){
- for ($col = 0; $col < $boardData["width"]; $col++){
- $board[$row][$col] = ".";
- } // end col for loop
- } // end row for loop
- } // end clearBoard
- function addWord($theWord, $dir){
- //attempt to add a word to the board or return false if failed
- global $board, $boardData;
- //remove trailing characters if necessary
- $theWord = rtrim($theWord);
- $itWorked = TRUE;
- switch ($dir){
- case "E":
- //col from 0 to board width - word width
- //row from 0 to board height
- $newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));
- $newRow = rand(0, $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //new character same row, initial column + $i
- $boardLetter = $board[$newRow][$newCol + $i];
- $wordLetter = substr($theWord, $i, 1);
- //check for legal values in current space on board
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow][$newCol + $i] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "W":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"] -1);
- $newRow = rand(0, $boardData["height"]-1);
- //print "west:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow][$newCol - $i];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow][$newCol - $i] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "S":
- //col from 0 to board width
- //row from 0 to board height - word length
- $newCol = rand(0, $boardData["width"] -1);
- $newRow = rand(0, $boardData["height"]-1 - strlen($theWord));
- //print "south:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow + $i][$newCol];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow + $i][$newCol] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "N":
- //col from 0 to board width
- //row from word length to board height
- $newCol = rand(0, $boardData["width"] -1);
- $newRow = rand(strlen($theWord), $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow - $i][$newCol];
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow - $i][$newCol] = $wordLetter;
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "NE":
- //col from 0 to board width - word width
- //row from 0 to board height
- $newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
- $newRow = rand(0, $boardData["height"]-1);
- for ($i = 0; $i < strlen($theWord); $i++){
- //new character same row, initial column + $i
- $boardLetter = $board[$newRow - $i][$newCol + $i];//modded $newRow to $newRow - $i sam
- $wordLetter = substr($theWord, $i, 1);
- //check for legal values in current space on board
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow-$i][$newCol + $i] = $wordLetter;//modded [newRow] to [newRow - $i] sam
- } else {
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "SW":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(strlen($theWord), $boardData["width"] -1);// modded sam
- $newRow = rand(0, $boardData["height"]-1);//modded sam
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\n";
- for ($i = 0; $i < strlen($theWord); $i++){
- //check for a legal move
- $boardLetter = $board[$newRow + $i][$newCol - $i];//modded to + and -
- $wordLetter = substr($theWord, $i, 1);
- if (($boardLetter == $wordLetter) ||
- ($boardLetter == ".")){
- $board[$newRow + $i][$newCol - $i] = $wordLetter;//modded to + and -
- }else{
- $itWorked = FALSE;
- } // end if
- } // end for loop
- break;
- case "NW":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(0, $boardData["width"] - 1 - strlen($theWord));//modded sam
- $newRow = rand(0, $boardData["height"]-1);//modded sam
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
- for($i = 0; $i < strlen($theWord); $i++){
- //check for legal move
- $boardLetter = $board[$newRow - $i][$newCol - $i];//modded to - and -
- $wordLetter = substr($theWord, $i, 1);
- if(($boardLetter == $wordLetter)||
- ($boardLetter == ".")){
- $board[$newRow - $i][$newCol - $i] = $wordLetter;// modded to - and -
- }else{
- $itWorked = FALSE;
- }
- }
- break;
- case "SE":
- //col from word width to board width
- //row from 0 to board height
- $newCol = rand(0, $boardData["height"]-1 - strlen($theWord));//modded
- $newRow =rand(strlen($theWord), $boardData["width"]-1); //modded
- //print "northwest:\tRow: $newRow\tCol: $newCol<br>\";
- for($i = 0; $i < strlen($theWord); $i++){
- //check for legal move
- $boardLetter = $board[$newRow + $i][$newCol + $i];//changed to + and +
- $wordLetter = substr($theWord, $i, 1);
- if(($boardLetter == $wordLetter)||
- ($boardLetter == ".")){
- $board[$newRow + $i][$newCol + $i] = $wordLetter;// changed to + and +
- }else{
- $itWorked = FALSE;
- }
- }
- break;
- } // end switch
- return $itWorked;
- } // end addWord
- 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","NE","SW","NW","SE");//added diagnals sam
- $itWorked = TRUE;
- $counter = 0;
- $keepGoing = TRUE;
- while($keepGoing){
- $dir = rand(0, 7);//add one for each dir
- $result = addWord($word[$counter], $direction[$dir]);
- if ($result == FALSE){
- //print "failed to place $word[$counter]";
- $keepGoing = FALSE;
- $itWorked = FALSE;
- } // end if
- $counter++;
- if ($counter >= count($word)){
- $keepGoing = FALSE;
- } // end if
- } // end while
- return $itWorked;
- } // end fillBoard
- function makeBoard($theBoard){
- //given a board array, return an HTML table based on the array
- global $boardData;
- $puzzle = "";
- $puzzle .= "<table>\n";
- //check logic here
- for ($row = 0; $row < $boardData["height"]; $row++){
- $puzzle .= "<tr>\n";
- for ($col = 0; $col < $boardData["width"]; $col++){
- $puzzle .= " <td>{$theBoard[$row][$col]}</td>\n";
- } // end col for loop
- $puzzle .= "</tr>\n";
- } // end row for loop
- $puzzle .= "</table>\n";
- return $puzzle;
- } // end printBoard;
- //////////////////
- //$samWord = filter_input(INPUT_POST, "wordList");
- $value = strtoupper($value);
- $value = rtrim($value);
- /////////////////
- function addFoils(){
- //add random dummy characters to board
- global $board, $boardData;
- for ($row = 0; $row < $boardData["height"]; $row++){
- for ($col = 0; $col < $boardData["width"]; $col++){
- if ($board[$row][$col] == "."){
- $newLetter = rand(65,90);//xxxxxxxxxxxxxxxxxxxxxxxxx
- $board[$row][$col] = chr($newLetter);
- } // end if
- } // end col for loop
- } // end row for loop
- } // end addFoils
- function printPuzzle(){
- //print out page to user with puzzle on it
- global $puzzle, $word, $keyPuzzle, $boardData;
- //print puzzle itself
- print <<<HERE
- <h1>{$boardData["name"]}</h1>
- $puzzle
- <h3>Word List</h3>
- <ul>
- HERE;
- //print word list
- foreach ($word as $theWord){
- $theWord = rtrim($theWord);
- print "<li>$theWord</li>\n";
- } // end foreach
- print "</ul>\n";
- $puzzleName = $boardData["name"];
- //print form for requesting answer key.
- //save answer key as session var
- $_SESSION["key"] = $keyPuzzle;
- $_SESSION["puzzleName"] = $puzzleName;
- print <<<HERE
- <form action = "wordP_Key.php"
- method = "post"
- id = "keyForm">
- <div>
- <input type = "submit"
- value = "show answer key" />
- </div>
- </form>
- HERE;
- } // end printPuzzle
- ?>
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 232 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
