so far I have code .. IN PHP when I randomly check the checkbox and submit .. Pr
ID: 3539255 • Letter: S
Question
so far I have code .. IN PHP
when I randomly check the checkbox and submit .. Program stores the check and result hit the battleship and if it didn't hit result not hit .
it must be random. Please help me out
<?php
$start = filter_input(INPUT_POST,"start");
if (empty ($start)){
print "
Game was not created go back to the Start page
Game Start page";
}
else {
createBoard();
}
function createBoard(){
//building the arrays
$column1 = array(
'a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'
);
$column2 = array(
'b1','b2','b3','b4','b5','b6','b7','b8','b9','b10'
);
$column3 = array(
'c1','c2','c3','c4','c5','c6','c7','c8','c9','c10'
);
$column4 = array(
'd1','d2','d3','d4','d5','d6','d7','d8','d9','d10'
);
$column5 = array(
'e1','e2','e3','e4','e5','e6','e7','e8','e9','e10'
);
$column6 = array(
'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10'
);
$column7 = array(
'g1','g2','g3','g4','g5','g6','g7','g8','g9','g10'
);
$column8 = array(
'h1','h2','h3','h4','h5','h6','h7','h8','h9','h10'
);
$column9 = array(
'i1','i2','i3','i4','i5','i6','i7','i8','i9','i10'
);
$column10 = array(
'j1','j2','j3','j4','j5','j6','j7','j8','j9','j10'
);
//build the master array
$row = array(
"a"=>$column1,
"b"=>$column2,
"c"=>$column3,
"d"=>$column4,
"e"=>$column5,
"f"=>$column6,
"g"=>$column7,
"h"=>$column8,
"i"=>$column9,
"j"=>$column10
);
//had to create new variables to make rand() work with the arrays. $r is random row $c is random column.
//array_rand() is not something we have covered in class yet, found it online and it works great for this.
$r = array_rand($row);
$c = rand(1,10)-1;
$randBoard = $row[$r][$c];
print "
$randBoard
";
//creating the checkbox battleship board
print<<
action = "">
HERE;
for ($i="a";$i<="j";$i++){
print "";
foreach ($row["$i"] as $pntRow){
print "
}//end foreach
print" ";
} //end for loop
print "";
print "Fire!";
} //end function
?>
Explanation / Answer
http://www.chessish.com/bshipscode.php?PHPSESSID=spfdnoau
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.