Upload files to "/"

This commit is contained in:
5803025056 2025-12-15 21:16:50 -05:00
parent db356f55be
commit c3005b83ab
5 changed files with 298 additions and 0 deletions

97
menu.php Normal file
View File

@ -0,0 +1,97 @@
<?php
session_start();
if (!isset($_SESSION['user'])) {
header("Location: index.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Menu Utama</title>
<link rel="stylesheet" href="assets/style.css">
<style>
/* Popup background */
#settingsPopup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
justify-content: center;
align-items: center;
}
/* Popup box */
.popup-box {
background: #1e1e1e;
width: 350px;
padding: 20px;
border-radius: 12px;
text-align: center;
color: white;
box-shadow: 0 0 20px black;
}
.popup-option {
width: 100%;
padding: 12px;
margin-top: 8px;
border: none;
border-radius: 8px;
font-size: 15px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="box" style="width: 350px;">
<h2>Menu Utama</h2>
<p>Halo, <b><?= $_SESSION['user'] ?></b></p>
<a href="game.php">
<button style="width: 100%;">Mulai Game</button>
</a>
<!-- Tombol Settings membuka popup -->
<button onclick="openSettings()" style="width: 100%; background:#00d37e;">Pengaturan</button>
<a href="logout.php">
<button style="width: 100%; background: #ff4d4d;">Keluar</button>
</a>
</div>
<!-- ================= SETTINGS POPUP ================== -->
<div id="settingsPopup">
<div class="popup-box">
<h2>Pengaturan</h2>
<a href="skins.php">
<button class="popup-option" style="background:#ffaa00;">Pilih Skin</button>
</a>
<button class="popup-option" onclick="closeSettings()" style="background:#555;">Kembali</button>
</div>
</div>
<script>
function openSettings() {
document.getElementById("settingsPopup").style.display = "flex";
}
function closeSettings() {
document.getElementById("settingsPopup").style.display = "none";
}
</script>
</body>
</html>

43
register.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require 'db.php';
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$check = $conn->query("SELECT * FROM users WHERE username='$username'");
if ($check->num_rows > 0) {
$message = "Username sudah digunakan!";
} else {
$sql = "INSERT INTO users(username, password) VALUES('$username', '$password')";
if ($conn->query($sql)) {
header("Location: index.php");
exit;
} else {
$message = "Gagal registrasi!";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link rel="stylesheet" href="assets/style.css">
</head>
<body>
<div class="box">
<h2>Register</h2>
<form method="POST">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit">Daftar</button>
</form>
<p><?= $message ?></p>
<a href="index.php">Login</a>
</div>
</body>
</html>

24
save_score.php Normal file
View File

@ -0,0 +1,24 @@
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "dodge_game");
if ($conn->connect_error) {
die("DB Error: " . $conn->connect_error);
}
$username = $_POST['username'];
$score = intval($_POST['score']);
// cek jika user sudah punya skor sebelumnya
$check = $conn->query("SELECT * FROM leaderboard WHERE username='$username'");
if ($check->num_rows > 0) {
// update jika score baru lebih tinggi
$conn->query("UPDATE leaderboard SET score=GREATEST(score, $score) WHERE username='$username'");
} else {
// insert jika belum ada
$conn->query("INSERT INTO leaderboard (username, score) VALUES ('$username', $score)");
}
echo "OK";
?>

BIN
settings.php Normal file

Binary file not shown.

134
skins.php Normal file
View File

@ -0,0 +1,134 @@
<?php
session_start();
if (!isset($_SESSION['user'])) {
header("Location: index.php");
exit;
}
$conn = new mysqli("localhost", "root", "", "dodge_game");
$user = $_SESSION['user'];
// AMBIL SKIN USER SEKARANG
$qSkin = $conn->query("SELECT skin FROM users WHERE username='$user'");
$currentSkin = $qSkin->fetch_assoc()['skin'];
// LIST SKIN
$skins = [
"cyan" => "#00ffff",
"blue" => "#0066ff",
"yellow" => "#ffee00",
"purple" => "#ff55ff",
"green" => "#33ff55"
];
// AMBIL SKIN USER
$qSkin = $conn->query("SELECT skin FROM users WHERE username='$user'");
$data = $qSkin->fetch_assoc();
// PROSES SIMPAN SKIN
if (isset($_POST['chooseSkin'])) {
$selectedSkin = $_POST['skin'];
$conn->query("UPDATE users SET skin='$selectedSkin' WHERE username='$user'");
$currentSkin = $selectedSkin;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Pilih Skin</title>
<link rel="stylesheet" href="assets/style.css">
<style>
body {
text-align: center;
padding-top: 40px;
color: white;
}
.skin-container {
margin-top: 20px;
}
.skin-box {
width: 90px;
height: 90px;
border-radius: 12px;
display: inline-block;
margin: 12px;
cursor: pointer;
transition: 0.2s;
border: 4px solid transparent;
}
.skin-box:hover {
transform: scale(1.1);
}
.skin-selected {
border: 4px solid #fff;
box-shadow: 0 0 15px white;
}
.hidden-radio {
display: none;
}
</style>
</head>
<body>
<h2>Pilih Skin Pemain</h2>
<form method="POST">
<div class="skin-container">
<?php foreach ($skins as $name => $color): ?>
<label>
<input
type="radio"
name="skin"
class="hidden-radio"
value="<?= $name ?>"
<?= $currentSkin == $name ? "checked" : "" ?>
>
<div
class="skin-box <?= $currentSkin == $name ? "skin-selected" : "" ?>"
style="background: <?= $color ?>"
></div>
</label>
<?php endforeach; ?>
</div>
<br><br>
<button type="submit" name="chooseSkin" style="width:250px;">Simpan Skin</button>
</form>
<a href="menu.php">
<button style="width:250px; background:#555; margin-top:20px;">Kembali</button>
</a>
<script>
// AUTO HIGHLIGHT SKIN KETIKA DIPILIH
const radios = document.querySelectorAll("input[name='skin']");
const boxes = document.querySelectorAll(".skin-box");
boxes.forEach((box, index) => {
box.addEventListener("click", () => {
// pilih radio
radios[index].checked = true;
// remove highlight
boxes.forEach(b => b.classList.remove("skin-selected"));
// add highlight ke yang dipilih
box.classList.add("skin-selected");
});
});
</script>
</body>
</html>