putting the buttons into the grid

Im working on this game, but its a work in progress
i need to get the fire buttons in the grid first and then I will go from there
please and thank you …
[php]<?php

if(isset($_POST[‘start_game’])

$form = “showOptions”;
}else{
$form = “showStart”;
}

if($form == “showOptions”){
?>

<?php $step = $_POST['step'];

if ($step > 2) {

$step = 0; 

} else {

$step += 1; 

}//end if

//player fireing

if ($step == 0) {

for ($i = a; $i < k; $i++){

 echo "<tr><td width='10' align ='right'>$i</td>"; 

   for ($j = 1; $j < 11; $j++){ 

     echo "<td><input type='submit' value='fire' name='$i$j'></td>"; 

   } // end for loop 

 echo "</tr>"; 

} // end for loop 

echo "<tr><td></td>"; 

for ($j = 1; $j < 11; $j++){ 

 echo "<td>$j</td>"; 

} 

echo "</tr></table>"; 



//player fireing 

} else if($step == 1) {

for ($i = a; $i < k; $i++){

 echo "<tr><td width='10' align='right'>$i</td>"; 

   for ($j = 1; $j < 11; $j++){ 

     echo "<td><input type='submit' value='fire' name='$i$j'></td>"; 

   } // end for loop 

 echo "</tr>"; 

} // end for loop 

echo "<tr><td></td>"; 

for ($j = 1; $j < 11; $j++){ 

 echo "<td>$j</td>"; 

} 

echo "</tr></table>"; 

// result of  fire 

} else {

echo "Result  "; 

for ($i = a; $i < k; $i++){ 

 echo "<tr><td width='10' align='right'>$i</td>"; 

   for ($j = 1; $j < 11; $j++){ 

     echo "<td> <input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>"; 

   } // end for loop 

 echo "</tr>"; 

} // end for loop 

echo "<tr><td></td>"; 

for ($j = 1; $j < 11; $j++){ 

 echo "<td>$j</td>"; 

} 

echo "</tr></table><br><input type='submit' name='' value='shoot'>"; 

}//end if

?>

<?php //Display the grid echo ''; for ( $row = 1; $row <= 10; $row++ ) { echo ''; for( $col = 1; $col <= 10; $col++ ) { echo ''; } echo ''; } echo '
'; echo ( isset($grid[$row][$col]) ? $grid[$row][$col] : ' ' ); echo '
'; ?>

<input type=“hidden” name=“step” value="<?php echo "$step";?>" />

The number of squares for each ship is determined by the type of the ship.
The ships cannot overlap (i.e., only one ship can occupy any given square in the grid).

In each round, the Human clicks the target square which is to be shot at.

The Computer announces whether or not the square is occupied by a ship,

and if it is a hit they mark this on their own primary grid.

When all of the squares of a ship have been hit, the ship is sunk,

and the Computer owner announces this (e.g. You sunk my battleship!!).

If all of a player’s ships have been sunk, the game is over and their opponent wins.

<?php echo "
Reset Game" ?>

<?php

error_reporting( E_ALL );

// $ships[‘Ship Name’] = size (int);
$ships = array(
‘Carrier’ => 5,
‘Battleship’ => 4,
‘Destroyer’ => 3,
‘Submarine’ => 3,
‘Patrol Boat’ => 2
);
// $grid[x-coord][y-coord]
$grid = array();

// Loop through ships for placement
foreach( $ships as $name => $size ) {

// Begin an infinite loop ( dangerous, but we can break it when
// the ship is happily placed )
while ( TRUE ) {
	
	// Determine direction of ship
	// x- horizontal, y- vertical
	$axis = ( mt_rand(0,1) == 1 ? 'x' : 'y' );
	
	// Maximum values on grid 
	$max = array( 'x' => 10, 'y' => 10 );
	
	// Subtract $size from the max value to compensate for ship size
	$max[ $axis ] -= $size;

	// Generate random placement
	$x = mt_rand( 1, $max['x'] );
	$y = mt_rand( 1, $max['y'] );

	// Check to see if the grid is empty by checking $size squares in $axis direction
	for ( $i = 0; $i < $size; $i++ ) {
		//Create a temporary holder for our coordinates
		$curr = array( 'x' => $x, 'y' => $y );
		////Add current grid position to the direction we're going
		$curr[ $axis ] += $i;
		// Check to see if the grids populated
		if (  isset( $grid[ $curr['x'] ][ $curr['y'] ] )  ) 
			//If it is, start at the beginning of the while loop and find new coordinates
			continue 2;
	}
	
// If the for loop didn't run into a collision, then we know the grid space is empty
	//and we can break out of the infinite loop!
	break;
	
}

//Now that we have a position for the ship, write it into the grid!
for ( $i = 0; $i < $size; $i++ ) {
	// Create a temporary holder for our coordinates
	$curr = array( 'x' => $x, 'y' => $y );
	// Add current grid position to the direction we're going
	$curr[ $axis ] += $i;
	// Add the first letter of the ships name to the grid ( just for example purposes )
	$grid[ $curr['x'] ][ $curr['y'] ] = substr( $name, 0, 1 );
}

}

//Display the grid
echo ‘

’;
for ( $row = 1; $row <= 10; $row++ ) {
echo '<tr>';
for( $col = 1; $col <= 10; $col++ ) {
	echo '<td width="30" align="center">';
	echo ( isset($grid[$row][$col]) ? $grid[$row][$col] : '&nbsp;' );
	echo '</td>';
}
echo '</tr>';

}
echo ‘

’;

?>

<?php } else{ ?>

When play begins, The Computer secretly arranges Her ships on Her primary grid.

Each ship occupies a number of consecutive squares on the grid,

arranged either horizontally or vertically.


The number of squares for each ship is determined by the type of the ship.

The ships cannot overlap (i.e., only one ship can occupy any given square in the grid).

In each round, the Human clicks the target square which is to be shot at.

The Computer announces whether or not the square is occupied by a ship,

and if it is a “hit” they mark this on their own primary grid.

The attacking player notes the hit or miss on their own “tracking” grid, in order to build up a picture of the opponent’s fleet.

When all of the squares of a ship have been hit, the ship is sunk,

and the ship’s owner announces this (e.g. “You sunk my battleship!”).

If all of a player’s ships have been sunk, the game is over and their opponent wins.


[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service