211 lines
8.3 KiB
PHP
211 lines
8.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once 'db/config.php';
|
|
|
|
// Fetch top high scores
|
|
$highScores = [];
|
|
try {
|
|
$stmt = db()->query("SELECT player_name, score FROM high_scores ORDER BY score DESC LIMIT 5");
|
|
$highScores = $stmt->fetchAll();
|
|
} catch (Exception $e) {
|
|
// Fail silently if table doesn't exist yet
|
|
}
|
|
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Classic Tetris Game - Single and Multiplayer HTML5 game.';
|
|
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Classic Tetris</title>
|
|
|
|
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
|
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
<?php if ($projectImageUrl): ?>
|
|
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
<?php endif; ?>
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
#debuff-notifications {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
z-index: 1050;
|
|
}
|
|
.debuff-toast {
|
|
background: rgba(220, 53, 69, 0.9);
|
|
color: white;
|
|
padding: 10px 20px;
|
|
border-radius: 5px;
|
|
margin-bottom: 10px;
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
animation: slideIn 0.3s ease-out;
|
|
}
|
|
@keyframes slideIn {
|
|
from { transform: translateX(100%); }
|
|
to { transform: translateX(0); }
|
|
}
|
|
.online-badge {
|
|
width: 8px;
|
|
height: 8px;
|
|
background: #28a745;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
margin-right: 5px;
|
|
}
|
|
.invite-toast {
|
|
position: fixed;
|
|
bottom: 20px;
|
|
left: 20px;
|
|
z-index: 1060;
|
|
background: #1e293b;
|
|
border-left: 5px solid #3b82f6;
|
|
padding: 15px;
|
|
box-shadow: 0 5px 15px rgba(0,0,0,0.5);
|
|
border-radius: 5px;
|
|
min-width: 250px;
|
|
color: #f8fafc;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="debuff-notifications"></div>
|
|
<div id="invite-container"></div>
|
|
|
|
<nav class="navbar navbar-expand-lg py-3">
|
|
<div class="container">
|
|
<a class="navbar-brand fw-bold" href="/">TETRIS</a>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav me-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="about.php">About Author</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="d-flex align-items-center">
|
|
<span class="text-muted small me-3">Level: <span id="level-val">1</span></span>
|
|
<span class="text-muted small">Score: <span id="score-val">0</span></span>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container py-5">
|
|
<div id="multiplayer-status-bar" class="alert d-none mb-4 text-center">
|
|
<span id="multiplayer-status-text">Waiting for opponent...</span>
|
|
<strong id="display-room-code" class="ms-2"></strong>
|
|
</div>
|
|
|
|
<div class="row g-4 justify-content-center">
|
|
<div id="player-column" class="col-lg-auto text-center">
|
|
<h6 id="player-label" class="fw-bold mb-2 text-uppercase">You</h6>
|
|
<div class="game-container p-2">
|
|
<canvas id="tetris" width="360" height="600"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="opponent-column" class="col-lg-auto text-center d-none">
|
|
<h6 id="opponent-label" class="fw-bold mb-2 text-danger text-uppercase">Opponent</h6>
|
|
<div class="game-container p-2">
|
|
<canvas id="opponent-tetris" width="240" height="400" style="width: 180px; height: 300px;"></canvas>
|
|
</div>
|
|
<div class="mt-2 small text-muted">Opponent Score: <span id="opponent-score-val">0</span></div>
|
|
</div>
|
|
|
|
<div class="col-lg-4" id="sidebar">
|
|
<!-- Online Players Card -->
|
|
<div class="card border-0 shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title fw-bold mb-3 d-flex align-items-center">
|
|
Online Players
|
|
<span class="ms-2 badge bg-dark text-muted small fw-normal" id="online-count">0</span>
|
|
</h5>
|
|
<div id="online-players-list" class="list-group list-group-flush" style="max-height: 200px; overflow-y: auto;">
|
|
<p class="text-muted small p-2">No other players online</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Multiplayer Controls -->
|
|
<div class="card border-0 shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title fw-bold mb-3">Multiplayer</h5>
|
|
<div id="mp-setup">
|
|
<div class="mb-3">
|
|
<input type="text" id="player-name" class="form-control" placeholder="Your Name" value="Player">
|
|
</div>
|
|
<div class="d-grid gap-2">
|
|
<button id="create-room-btn" class="btn btn-dark">Create Private Room</button>
|
|
<div class="input-group">
|
|
<input type="text" id="join-room-code" class="form-control" placeholder="Room Code">
|
|
<button id="join-room-btn" class="btn btn-outline-info">Join</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="mp-active" class="d-none">
|
|
<p class="small mb-2">Room: <strong id="active-room-code" class="text-info"></strong></p>
|
|
<button id="leave-room-btn" class="btn btn-sm btn-outline-danger w-100">Leave Multiplayer</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title fw-bold mb-3">Controls</h5>
|
|
<ul class="list-unstyled small text-muted mb-0">
|
|
<li class="mb-2"><strong>← / →</strong> : Move Left/Right</li>
|
|
<li class="mb-2"><strong>↑ / W</strong> : Rotate</li>
|
|
<li class="mb-2"><strong>↓ / S</strong> : Soft Drop</li>
|
|
<li class="mb-2"><strong>Space</strong> : Hard Drop</li>
|
|
<li><strong>P</strong> : Pause Game</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title fw-bold mb-3">Next Piece</h5>
|
|
<div class="next-piece-container d-flex align-items-center justify-content-center" style="height: 170px;">
|
|
<canvas id="next-piece" width="150" height="150"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2">
|
|
<button id="start-btn" class="btn btn-primary py-2 fw-semibold">Start New Game</button>
|
|
<button id="pause-btn" class="btn btn-outline-secondary py-2 fw-semibold" disabled>Pause</button>
|
|
</div>
|
|
|
|
<?php if (!empty($highScores)): ?>
|
|
<div class="mt-4" id="high-scores-section">
|
|
<h6 class="fw-bold text-uppercase small text-muted mb-3">High Scores</h6>
|
|
<div class="list-group list-group-flush border-0">
|
|
<?php foreach ($highScores as $s): ?>
|
|
<div class="list-group-item d-flex justify-content-between align-items-center small py-2">
|
|
<span><?= htmlspecialchars($s['player_name']) ?></span>
|
|
<span class="fw-bold text-info"><?= (int)$s['score'] ?></span>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="container py-4 border-top border-secondary text-center">
|
|
<p class="text-muted small mb-1">© <?= date('Y') ?> Classic Tetris. Built with PHP & Canvas.</p>
|
|
<a href="about.php" class="text-decoration-none small text-muted">About the Author</a>
|
|
</footer>
|
|
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|