Browse Source

Finished high score system for bamboo field

pull/1/head
jrtechs 4 years ago
parent
commit
cd368ee790
9 changed files with 182 additions and 28 deletions
  1. +16
    -8
      games/bamboofield.html
  2. +18
    -5
      games/bamboofield.php
  3. +42
    -0
      games/highscore.php
  4. +19
    -6
      games/insertScore.php
  5. +44
    -0
      games/userscores.php
  6. +1
    -1
      includes/footer.php
  7. +0
    -2
      includes/header.php
  8. +2
    -2
      index.php
  9. +40
    -4
      user/profile.php

+ 16
- 8
games/bamboofield.html View File

@ -253,6 +253,8 @@
}
}
var sent;
var tic = function()
{
//console.log('tic was called');
@ -264,16 +266,22 @@
}
else
{
context.fillStyle = "rgba(0, 0,0 ,1)";
context.fillRect(0,0, width, height);
if(!sent)
{
context.fillStyle = "rgba(0, 0,0 ,1)";
context.fillRect(0,0, width, height);
context.fillStyle = "rgba(255, 255,255 ,1)";
context.font = "20px Georgia";
context.fillText("You died with a score of: " + score, 250, 325);
context.fillStyle = "rgba(255, 255,255 ,1)";
context.font = "20px Georgia";
context.fillText("You died with a score of: " + score, 250, 325);
document.body.innerHTML += '<form id="dynForm" action="insertScore.php" method="post"><input type="hidden" name="game_new_score" value=true><input type="hidden" name="game" value=1><input type="hidden" name="user_id_score" value=<?php echo $_SESSION['user_id']; ?>><input type="hidden" name="score_validate" value=' + score + '></form>';
document.getElementById("dynForm").submit();
sent = true;
}
document.body.innerHTML += '<form id="dynForm" action="games/insertScore.php" method="post"><input type="hidden" name="game_new_score" value=true><input type="hidden" name="game" value=1><input type="hidden" name="user_id_score" value=<?php echo $_SESSION['user_id']; ?>><input type="hidden" name="score_validate" value=' + score + '></form>';
document.getElementById("dynForm").submit();
}
animate(tic);
}

+ 18
- 5
games/bamboofield.php View File

@ -5,16 +5,29 @@
//ini_set('display_errors', 1);
include '../includes/header.php';
echo '<br><div class="w3-row">
<div class="w3-twothird w3-container ">';
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-half w3-container">';
include('bamboofield.html');
echo '</div><div class="w3-third w3-container">';
echo '</div><div class="w3-half w3-container">';
//include('../includes/profile.php');
include('highscore.php');
echo '</div></div>';
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-half w3-container">';
//edit user
include('../user/profile.php');
echo '</div>';
echo '</div>';
echo '</div><div class="w3-half w3-container">';
include('userscores.php');
echo '</div></div>';
include '../includes/footer.php';

+ 42
- 0
games/highscore.php View File

@ -0,0 +1,42 @@
<?php
//5-17-17
echo '<h1 class="w3-text-teal"><center>High Scores</center></h1>';
$q = "select * from scores order by score desc limit 20";
$r = mysqli_query($dbc, $q);
echo '<div class="w3-responsive w3-card-4"><table class="w3-table w3-striped w3-bordered"><thead>';
echo '<tr class="w3-theme">
<td>Rank</td>
<td>User Name</td>
<td>Score</td>
</tr></thead><tbody>';
$rank = 0;
while($row = mysqli_fetch_array($r))
{
$rank ++;
echo '<tr>';
echo '<td>' . $rank . '</td>';
echo '<td>';
$q2 = "select user_name from users where user_id='". $row['user_id'] . "' limit 1";
$r2 = mysqli_query($dbc, $q2);
while($row2 = mysqli_fetch_array($r2))
{
echo $row2['user_name'];
}
echo '</td>';
//score
echo '<td>' . $row['score'] . '</td>';
echo '</tr>';
}
echo '</tbody></table></div>';
?>

+ 19
- 6
games/insertScore.php View File

@ -1,23 +1,36 @@
<?php
//5-16-17
include_once '../../club_connect.php';
if(isset($_POST['game_new_score']))
{
$i_game = mysqli_real_escape_string($dbc, trim($_POST['game']));
$i_user_id = mysqli_real_escape_string($dbc, trim($_POST['user_id_score']));
$i_score = mysqli_real_escape_string($dbc, trim($_POST['score_validate']));
//
// foreach ($_POST as $key => $value)
// {
// echo $value . '<br>';
// }
$q = "insert into scores(game, user_id, score) values('$i_game','$i_user_id','$i_score')";
if($i_user_id > 0)
{
$r = mysqli_query($dbc, $q);
}
//
//
// echo '<h1>' . $q . '</h1>';
echo '<h1>' . $q . '</h1>';
$r = mysqli_query($dbc, $q);
//echo("<meta http-equiv='refresh' content='1'>");
if($i_game == 1)
{
header("Location: bamboofield.php");
}
}

+ 44
- 0
games/userscores.php View File

