Browse Source

Refactored syntax style of project

pull/5/head
jrtechs 3 years ago
parent
commit
07bd68c6ec
19 changed files with 1337 additions and 1552 deletions
  1. +8
    -14
      about.php
  2. +30
    -38
      admin.php
  3. +10
    -14
      games.php
  4. +21
    -95
      games/astroids.html
  5. +229
    -272
      games/bamboofield.html
  6. +23
    -26
      games/bamboofield.php
  7. +40
    -43
      games/highscore.php
  8. +23
    -39
      games/insertScore.php
  9. +27
    -34
      games/userscores.php
  10. +289
    -294
      games/zombiePanda.html
  11. +21
    -25
      games/zombiePanda.php
  12. +0
    -3
      includes/footer.php
  13. +123
    -132
      includes/header.php
  14. +53
    -52
      index.php
  15. +102
    -94
      user/editUser.php
  16. +78
    -77
      user/newUser.php
  17. +128
    -157
      user/profile.php
  18. +76
    -77
      user/register.php
  19. +56
    -66
      user/users.php

+ 8
- 14
about.php View File

@ -1,21 +1,15 @@
<?php
//5-19-17
//5-19-17
include 'includes/header.php';
include 'includes/header.php';
echo '<br><div class="w3-row">
<div class="w3-half w3-container ">';
//add stuff
echo '<br><div class="w3-row">
<div class="w3-half w3-container ">';
echo '</div><div class="w3-half w3-container">';
include 'user/profile.php';
echo '</div><div class="w3-half w3-container">';
include 'user/profile.php';
echo '</div></div>';
echo '</div>';
echo '</div>';
include 'includes/footer.php';
?>
include 'includes/footer.php';

+ 30
- 38
admin.php View File

@ -1,39 +1,31 @@
<?php
//11-24-16
require('includes/header.php');
if($admin)
{
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-twothird w3-container">';
//users
include('user/users.php');
echo '</div><div class="w3-third w3-container">';
//profile
include('user/profile.php');
echo '</div></div>';
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-twothird w3-container">';
//edit user
include('user/editUser.php');
echo '</div><div class="w3-third w3-container">';
//new user
include('user/newUser.php');
echo '</div></div>';
}
else
{
include('includes/profile.php');
}
require('includes/footer.php');
?>
//11-24-16
require('includes/header.php');
if($admin)
{
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-twothird w3-container">';
include('user/users.php');
echo '</div><div class="w3-third w3-container">';
include('user/profile.php');
echo '</div></div>';
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-twothird w3-container">';
include('user/editUser.php');
echo '</div><div class="w3-third w3-container">';
include('user/newUser.php');
echo '</div></div>';
}
else
{
include('includes/profile.php');
}
require('includes/footer.php');

+ 10
- 14
games.php View File

@ -1,22 +1,18 @@
<?php
//5-16-17
//5-16-17
//ini_set('display_errors', 1);
include 'includes/header.php';
//ini_set('display_errors', 1);
include 'includes/header.php';
echo '<br><div class="w3-row">
<div class="w3-half w3-container ">';
include('games/bamboofield.html');
echo '<br><div class="w3-row">
<div class="w3-half w3-container ">';
include('games/bamboofield.html');
echo '</div><div class="w3-half w3-container">';
include('games/zombiePanda.html');
echo '</div><div class="w3-half w3-container">';
include('games/zombiePanda.html');
echo '</div>';
echo '</div>';
echo '</div></div>';
include 'includes/footer.php';
?>
include 'includes/footer.php';

+ 21
- 95
games/astroids.html View File

