Shift-the-images game
Posted: Thu Apr 07, 2005 1:05 pm
You know those games where you move the blocks around to try and put them in the right order to get the correct image? That's what I'm trying to do.
I want to have it start out with a random configuration each time, though. Unfortunetly, I'm having trouble... Not only does the following take forever to load, it doesn't do anything. ^^;
I want to have it start out with a random configuration each time, though. Unfortunetly, I'm having trouble... Not only does the following take forever to load, it doesn't do anything. ^^;
Code: Select all
function imagelist() {
$absent = rand(0,8);
$images = array();
for ($i=0; $i<9; $i++) {
if ($i == $absent) {
$images[] = '<!-- blank -->';
} else {
$right = 0;
while (!$right) {
$val = rand(0,8);
$foo = 0;
foreach ($images as $img) {
if ($val != $img) { $foo++; }
}
if ($foo == count($images)-1) {
$right = 1;
$images[] = "<img src='eit_{$val}.jpg' alt='' />";
}
}
}
}
return $images;
}
$default = imagelist();
print("<table cellspacing='0' cellpadding='0'>
<tr><td>{$default[0]}</td><td>{$default[1]}</td><td>{$default[2]}</td></tr>
<tr><td>{$default[3]}</td><td>{$default[4]}</td><td>{$default[5]}</td></tr>
<tr><td>{$default[6]}</td><td>{$default[7]}</td><td>{$default[8]}</td></tr></table>");