php-chess/html/index.php

30 lines
490 B
PHP
Raw Normal View History

2024-10-19 13:32:46 +00:00
<?php
require_once '../src/core.php';
use Game\Game;
use Game\Move;
2024-10-19 13:32:46 +00:00
session_start();
if (isset($_SESSION["game"])) {
$game = $_SESSION["game"];
} else {
$game = Game::fromStartPosition();
$_SESSION["game"] = $game;
}
2024-10-19 13:32:46 +00:00
$content = function() use ($game) {
require '../src/View/fragments/game.php';
2024-10-19 13:32:46 +00:00
};
if (isset($_GET["move"])) {
$move = Move::fromJS($_REQUEST["move"]);
$game->applyInPlace($move);
$content();
} else {
require '../src/View/base.php';
}