@ -23,16 +23,16 @@
c.fillRect(0,0, canvas.width, canvas.height);
};
//entire game
function playBF()
{
var animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback)
var animate = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame || function (callback)
{
window.setTimeout(callback, 1000 / 60)
};
var canvas = document.getElementById("canvas");
var width = 800;
@ -121,54 +121,41 @@
this.dirSpeed = 10;
this.render = function()
{
context.fillStyle = "rgba(255, 255, 255, 1)"; //white
context.fillRect(this.x, this.y, this.width, this.height);
}
this.move = function()
{
for (var key in keysDown)
{
var value = Number(key);
if(value == 37) //left
{
this.dir += this.dirSpeed * Math.PI / 360;
}
else if(value == 39)
{
//
this.dir -= this.dirSpeed * Math.PI / 360;
}
else if(value == 38) // up
{
this.x += this.speed * Math.sin(this.dir);
this.y += this.speed * Math.cos(this.dir);
}
else if(value == 40) //down
{
this.x -= this.speed * Math.sin(this.dir);
this.y -= this.speed * Math.cos(this.dir);
}
else if(value == 32) //shoot
{
this.shoot();
}
}
//collisions
@ -178,12 +165,15 @@
{
bb = astroids[i];
//if(Math.abs(bb.x - p.x) <= bb.width)
if(p.x > bb.x && p.x < bb.x + bb.width || p.x + p.width < bb.x + bb.width && p.x + p.width > bb.x)
if(p.x > bb.x && p.x < bb.x + bb.width ||
p.x + p.width < bb.x + bb.width && p.x + p.width
> bb.x)
{
if(p.y > bb.y && p.y < bb.y + bb.height || p.y + p.height < bb.y + bb.height && p.y + p.height > bb.y)
if(p.y > bb.y && p.y < bb.y + bb.height ||
p.y + p.height < bb.y + bb.height &&
p.y + p.height > bb.y)
{
alive = false;
bb = -1;
}
}
@ -191,25 +181,14 @@
}
if(this.x < 0)
{
this.x += this.speed;
}
else if(this.x > width- this.width)
{
this.x -= this.speed;
}
if(this.y < 0)
{
this.y += this.speed;
}
else if(this.y > height)
{
this.y -= this.speed;
}
}
this.shoot = function()
@ -224,21 +203,13 @@
bullets[i] = new Bullet(this.dir, this.x, this.y);
}
}
if(dimmed == false)
{
bullets.push(new Bullet(this.dir, this.x, this.y));
}
}
}
//player object
var p = new Player(350, 850);
//object that falls from the sky
var Astroid = function(size)
{
@ -267,18 +238,15 @@
{
this.y = height;
this.x = temp;
}
else
{
this.y = temp;
this.x = 0;
}
this.speed = 2;
this.render = function()
{
context.fillStyle = "rgba(255, 255, 255 , 1)"; //green
@ -299,61 +267,38 @@
//remove bamboo from array
score++;
return true;
}
}
}
var astroids = [];
//draws all the objects
var render = function()
{
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("Score: " + score, 10, 25);
p.render();
for(i= 0; i < astroids.length; i++)
{
if(astroids[i] != -1)
{
astroids[i].render();
}
}
for (var i = bullets.length; i--; )
{
if(bullets[i] != -1)
{
bullets[i].render();
}
}
//console.log('render was called');
//context.fillStyle = "rgba(0, 128, 0 ,1)"; //green
//context.fillRect(0, 0, 700, 700);
//console.log(context);
}
var update = function()
{
addAstroid();
p.move();
var halp = bullets.lenght
//console.log(halp);
//for (b = 0; b < bullets.lenght; b++)
//var b;
@ -371,22 +316,11 @@
}
}
for (i = 0; i< astroids.length; i++)
{
if(astroids[i] != -1)
{
if(astroids[i].move())
{
astroids[i] = -1;
}
}
}
}
var count = 0;
@ -415,8 +349,6 @@
astroids.push(new Astroid());
}
if(limit > 10)
{
limit --;
@ -443,15 +375,9 @@
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;
context.fillText("You died with a score of: " +
score, 250, 325);
}
}
animate(tic);
}
@ -472,9 +398,9 @@
});
//tic();
animate(tic);
}
</script>
<div><canvas id="canvas" width="700" height="700"></canvas></div>
<div><input type="submit" name="play" value="Play Game" onclick="this.blur();playBF()"/></div>
<div><input type="submit" name="play" value="Play Game" onclick="this.blur();
playBF()"/></div>

+ 229
- 272
games/bamboofield.html View File

