Raisch
extraordinary bit
Hab da mal was zusammen gebastelt:
Gruß
PHP:
<?php
class Schachbrett
{
private $schachspiel = array(
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 ),
array( 0, 0, 0, 0, 0, 0, 0, 0 )
);
public function Brett()
{
$fuellen = array();
$class = '';
$sizeOuter = count( $this->schachspiel );
echo '<table class="t" border="1">';
for( $z = 0; $z < $sizeOuter; $z++ ) {
if ( ( $z % 2 ) == 0 ) {
$fuellen[0] = 'f';
$fuellen[1] = 'd';
} else {
$fuellen[0] = 'd';
$fuellen[1] = 'f';
}
$sizeInner = count( $this->schachspiel[$z] );
echo '<tr>';
for( $s = 0; $s < $sizeInner; $s++ ) {
if( ( $s % 2 ) == 0 ) {
$class = $fuellen[0];
} else {
$class = $fuellen[1];
}
echo '<td class="'.$class.'"></td>';
}
echo '</tr>';
}
echo '</table>';
}
}
?>
<html>
<head>
<title>Schach</title>
<style>
.t {float: left;}
.t td {width: 10px; height: 10px;}
.t td.f {background-color: yellow;}
.t td.d {background-color: red;}
</style>
</head>
<body>
<?php
$schachbrett = new Schachbrett();
$schachbrett->Brett();
?>
</body>
</html>
Gruß
Zuletzt bearbeitet: