Exemple #1
0
<head>
    <link type="text/css" rel="stylesheet" href="css/style.css">
</head>

<body>

<?php 
require_once "./src/gameOfLife.php";
$game = new GameOfLife(6);
$game->setCell(2, 1, true);
$game->setCell(2, 2, true);
$game->setCell(2, 3, true);
$game->setCell(2, 4, true);
$game->printBoard();
$game->computeNextStep();
$game->printBoard();
$game->computeNextStep();
$game->printBoard();
?>


</body>
Exemple #2
0
<?php

require_once "./src/GameOfLife.php";
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['send'])) {
        if (isset($_POST['size']) && isset($_POST['cell1']) && isset($_POST['cell2'])) {
            $sizeOfBoard = intval($_POST['size']);
            $cell1 = intval($_POST['cell1']) - 1;
            $cell2 = intval($_POST['cell2']) - 1;
            if ($sizeOfBoard > 4 && $cell1 >= 0 && $cell1 <= $sizeOfBoard && $cell2 >= 0 && $cell2 <= $sizeOfBoard) {
                $_SESSION['size'] = $sizeOfBoard;
                $game = new GameOfLife($_SESSION['size']);
                $_SESSION['game'] = $game;
                $game->setFirstAliveCells($cell1, $cell2, $_SESSION['size']);
            } else {
                echo "Invalid data. Are you sure you enter positive numbers? Try one more time.";
            }
        }
    } elseif (isset($_POST['clear'])) {
        header('refresh: 1;');
        echo 'Thank you for choosing our game. Hope you had fun!';
        session_destroy();
    } elseif (isset($_POST['step'])) {
        $_SESSION['game']->board = $_SESSION['newBoard'];
        $_SESSION['game']->computeNextStep();
    }
}
?>

<!DOCTYPE html>
Exemple #3
0
<?php

session_start();
require_once './src/GameOfLife.php';
require_once './src/GameOfLifeSetup.php';
$game = new GameOfLife($_SESSION['size']);
$click = 0;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($_POST['sizeSubmit'] == "Zatwierdz rozmiar") {
        settype($_POST['size'], "integer");
        $_SESSION['size'] = $_POST["size"];
        $click = "size";
        $gameSet = new GameOfLifeSetup($_SESSION['size']);
    }
    if ($_POST['pickSubmit'] == "Wybierz pola startowe") {
        $_SESSION['pick'] = $_POST["pick"];
        $click = "pick";
    }
    if ($_POST['reload'] == "Przeladuj") {
        $game->board = $_SESSION['NewBoard'];
        $click = "reload";
    }
}
?>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="style/style.css"
    </head>
    <body>
        <form method="POST">
            <fieldset>
Exemple #4
0
$game = new GameOfLife(12);
$game->setCell(5, 4, true);
$game->setCell(5, 5, true);
$game->setCell(5, 6, true);
$game->setCell(4, 5, true);
$game->setCell(6, 5, true);
$n = 5;
//ilość wyników jakie chcę zobaczyć
$game->printBoard();
for ($i = 0; $i < $n; $i++) {
    $game->computeNextStep();
    $game->printBoard();
}
echo "<hr>";
//schemat 2 pulsar
$game = new GameOfLife(16);
$game->setCell(2, 4, true);
$game->setCell(2, 5, true);
$game->setCell(2, 6, true);
$game->setCell(2, 10, true);
$game->setCell(2, 11, true);
$game->setCell(2, 12, true);
$game->setCell(7, 4, true);
$game->setCell(7, 5, true);
$game->setCell(7, 6, true);
$game->setCell(7, 10, true);
$game->setCell(7, 11, true);
$game->setCell(7, 12, true);
$game->setCell(9, 4, true);
$game->setCell(9, 5, true);
$game->setCell(9, 6, true);
Exemple #5
0
<html>
<head>
    <link type="text/css" rel="stylesheet" href="css/style.css">
</head>

<body>
<?php 
require_once "./src/gameoflife.php";
$game = new GameOfLife(6);
$game->setCell(2, 1, true);
$game->setCell(2, 2, true);
$game->setCell(2, 3, true);
$game->setCell(2, 4, true);
$game->printBoard();
/*
$game->computeNextStep();
$game->printBoard();

$game->computeNextStep();
$game->printBoard();

$game->computeNextStep();
$game->printBoard();

$game->computeNextStep();
$game->printBoard();

$game->computeNextStep();
$game->printBoard();

$game->computeNextStep();
Exemple #6
0
<?php

require_once 'Neighborhood.php';
require_once 'Constitution.php';
require_once 'GameOfLife.php';
$population = ['4,2', '2,3', '3,3', '3,4', '4,4'];
$matrixSize = 5;
$neighborhood = new Neighborhood($population, $matrixSize);
$constitution = new Constitution($neighborhood);
$game = new GameOfLife($constitution, $neighborhood);
var_dump($game->nextGeneration());
$population = ['2,3', '2,4', '3,2', '3,4', '4,4'];
$matrixSize = 5;
$neighborhood = new Neighborhood($population, $matrixSize);
$constitution = new Constitution($neighborhood);
$game = new GameOfLife($constitution, $neighborhood);
var_dump($game->nextGeneration());