@ -1,319 +1,276 @@
<script>
window.addEventListener("keydown", function(e)
window.addEventListener("keydown", function(e)
{
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1)
{
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1)
{
e.preventDefault();
}
}, false);
window.onload = function()
e.preventDefault();
}
}, false);
window.onload = function()
{
var canvasBFc = document.getElementById("canvasBF");
var c = canvasBFc.getContext('2d');
c.fillStyle= "black";
c.fillRect(0,0, canvasBFc.width, canvasBFc.height);
};
function playBF()
{
var animate = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame || function (callback)
{
var canvasBFc = document.getElementById("canvasBF");
var c = canvasBFc.getContext('2d');
c.fillStyle= "black";
c.fillRect(0,0, canvasBFc.width, canvasBFc.height);
window.setTimeout(callback, 1000 / 60)
};
//entire game
function playBF()
var canvasBFc = document.getElementById("canvasBF");
var width = 700;
var height = 700;
canvasBFc.style.textAligh = 'center';
var context = canvasBFc.getContext('2d');
var keysDown = {};
//player variables;
var score = 0;
var alive = true;
function getRandomIntInclusive(min, max)
{
var animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback)
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var Player = function(x,y)
{
this.x = 350
this.y = 650;
this.width = 10;
this.height = 10;
this.speed = 4;
this.facing = 40;
this.updateDirection = function(key)
{
window.setTimeout(callback, 1000 / 60)
};
var canvasBFc = document.getElementById("canvasBF");
var width = 700;
var height = 700;
canvasBFc.style.textAligh = 'center';
var context = canvasBFc.getContext('2d');
var keysDown = {};
//player variables;
var score = 0;
var alive = true;
//usefull function
function getRandomIntInclusive(min, max)
facing = key;
}
this.render = function()
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
context.fillStyle = "rgba(255, 255, 255, 1)"; //white
context.fillRect(this.x, this.y, this.width, this.height);
}
//objects
var Player = function(x,y)
this.move = function()
{
this.x = 350
this.y = 650;
this.width = 10;
this.height = 10;
this.speed = 4;
this.facing = 40;
this.updateDirection = function(key)
{
facing = key;
}
this.render = function()
for (var key in keysDown)
{
context.fillStyle = "rgba(255, 255, 255, 1)"; //white
context.fillRect(this.x, this.y, this.width, this.height);
var value = Number(key);
if(value == 37) //left
this.x = this.x - this.speed;
else if(value == 39)
this.x = this.x + this.speed;
}
this.move = function()
//collisions
for(i = 0; i < bamboos.length; i++)
{
for (var key in keysDown)
{
var value = Number(key);
if(value == 37) //left
{
this.x = this.x - this.speed;
}
else if(value == 39)
{
this.x = this.x + this.speed;
}
}
//collisions
for(i = 0; i < bamboos.length; i++)
if(bamboos[i] != -1)
{
if(bamboos[i] != -1)
bb = bamboos[i];
//if(Math.abs(bb.x - p.x) <= bb.width)
if(p.x > bb.x && p.x < bb.x + bb.width ||
p.x + p.width < bb.x + bb.width && p.x +
p.width > bb.x)
{
bb = bamboos[i];
//if(Math.abs(bb.x - p.x) <= bb.width)
if(p.x > bb.x && p.x < bb.x + bb.width || p.x + p.width < bb.x + bb.width && p.x + p.width > bb.x)
if(p.y > bb.y && p.y < bb.y + bb.height ||
p.y + p.height < bb.y + bb.height &&
p.y + p.height > bb.y)
{
if(p.y > bb.y && p.y < bb.y + bb.height || p.y + p.height < bb.y + bb.height && p.y + p.height > bb.y)
{
alive = false;
bb = -1;
}
alive = false;
bb = -1;
}
}
}
if(this.x < 0)
{
this.x += this.speed;
}
else if(this.x > width)
{
this.x -= this.speed;
}
}
if(this.x < 0)
this.x += this.speed;
else if(this.x > width)
this.x -= this.speed;
}
//player object
var p = new Player(350, 850);
//object that falls from the sky
var Bamboo = function()
}
//player object
var p = new Player(350, 850);
//object that falls from the sky
var Bamboo = function()
{
this.width = 25;
this.height = 75;
this.x = getRandomIntInclusive(0, width);
this.y = -this.height;
this.speed = 4;
this.render = function()
{
this.width = 25;
this.height = 75;
this.x = getRandomIntInclusive(0, width);
this.y = -this.height;
this.speed = 4;
this.render = function()
{
context.fillStyle = "rgba(0, 255, 0 , 1)"; //green
context.fillRect(this.x, this.y, this.width, this.height);
}
this.move = function()
{
this.y += this.speed;
if(this.y> height)
{
//remove bamboo from array
score++;
return true;
}
}
context.fillStyle = "rgba(0, 255, 0 , 1)"; //green
context.fillRect(this.x, this.y, this.width, this.height);
}
var bamboos = [];
//draws all the objects
var render = function()
this.move = function()
{
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("Score: " + score, 10, 25);
p.render();
for(i= 0; i < bamboos.length; i++)
this.y += this.speed;
if(this.y> height)
{
if(bamboos[i] != -1)
{
bamboos[i].render();
}
//remove bamboo from array
score++;
return true;
}
//console.log('render was called');
//context.fillStyle = "rgba(0, 128, 0 ,1)"; //green
//context.fillRect(0, 0, 700, 700);
//console.log(context);
}
var update = function()
}
var bamboos = [];
//draws all the objects
var render = function()
{
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("Score: " + score, 10, 25);
p.render();
for(i= 0; i < bamboos.length; i++)
if(bamboos[i] != -1)
bamboos[i].render();
}
var update = function()
{
addBamboo();
p.move();
for (i = 0; i< bamboos.length; i++)
if(bamboos[i] != -1)
if(bamboos[i].move())
bamboos[i] = -1;
addBamboo();
}
var count = 0;
var limit = 25;
var addBamboo = function()
{
count++;
if(count == limit)
{
addBamboo();
p.move();
for (i = 0; i< bamboos.length; i++)
count = 0;
var bnew = true;
for(i = 0; i < bamboos.length; i++)
{
if(bamboos[i] != -1)
if(bamboos[i] == -1)
{
if(bamboos[i].move())
{
bamboos[i] = -1;
}
bamboos[i] = new Bamboo();
bnew = false;
}
}
addBamboo();
if(bnew)
bamboos.push(new Bamboo());
if(limit > 10)
limit --;
}
var count = 0;
var limit = 25;
var addBamboo = function()
}
var sent;
var tic = function()
{
if(alive)
{
count++;
if(count == limit)
{
count = 0;
var bnew = true;
for(i = 0; i < bamboos.length; i++)
{
if(bamboos[i] == -1)
{
bamboos[i] = new Bamboo();
bnew = false;
}
}
if(bnew)
{
bamboos.push(new Bamboo());
}
if(limit > 10)
{
limit --;
}
}
update();
render();
}
var sent;
var tic = function()
else
{
//console.log('tic was called');
if(alive)
{
update();
render();
}
else
if(!sent)
{
if(!sent)
{
context.fillStyle = "rgba(0, 0,0 ,1)";
context.fillRect(0,0, width, height);
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="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;
}
animate(tic);
}
window.addEventListener("keydown", function (event)
{
if(event.keyCode >=37 && event.keyCode <=40)
{
p.facing = event.keyCode;
}
keysDown[event.keyCode] = true;
});
window.addEventListener("keyup", function (event)
{
delete keysDown[event.keyCode];
});
//tic();
animate(tic);
}
window.addEventListener("keydown", function (event)
{
if(event.keyCode >=37 && event.keyCode <=40)
p.facing = event.keyCode;
keysDown[event.keyCode] = true;
});
window.addEventListener("keyup", function (event)
{
delete keysDown[event.keyCode];
});
//tic();
animate(tic);
}
</script>
<div><canvas id="canvasBF" width="700" height="700"></canvas></div>
<div><input type="submit" name="play" value="Play Game" onclick="this.blur();playBF()"/></div>
<div><input type="submit" name="play" value="Play Game" onclick="this.blur();
playBF()"/></div>

