-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighscores.php
128 lines (122 loc) · 4.32 KB
/
highscores.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*** -- File Details --
* Original Creation Date: 2011-02-06
* Date Last Edited or Altered: 2011-02-07
* Author List [most recent active month]:
* Stephen T. Robbins [2011-02]
* File Dependencies: Location:
* newlands.css includes/css/
* connectinfo.php nope
* includes/lib/jquery/js/jquery-1.5.min.js
* includes/lib/jquery/js/jquery-ui-1.8.9.custom.min.js
* includes/lib/jquery/DataTables-1.7.5/media/js/jquery.dataTables.min.js
* Function List:
* -none-
*/
/* File Description: This file is the page used to view high scores for the
* MooTools, JavaScript-based game "New Lands".
*
* File Activity Explanation: This will generate a simple web page table and
* fill it with high score records from the database. The table is powered
* by jQuery-UI DataTables.
*/
/* -- Known Issues, Suggested Updates/Improvements, and Notices --
* -none-
*/
// Require necessary file dependencies.
require_once("../../../nope/connectinfo.php"); // _remote_x10
/* Get the high score data from the database. */
// Connect to the database.
$mysqli = new mysqli('localhost', $mydb_user, $mydb_password, $mydb_database_games);
if ($mysqli->connect_errno) {
die("DB connection failed @ " . $mysqli->connect_errno . ": " . $mysqli->connect_error . "\n");
}
// Query the database for the high score records.
$query = "SELECT *
FROM newlands_highscore
ORDER BY (highscore_exploration_days / (highscore_map_shortaxis * highscore_map_longaxis)) ASC;";
$result = $mysqli->query($query);
if ($result === false) {
echo("Highscore query failed @ " . $mysqli->connect_errno . ": " . $mysqli->connect_error . "\n");
}
// Disconnect from the database.
$mysqli->close();
/* Display the page. */
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>New Lands Exploration</title>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1" />
<link href="includes/css/newlands.css" rel="stylesheet" />
<script type="text/javascript" src="includes/lib/jquery/js/jquery-1.5.min.js"></script>
<script type="text/javascript" src="includes/lib/jquery/js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="includes/lib/jquery/js/jquery-dataTables-1.7.5.min.js"></script>
</head>
<body>
<table class="gui_main data_table" id="scores_table">
<thead>
<tr>
<th colspan="7" style="text-align: left;">
<a href="index.php">Play the game</a>
<span style="float: right;"><a href="highscores.php">Refresh Scores</a></span>
</th>
</tr>
<tr class="sortable_header_row">
<th>Player</th>
<th>Map<br/>Size</th>
<th>Exp.<br/>Pct.</th>
<th>Days<br/>Exp.</th>
<th>Rem.<br/>Sup.</th>
<th>Difficulty</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody>
<?php
// Parse the returned $result resource and print high score records into the table.
while($row = $result->fetch_array(MYSQLI_BOTH))
{
$playername = $row["highscore_playername"];
$shortaxis = $row["highscore_map_shortaxis"];
$longaxis = $row["highscore_map_longaxis"];
$mapsize = $shortaxis * $longaxis;
$explored = $row["highscore_explored_cells"];
$explore_pct = $explored / $mapsize * 100;
$days = $row["highscore_exploration_days"];
$supplies = $row["highscore_supplies_remaining"];
$difficultylevel = $row["highscore_difficultylevel"];
$difficulty = "";
switch($difficultylevel)
{
case 1: $difficulty = "easy"; break;
case 2: $difficulty = "normal"; break;
case 3: $difficulty = "hard"; break;
}
$time = $row["highscore_timestamp"];
echo <<<END
<tr>
<td style="text-align: left; white-space: nowrap; letter-spacing: 0.1em;">$playername</td>
<td>$mapsize</td>
<td>$explore_pct%</td>
<td>$days</td>
<td>$supplies</td>
<td>($difficultylevel) $difficulty</td>
<td>$time</td>
</tr>
END;
}
?>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#scores_table').dataTable( {
'bPaginate': true,
'bFilter': false,
'bSort': true,
'bInfo': false } );
} );
</script>
</body>
</html>