Compare commits

...

6 Commits
yeri ... main

Author SHA1 Message Date
d0459d99f8 y 2025-12-05 16:00:32 +07:00
77de57304e score ke database 2025-12-05 12:50:38 +07:00
df3f478734 gabungkan smua 2025-12-05 11:37:08 +07:00
77a7a4a342 gabungin semuanya 2025-12-05 11:36:08 +07:00
e30ef4a019 update database 2025-12-03 12:21:15 +07:00
c2a00e3238 leaderboard 2025-12-03 12:01:37 +07:00
11 changed files with 314 additions and 106 deletions

View File

@ -26,7 +26,10 @@
<h1 style="color: red" id="gameover-title">YOU DIED</h1>
<p id="gameover-score">Score: 0</p>
<button id="ulangi" class="modegame">Main lagi?</button>
<button id="keluar" class="modegame">Keluar?</button>
<a href="http://localhost/uas_sem_1/index.php">
<button id="keluar" class="">Keluar?</button>
</a>
</div>
</div>
<div id="gameover" class="gameover"></div>

BIN
gameOver/gameOver.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -16,7 +16,6 @@
width: 70%;
justify-self: center;
background-image: url();
}
#button {
@ -35,13 +34,15 @@
<body>
<h1>EAT THAT APPLE</h1>
<div class="container">
<a href="game.html">
<div id="button">Play Game</div>
</a>
<div id="button">Leaderboard</div>
<div id="button">Quit</div>
<div id="button">Logout</div>
</div>
<input type="text">
</body>
<script>
</script>
<script></script>
</html>

View File

@ -1,26 +1,72 @@
<?php
// buat inisialisasi session
session_start();
// mengecek apakah ada session user yang aktif, jika tidak arahkan ke login.php
if(!isset($_SESSION['users'])) {
header('location:login.php'); // arahkan ke login.php
header('location:login.php');
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<style>
body {
background-image: url();
}
h1 {
text-align: center;
margin-top: 10%;
font-size: 85px;
}
.container {
padding: 5px;
border: 2px solid; /* Nanti dihapus */
border-radius: 7pt; /* Nanti dihapus */
width: 70%;
justify-self: center;
background-image: url();
}
#button {
font-size: 35px;
margin-top: 5%;
width: 50%;
margin-bottom: 5%;
border: 1px solid;
border-radius: 3pt;
padding: 2px;
justify-self: center;
text-align: center;
}
</style>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman ke-1</title>
</head>
<body style='text-align:center'>
<h1>Halaman ke-1</h1>
<a href="index.php">Home</a>
<a href="logout.php">Logout</a>
</head>
<body style='text-align:center'>
<h1>EAT THAT APPLE</h1>
<!-- <a href="index.php">Home</a>
<a href="logout.php">Logout</a> -->
<hr>
<h3>Selamat datang, <?php echo $_SESSION['users']['nama'] ?></h3>
Halaman ini akan tampil setelah user login.
</body>
<br>
<!-- <h1>EAT THAT APPLE</h1> -->
<div class="container">
<a href="game.html">
<div id="button">Play Game</div>
</a>
<a href="http://localhost/uas_sem_1/leaderboard.php">
<div id="button">Leaderboard</div>
</a>
<a href="http://localhost/uas_sem_1/logout.php">
<div id="button">Logout</div>
</a>
</div>
</body>
</html>

78
leaderboard.php Normal file
View File

@ -0,0 +1,78 @@
<?php
session_start();
require_once "koneksi.php";
if (isset($_SESSION['username'])) {
$nama = $_SESSION['username'];
} else {
$nama = "";
}
$score = 0;
if (!empty($nama)) {
$getScore = "SELECT score FROM users WHERE username = '$nama'";
$resultMe = mysqli_query($koneksi, $getScore);
if ($resultMe && mysqli_num_rows($resultMe) > 0) {
$row = mysqli_fetch_assoc($resultMe);
$score = $row['score'];
}
}
$sql = "SELECT username, score FROM users ORDER BY score DESC LIMIT 10";
$result = mysqli_query($koneksi, $sql);
$leaderboard = [];
if($result) {
$leaderboard = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaderboard</title>
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
</head>
<body>
<table>
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$peringkat = 1;
if (!empty($leaderboard)) {
foreach ($leaderboard as $pemain):
?>
<tr>
<td><?php echo $peringkat; ?></td>
<td><?php echo htmlspecialchars($pemain['username']); ?></td>
<td><?php echo $pemain['score']; ?> PTS</td>
</tr>
<?php
$peringkat++;
endforeach;
} else {
echo '<tr><td colspan="3" style="text-align: center;">Belum ada Pemain</td></tr>';
}
?>
</tbody>
</table>
</body>
</html>

View File

@ -1,18 +1,8 @@
<?php
session_start();
include "koneksi.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman: Login</title>
</head>
<body>
<?php
if(isset($_POST['username'])) {
if(isset($_POST['username'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
@ -21,13 +11,32 @@ include "koneksi.php";
if(mysqli_num_rows($query) > 0) {
$data = mysqli_fetch_array($query);
$_SESSION['users'] = $data;
echo '<script>alert("Selamat datang, '.$data['nama'].'"); location.href="index.php";</script>';
$_SESSION['username'] = $data = ['username'];
echo '<script>location.href="index.php";</script>';
} else {
echo '<script>alert("Username atau Password tidak sesuai");</script>';
}
}
?>
?>
<!DOCTYPE html>
<html lang="id">
<style>
body {
background-color: limegreen;
}
.login {
background-image: url('login/log.png');
}
</style>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman: Login</title>
</head>
<body>
<div class="login">
<form action="" method="post">
<table align="center">
<tr>
@ -37,12 +46,12 @@ include "koneksi.php";
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
<td></td>
<td><input type="text" name="username" placeholder="Username" style="border: none"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
<td></td>
<td><input type="password" name="password" placeholder="Password" style="border: none"></td>
</tr>
<tr>
<td></td>
@ -53,6 +62,8 @@ include "koneksi.php";
</tr>
</table>
</form>
</div>
</body>
</body>
</html>

BIN
login/log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
login/login.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
mapGame/mapgame .png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
succes/loginSuccess.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

69
users.sql Normal file
View File

@ -0,0 +1,69 @@
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Dec 03, 2025 at 05:17 AM
-- Server version: 8.0.30
-- PHP Version: 8.1.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `game`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id_user` int NOT NULL,
`nama` varchar(255) DEFAULT NULL,
`username` varchar(225) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`score` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id_user`, `nama`, `username`, `password`, `score`) VALUES
(1, 'Chris Daud Koroh', 'daudkoroh', '88d602f1ad6d62b9a11c688ab47fed22', 20),
(2, 'Zefanya Isaac', 'zefanya', 'de413c0365e3c88d8b3315f9d90b98ae', 68);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id_user`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id_user` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;