+ 23
- 26
games/bamboofield.php View File

@ -1,38 +1,35 @@
<?php
$dir = 2;
//used for high score
$game_id = 1;
$dir = 2;
//ini_set('display_errors', 1);
include '../includes/header.php';
//used for high score
$game_id = 1;
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-half w3-container">';
include('bamboofield.html');
//ini_set('display_errors', 1);
include '../includes/header.php';
echo '<div class="w3-row w3-padding-32">';
echo '<div class="w3-half w3-container">';
include('bamboofield.html');
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">';
echo '</div><div class="w3-half w3-container">';
//include('../includes/profile.php');
include('highscore.php');
//edit user
include('../user/profile.php');
echo '</div></div>';
echo '</div><div class="w3-half w3-container">';
include('userscores.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');
include '../includes/footer.php';
?>
echo '</div><div class="w3-half w3-container">';
include('userscores.php');
echo '</div></div>';
include '../includes/footer.php';

+ 40
- 43
games/highscore.php View File

@ -1,44 +1,41 @@
<?php
//5-17-17
echo '<h1 class="w3-text-teal"><center>High Scores</center></h1>';
$q = "select * from scores where game = '$game_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>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>';
?>
//5-17-17
echo '<h1 class="w3-text-teal"><center>High Scores</center></h1>';
$q = "select * from scores where game = '$game_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>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>';

