Exemplo n.º 1
0
                } elseif ($neighbours == 3 || $neighbours == 2) {
                    $newboard[$x][$y] = 1;
                }
            }
        }
    }
    //store the new generation of population into session variable
    //for later use (every stage of growth)
    $_SESSION['board'] = json_encode($newboard);
    return $newboard;
}
// restore session variables into main script for production of the
// next generation via the PHP function
$size = $_SESSION['size'];
$board = json_decode($_SESSION['board'], true);
$board = liveordie($board, $size);
//Use of PHP GD Graphics library by Thomas Boutell to produce the
//simulation for the game of life
// gray background, living cells with black and dead cells with red
$myImage = imagecreate(510, 510);
$myGray = imagecolorallocate($myImage, 204, 204, 204);
$myBlack = imagecolorallocate($myImage, 0, 0, 0);
$myRed = imagecolorallocate($myImage, 204, 0, 0);
//implementation of this animation
for ($x = 0; $x < $size; $x++) {
    for ($y = 0; $y < $size; $y++) {
        if ($board[$x][$y] == 1) {
            imagesetpixel($myImage, $x, $y, $myBlack);
        } else {
            imagesetpixel($myImage, $x, $y, $myRed);
        }
Exemplo n.º 2
0
function take()
{
    $_SESSION["obj"] = (int) $_GET["obj"];
    if ($_SESSION["world"][$_SESSION["room"]]["stuff"][$_SESSION["obj"]] >= 1) {
        $_SESSION["world"][$_SESSION["room"]]["stuff"][$_SESSION["obj"]] -= 1;
        $_SESSION["stuff"][$_SESSION["obj"]] += 1;
    }
    $code = conditions();
    if ($code === 0) {
        play();
    } else {
        liveordie($code);
    }
}