forked from andz138/Team4_AnimalSim_Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
56 lines (45 loc) · 1.48 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
include('common.php');
include('user_data_handler.php');
myHeader('Virtual Pet Game');
?>
<body class="index">
<div class="container">
<h1>Welcome to the Virtual Pet Game!</h1>
<ul>
<li><img src="images/login.png" alt="Login Image"><a href="login.php">Login</a></li>
<li><img src="images/register.png" alt="Register Image"><a href="register.php">Register</a></li>
</ul>
<h2>Leaderboard</h2>
<table>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Score</th>
</tr>
<?php
$filename = 'user_data.txt';
$leaderboard = [];
if (file_exists($filename)) {
$lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$parts = explode(",", $line);
$leaderboard[] = ['username' => $parts[0], 'score' => intval($parts[4])];
}
usort($leaderboard, function($a, $b) {
return $b['score'] - $a['score'];
});
$rank = 1;
foreach ($leaderboard as $user) {
echo "<tr><td>$rank</td><td>{$user['username']}</td><td>{$user['score']}</td></tr>";
$rank++;
}
}
?>
</table>
</div>
<?php
myFooter();
?>
</body>
</html>