+ 23
- 39
games/insertScore.php View File

@ -1,42 +1,26 @@
<?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>';
if($i_game == 1)
{
header("Location: bamboofield.php");
}
else if($i_game == 2)
{
header("Location: zombiePanda.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']));
$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);
if($i_game == 1)
header("Location: bamboofield.php");
else if($i_game == 2)
header("Location: zombiePanda.php");
}

+ 27
- 34
games/userscores.php View File

@ -1,44 +1,37 @@
<?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'] . "' and game='$game_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>';
//5-17-17
while($row = mysqli_fetch_array($r))
{
echo '<tr>';
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']
. "' and game='$game_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>';
echo '<td>';
$q2 = "select user_name from users where user_id='". $row['user_id'] . "' limit 1";
$r2 = mysqli_query($dbc, $q2);
while($row = mysqli_fetch_array($r))
{
echo '<tr><td>';
while($row2 = mysqli_fetch_array($r2))
{
echo $row2['user_name'];
}
$q2 = "select user_name from users where user_id='"
. $row['user_id'] . "' limit 1";
$r2 = mysqli_query($dbc, $q2);
echo '</td>';
while($row2 = mysqli_fetch_array($r2))
echo $row2['user_name'];
//score
echo '<td>' . $row['score'] . '</td>';
echo '</td>';
echo '</tr>';
}
echo '</tbody></table></div>';
//score
echo '<td>' . $row['score'] . '</td></tr>';
}
?>
echo '</tbody></table></div>';
}

+ 289
- 294
games/zombiePanda.html View File

