143 lines
6.2 KiB
PHP
143 lines
6.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/lib/tetris_store.php';
|
|
|
|
$projectName = trim((string) ($_SERVER['PROJECT_NAME'] ?? 'RetroStack'));
|
|
$topScores = [];
|
|
try {
|
|
$topScores = tetrisFetchTopScores(10);
|
|
} catch (Throwable $exception) {
|
|
error_log('Tetris index error: ' . $exception->getMessage());
|
|
}
|
|
|
|
function esc(?string $value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title><?= esc($projectName !== '' ? $projectName : 'RetroStack') ?> — Play Tetris Online</title>
|
|
<meta name="description" content="Play a clean browser Tetris game with score tracking, next and hold preview, and an online leaderboard.">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= urlencode((string) filemtime(__DIR__ . '/assets/css/custom.css')) ?>">
|
|
</head>
|
|
<body>
|
|
<main class="app-shell py-4 py-lg-5">
|
|
<div class="container">
|
|
<header class="app-topbar surface-panel mb-4 p-3 p-lg-4">
|
|
<div>
|
|
<p class="eyebrow mb-2">Arcade</p>
|
|
<h1 class="app-title mb-0"><?= esc($projectName !== '' ? $projectName : 'RetroStack') ?></h1>
|
|
</div>
|
|
<div class="topbar-actions">
|
|
<button class="btn btn-light" id="start-game-btn" type="button">Start</button>
|
|
<button class="btn btn-outline-light" id="pause-game-btn" type="button">Pause</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="row g-4 align-items-start">
|
|
<div class="col-lg-7 col-xl-8">
|
|
<section class="surface-panel p-3 p-lg-4" id="play">
|
|
<div class="board-wrap">
|
|
<div class="board-frame mx-auto">
|
|
<canvas id="tetris-board" width="300" height="600" aria-label="Tetris board"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mobile-controls mt-3" aria-label="Touch controls">
|
|
<button class="control-btn" type="button" data-control="left">←</button>
|
|
<button class="control-btn" type="button" data-control="rotate">↻</button>
|
|
<button class="control-btn" type="button" data-control="right">→</button>
|
|
<button class="control-btn" type="button" data-control="softDrop">↓</button>
|
|
<button class="control-btn wide" type="button" data-control="hardDrop">Drop</button>
|
|
<button class="control-btn wide" type="button" data-control="hold">Hold</button>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<div class="col-lg-5 col-xl-4">
|
|
<div class="stack-gap">
|
|
<section class="surface-panel p-3 p-lg-4">
|
|
<div class="stats-grid">
|
|
<article class="stat-card">
|
|
<span class="stat-label">Score</span>
|
|
<strong class="stat-value" id="score-value">0</strong>
|
|
</article>
|
|
<article class="stat-card">
|
|
<span class="stat-label">Lines</span>
|
|
<strong class="stat-value" id="lines-value">0</strong>
|
|
</article>
|
|
<article class="stat-card">
|
|
<span class="stat-label">Level</span>
|
|
<strong class="stat-value" id="level-value">1</strong>
|
|
</article>
|
|
<article class="stat-card">
|
|
<span class="stat-label">Best</span>
|
|
<strong class="stat-value" id="best-value">0</strong>
|
|
</article>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="surface-panel p-3 p-lg-4">
|
|
<div class="row g-3">
|
|
<div class="col-6">
|
|
<div class="mini-panel">
|
|
<div class="mini-label">Next</div>
|
|
<canvas id="next-piece" width="120" height="120" aria-label="Next piece"></canvas>
|
|
</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<div class="mini-panel">
|
|
<div class="mini-label">Hold</div>
|
|
<canvas id="hold-piece" width="120" height="120" aria-label="Held piece"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="surface-panel p-3 p-lg-4">
|
|
<form id="score-form" class="stack-gap-sm" autocomplete="off">
|
|
<label class="mini-label" for="player-name">Name</label>
|
|
<div class="d-flex gap-2">
|
|
<input class="form-control form-control-dark" id="player-name" name="player_name" type="text" maxlength="32" minlength="2" placeholder="Player" aria-label="Player name">
|
|
<button class="btn btn-light flex-shrink-0" id="submit-score-btn" type="submit">Save</button>
|
|
</div>
|
|
<div class="status-line" id="submission-state">Finish a run, then save.</div>
|
|
</form>
|
|
</section>
|
|
|
|
<section class="surface-panel p-3 p-lg-4" id="leaderboard">
|
|
<div class="section-head mb-3">
|
|
<h2 class="panel-title mb-0">Top 10</h2>
|
|
</div>
|
|
<div class="leaderboard-list" id="leaderboard-list">
|
|
<?php foreach ($topScores as $index => $entry): ?>
|
|
<a class="leaderboard-item" href="score.php?id=<?= (int) ($entry['id'] ?? 0) ?>">
|
|
<span class="leaderboard-rank">#<?= (int) $index + 1 ?></span>
|
|
<span class="leaderboard-player"><?= esc((string) ($entry['player_name'] ?? 'Player')) ?></span>
|
|
<span class="leaderboard-meta"><?= number_format((int) ($entry['score'] ?? 0)) ?></span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
window.APP_BOOTSTRAP = {
|
|
topScores: <?= json_encode($topScores, JSON_UNESCAPED_UNICODE) ?>,
|
|
apiUrl: 'api/scores.php'
|
|
};
|
|
</script>
|
|
<script src="assets/js/main.js?v=<?= urlencode((string) filemtime(__DIR__ . '/assets/js/main.js')) ?>" defer></script>
|
|
</body>
|
|
</html>
|