@ -0,0 +1,44 @@
<?php
//5-17-17
if($loggedIn)
{
echo '<h1 class="w3-text-teal"><center>User\'s Personal Records</center></h1>';
$q = "select * from scores where user_id='" . $_SESSION['user_id'] . "' order by score desc limit 20";
$r = mysqli_query($dbc, $q);
echo '<div class="w3-responsive w3-card-4"><table class="w3-table w3-striped w3-bordered"><thead>';
echo '<tr class="w3-theme">
<td>User Name</td>
<td>Score</td>
</tr></thead><tbody>';
while($row = mysqli_fetch_array($r))
{
echo '<tr>';
echo '<td>';
$q2 = "select user_name from users where user_id='". $row['user_id'] . "' limit 1";
$r2 = mysqli_query($dbc, $q2);
while($row2 = mysqli_fetch_array($r2))
{
echo $row2['user_name'];
}
echo '</td>';
//score
echo '<td>' . $row['score'] . '</td>';
echo '</tr>';
}
echo '</tbody></table></div>';
}
?>

+ 1
- 1
includes/footer.php View File

@ -2,7 +2,7 @@
<footer class="w3-container w3-padding-32 w3-theme-d1 w3-center">
<h4>Follow Us</h4>
<a class="w3-button w3-large w3-teal" href="http://instagram.com/jrtechs" title="Google +"><i class="fa fa-instagram"></i></a>
<a class="w3-button w3-large w3-teal w3-hide-small" href="javascript:void(0)" title="Linkedin"><i class="fa fa-linkedin"></i></a>
<a class="w3-button w3-large w3-teal w3-hide-small" href="https://www.youtube.com/channel/UCbebizd25t22-vv13_lr9_A/featured" title="Linkedin"><i class="fa fa-youtube"></i></a>
<p>Powered by <a href="https://www.jrtechs.net" target="_blank">Jrtechs</a></p>
<div style="position:relative;bottom:100px;z-index:1;" class="w3-tooltip w3-right">

+ 0
- 2
includes/header.php View File

@ -87,7 +87,6 @@
<div class="w3-top">
<div class="w3-bar w3-theme-d2 w3-left-align">
<a class="w3-bar-item w3-button w3-hide-medium w3-hide-large w3-right w3-hover-white w3-theme-d2" href="javascript:void(0);" onclick="openNav()"><i class="fa fa-bars"></i></a>
<a href="#" class="w3-bar-item w3-button w3-teal"><i class="fa fa-home w3-margin-right"></i>Logo</a>
<a href="../index.php" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Home</a>
<a href="../about.php" class="w3-bar-item w3-button w3-hide-small w3-hover-white">About</a>
<div class="w3-dropdown-hover w3-hide-small">
@ -146,7 +145,6 @@
<div class="w3-top">
<div class="w3-bar w3-theme-d2 w3-left-align">
<a class="w3-bar-item w3-button w3-hide-medium w3-hide-large w3-right w3-hover-white w3-theme-d2" href="javascript:void(0);" onclick="openNav()"><i class="fa fa-bars"></i></a>
<a href="#" class="w3-bar-item w3-button w3-teal"><i class="fa fa-home w3-margin-right"></i>Logo</a>
<a href="index.php" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Home</a>
<a href="about.php" class="w3-bar-item w3-button w3-hide-small w3-hover-white">About</a>
<div class="w3-dropdown-hover w3-hide-small">

+ 2
- 2
index.php View File

@ -12,7 +12,7 @@
//new game or something
include 'games/bamboofield.html';
//include 'games/bamboofield.html';
echo '</div><div class="w3-half w3-container">';
//profile
@ -42,7 +42,7 @@
echo '</div></div>';
echo '<div class="w3-half w3-container"><div id="repo1">';
include('games/bamboofield.html');
//include('games/bamboofield.html');
echo '</div></div></div>';
include 'includes/footer.php';

+ 40
- 4
user/profile.php View File

@ -8,7 +8,14 @@
echo '<h3>You are now logged out</h3>';
echo("<meta http-equiv='refresh' content='1'>");
if($dir == 2)
{
header("Location: ../index.php");
}
else
{
header("Location: index.php");
}
}
if(isset($_POST['log_in']))
@ -70,8 +77,15 @@
$_SESSION['username'] = $row['user_name'];
$_SESSION['agent'] = md5($_SERVER['HTTP_USERAGENT'] . 'salt');
if($dir == 2)
{
header("Location: ../index.php");
}
else
{
header("Location: index.php");
}
header("Location: index.php");
}
}
else
@ -106,17 +120,39 @@
{
echo '<h3 class="w3-center">Welcome ' . $_SESSION['fname'] . '</h3>';
echo '<form action="index.php" method ="post">
if($dir == 2)
{
echo '<form action="../index.php" method ="post">
<input class="w3-padding-16 w3-hover-dark-grey w3-btn-block w3-center-align" type="submit" name ="logout" value="logout" />
<input type="hidden" name="logout" value="TRUE" />
</form>';
}
else
{
echo '<form action="index.php" method ="post">
<input class="w3-padding-16 w3-hover-dark-grey w3-btn-block w3-center-align" type="submit" name ="logout" value="logout" />
<input type="hidden" name="logout" value="TRUE" />
</form>';
}
}
else
{
//prints login form
echo '<form action ="index.php" method ="post">
if($dir == 2)
{
echo '<form action ="../index.php" method ="post">';
}
else
{
echo '<form action ="index.php" method ="post">';
}
echo '
<div class="w3-group">
<input class="w3-input" type="text" value="" name="user_name" class="w3-container w3-card-4" required/>
<label class="w3-label w3-validate">User Name</label>

Loading…
Cancel
Save