2025-12-09 22:04:30 -05:00

180 lines
5.1 KiB
PHP

<?php
session_start();
$conn = new mysqli("localhost","root","","breakout_db");
if($conn->connect_error){ die("DB Error"); }
$isLoggedIn = isset($_SESSION['username']);
$username = $isLoggedIn ? htmlspecialchars($_SESSION['username']) : null;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Breakout Game</title>
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
/* ===== GLOBAL STYLE ===== */
body {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
background: radial-gradient(circle at top, #6a85f1, #4834d4);
color: white;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
h1 {
font-size: 2.7rem;
margin-top: 25px;
text-shadow: 3px 3px 10px rgba(0,0,0,0.4);
letter-spacing: 1px;
}
/* ===== MENU ===== */
.menu {
margin-top: 10px;
display: flex;
gap: 15px;
flex-wrap: wrap;
}
.menu a {
text-decoration: none;
color: #fff;
padding: 10px 18px;
background: rgba(255,255,255,0.18);
border-radius: 30px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.3);
transition: 0.3s ease;
display: flex;
align-items: center;
gap: 7px;
}
.menu a:hover {
transform: translateY(-3px);
background: rgba(255,255,255,0.35);
}
.user-info {
font-size: 1.1rem;
margin-bottom: 5px;
text-align: center;
}
/* ===== GAME CARD ===== */
.game-container {
margin-top: 20px;
background: rgba(255,255,255,0.08);
backdrop-filter: blur(12px);
padding: 25px;
border-radius: 20px;
border: 1px solid rgba(255,255,255,0.25);
box-shadow: 0px 10px 25px rgba(0,0,0,0.25);
text-align: center;
width: 95%;
max-width: 520px;
}
canvas {
border-radius: 12px;
border: 3px solid rgba(255,255,255,0.8);
background: #111;
box-shadow: 0px 8px 25px rgba(0,0,0,0.6);
}
#score {
font-size: 1.6rem;
font-weight: bold;
margin: 10px 0;
}
/* ===== CONTROLS ===== */
.controls {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 15px;
flex-wrap: wrap;
}
select {
padding: 8px 12px;
border-radius: 8px;
border: none;
font-size: 1rem;
outline: none;
}
button {
padding: 10px 22px;
font-size: 1rem;
border: none;
border-radius: 25px;
color: white;
background: linear-gradient(45deg, #ff6b6b, #ff4757);
box-shadow: 0px 5px 15px rgba(255,76,76,0.4);
transition: 0.25s ease;
cursor: pointer;
}
button:hover {
transform: scale(1.05);
box-shadow: 0px 7px 18px rgba(255,76,76,0.55);
}
@media (max-width: 600px) {
h1 { font-size: 2.2rem; }
canvas { width: 100%; height: auto; }
}
</style>
</head>
<body>
<h1><i class="fas fa-gamepad"></i> Breakout Game</h1>
<!-- USER MENU -->
<div class="menu">
<?php if($isLoggedIn): ?>
<span class="user-info">Hello, <b><?= $username ?></b> 👋</span>
<a href="leaderboard.php"><i class="fas fa-trophy"></i> Leaderboard</a>
<a href="logout.php"><i class="fas fa-right-from-bracket"></i> Logout</a>
<?php else: ?>
<a href="login.php"><i class="fas fa-sign-in-alt"></i> Logout</a>
<a href="leaderboard.php"><i class="fas fa-trophy"></i> Leaderboard</a>
<?php endif; ?>
</div>
<!-- GAME CARD -->
<div class="game-container">
<canvas id="game" width="480" height="320"></canvas>
<p>Score: <span id="score">0</span></p>
<div class="controls">
<select id="diff">
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<button onclick="startGame()">Start Game</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>