@ -1,396 +1,391 @@
<script>
window.addEventListener("keydown", function(e)
window.addEventListener("keydown", function(e)
{
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1)
{
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1)
{
e.preventDefault();
}
}, false);
window.onload = function()
e.preventDefault();
}
}, false);
window.onload = function()
{
var canvas = document.getElementById("canvasZP");
var c = canvas.getContext('2d');
c.fillStyle= "black";
c.fillRect(0,0,canvas.width,canvas.height);
};
function playZP()
{
var animate = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame || function (callback)
{
var canvas = document.getElementById("canvasZP");
var c = canvas.getContext('2d');
c.fillStyle= "black";
c.fillRect(0,0,canvas.width,canvas.height);
window.setTimeout(callback, 1000 / 60)
};
function playZP()
var canvas = document.getElementById("canvasZP");
var width = 700;
var height = 700;
canvas.style.textAlign = 'center';
var context = canvas.getContext('2d');
var keysDown = {};
var score = 0;
var dead = false;
//player
var Player = function(x,y)
{
this.x = x;
this.y = y;
this.width = 25;
this.height = 25;
var animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback)
{
window.setTimeout(callback, 1000 / 60)
};
var canvas = document.getElementById("canvasZP");
var width = 700;
var height = 700;
canvas.style.textAlign = 'center';
var context = canvas.getContext('2d');
var keysDown = {};
var score = 0;
var dead = false;
//player
var Player = function(x,y)
{
this.x = x;
this.y = y;
this.width = 25;
this.height = 25;
this.speed = 3;
this.facing = 40;
this.speed = 3;
this.updateDirection = function(key)
{
facing = key;
}
this.render = function()
{
context.fillStyle = "rgba(0, 45, 160, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
}
this.move = function()
{
for (var key in keysDown)
{
var value = Number(key);
if (value == 37) //left
{
this.x = this.x - this.speed;
}
else if (value == 39) //right
{
this.x = this.x + this.speed
}
else if(value == 38) //up
{
this.y = this.y - this.speed
}
else if(value == 40) //down
{
this.y = this.y + this.speed
}
else if(value == 32)
{
var added = false;
for(i = 0; i< bullets.length; i++)
{
if(bullets[i] == -1)
{
bullets[i] = new Bullet();
added = true;
break;
}
}
if(added == false)
{
bullets.push(new Bullet());
}
}
}
}
this.facing = 40;
this.updateDirection = function(key)
{
facing = key;
}
var p = new Player(350, 350);
//bullet
var Bullet = function()
this.render = function()
{
this.x = p.x;
this.y = p.y;
this.width = 10;
this.height = 10;
this.speed = 4;
this.facing = p.facing;
context.fillStyle = "rgba(0, 45, 160, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
}
this.move = function()
this.move = function()
{
for (var key in keysDown)
{
if (this.facing == 37) //left
var value = Number(key);
if (value == 37) //left
{
this.x = this.x - this.speed;
}
else if (this.facing == 39) //right
}
else if (value == 39) //right
{
this.x = this.x + this.speed
}
else if(this.facing == 38) //up
else if(value == 38) //up
{
this.y = this.y - this.speed
}
else if(this.facing == 40) //down
else if(value == 40) //down
{
this.y = this.y + this.speed
}
else if(value == 32)
{
var added = false;
}
for(i = 0; i< bullets.length; i++)
{
if(bullets[i] == -1)
{
bullets[i] = new Bullet();
added = true;
break;
}
}
if(added == false)
bullets.push(new Bullet());
this.render = function()
{
context.fillStyle = "rgba(255, 0, 199, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
}
}
}
var bullets = [];
}
var p = new Player(350, 350);
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
//bullet
var Bullet = function()
{
this.x = p.x;
this.y = p.y;
this.width = 10;
this.height = 10;
this.speed = 4;
this.facing = p.facing;
//zombie
var Zombie = function(x,y)
this.move = function()
{
this.x = x;
this.y = y;
this.width = 25;
this.height = 25;
this.speed = 3;
var side = getRandomIntInclusive(0,3);
var mid = getRandomIntInclusive(0,700);
if(side === 1)
{
this.x = mid;
this.y = 0;
}
else if(side === 2)
{
this.x = 700;
this.y = mid;
}
else if(side === 3)
{
this.y = 700;
this.x = mid;
}
else
{
this.x = 0;
this.y = mid;
}
if (this.facing == 37) //left
this.x = this.x - this.speed;
else if (this.facing == 39) //right
this.x = this.x + this.speed
else if(this.facing == 38) //up
this.y = this.y - this.speed
else if(this.facing == 40) //down
this.y = this.y + this.speed
}
this.render = function()
{
context.fillStyle = "rgba(0, 160, 0, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
}
this.render = function()
{
context.fillStyle = "rgba(255, 0, 199, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
this.move = function()
{
if(this.x > p.x + this.speed)
this.x -= this.speed;
else if(this.x + this.speed < p.x )
this.x += this.speed;
}
}
var bullets = [];
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
if(this.y > p.y + this.speed)
this.y -= this.speed;
else if(this.y + this.speed < p.y )
this.y += this.speed;
}
//zombie
var Zombie = function(x,y)
{
this.x = x;
this.y = y;
this.width = 25;
this.height = 25;
this.speed = 3;
var side = getRandomIntInclusive(0,3);
var mid = getRandomIntInclusive(0,700);
if(side === 1)
{
this.x = mid;
this.y = 0;
}
else if(side === 2)
{
this.x = 700;
this.y = mid;
}
else if(side === 3)
{
this.y = 700;
this.x = mid;
}
else
{
this.x = 0;
this.y = mid;
}
var zombies = [];
zombies.push(new Zombie());
this.render = function()
{
context.fillStyle = "rgba(0, 160, 0, 1)"; //green
context.fillRect(this.x, this.y, this.width,this.height);
}
var render = function()
this.move = function()
{
context.fillStyle = "#000000";
context.fillRect(0, 0, width, height);
if(this.x > p.x + this.speed)
this.x -= this.speed;
else if(this.x + this.speed < p.x )
this.x += this.speed;
context.fillStyle = "rgba(255, 255, 255, 1)";
context.font= "20px Georgia";
context.fillText("Score: " + score,10,25);
for(i = 0; i< zombies.length; i++)
{
if(zombies[i] != -1)
{
zombies[i].render();
}
if(this.y > p.y + this.speed)
this.y -= this.speed;
else if(this.y + this.speed < p.y )
this.y += this.speed;
}
}
var zombies = [];
zombies.push(new Zombie());
}
for(i = 0; i< bullets.length; i++)
var render = function()
{
context.fillStyle = "#000000";
context.fillRect(0, 0, width, height);
context.fillStyle = "rgba(255, 255, 255, 1)";
context.font= "20px Georgia";
context.fillText("Score: " + score,10,25);
for(i = 0; i< zombies.length; i++)
{
if(zombies[i] != -1)
{
if(bullets[i] != -1)
{
bullets[i].render();
}
zombies[i].render();
}
}
for(i = 0; i< bullets.length; i++)
{
if(bullets[i] != -1)
{
bullets[i].render();
}
p.render();
}
var update = function()
p.render();
}
var update = function()
{
addZombie();
p.move();
for(i = 0; i< zombies.length; i++)
{
addZombie();
p.move();
for(i = 0; i< zombies.length; i++)
for(z = 0;z < bullets.length; z++)
{
for(z = 0;z < bullets.length; z++)
if(zombies[i] != -1 && bullets[z] != -1)
{
if(zombies[i] != -1 && bullets[z] != -1)
if(Math.abs(zombies[i].x - bullets[z].x) < 25 &&
Math.abs(zombies[i].y - bullets[z].y) < 25)
{
if(Math.abs(zombies[i].x - bullets[z].x) < 25 && Math.abs(zombies[i].y - bullets[z].y) < 25)
{
score++;
zombies[i] = -1;
bullets[z] = -1;
}
score++;
zombies[i] = -1;
bullets[z] = -1;
}
}
if(zombies[i] != -1)
{
zombies[i].move();
}
}
for(i = 0; i< bullets.length; i++)
if(zombies[i] != -1)
{
//checks to see if goes out of bounds
if(bullets[i].x < 0 || bullets[i].y < 0 || bullets[i].x > 700 || bullets[i].y > 700)
{
bullets[i] = -1;
}
zombies[i].move();
}
if(bullets[i] != -1)
{
}
for(i = 0; i< bullets.length; i++)
{
//checks to see if goes out of bounds
if(bullets[i].x < 0 || bullets[i].y < 0 ||
bullets[i].x > 700 || bullets[i].y > 700)
{
bullets[i] = -1;
}
bullets[i].move();
}
if(bullets[i] != -1)
{
bullets[i].move();
}
for(i=0; i<zombies.length; i++)
}
for(i=0; i<zombies.length; i++)
{
if(zombies[i] != -1 &&
Math.abs(p.x - zombies[i].x) < 25 &&
Math.abs(p.y - zombies[i].y) < 25)
{
if(zombies[i] != -1 && Math.abs(p.x - zombies[i].x) < 25 && Math.abs(p.y - zombies[i].y) < 25)
{
dead = true;
}
dead = true;
}
}
var counter2 = 0;
var counter = 0;
var rate = 180;
var addZombie = function()
}
var counter2 = 0;
var counter = 0;
var rate = 180;
var addZombie = function()
{
counter2++;
counter++;
var added = false;
if(counter >= rate)
{
counter2++;
counter++;
var added = false;
if(counter >= rate)
for(i = 0; i< zombies.length; i++)
{
for(i = 0; i< zombies.length; i++)
if(zombies[i] == -1)
{
if(zombies[i] == -1)
{
zombies[i] = new Zombie();
added = true;
break;
}
zombies[i] = new Zombie();
added = true;
break;
}
if(added == false)
{
zombies.push(new Zombie());
}
}
counter = 0;
if(added == false)
{
zombies.push(new Zombie());
}
if(counter2 >= 60)
counter = 0;
}
if(counter2 >= 60)
{
if(rate > 30)
{
if(rate > 30)
{
rate = rate -5;
}
counter2 = 0;
rate = rate -5;
}
counter2 = 0;
}
}
var sent = false;
var sent = false;
var tic = function()
var tic = function()
{
if(dead)
{
if(dead)
{
context.fillStyle = "#000000";
context.fillRect(0, 0, width, height);
context.fillStyle = "#000000";
context.fillRect(0, 0, width, height);
context.fillStyle = "rgba(255, 255, 255, 1)"; //green
context.font= "20px Georgia";
context.fillText("You died with a score of " + score,200,340);
if(!sent)
{
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=2><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();