Skip to content

Commit

Permalink
MAJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne02ptzero committed Apr 13, 2014
1 parent 0330085 commit f686eff
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 14 deletions.
13 changes: 13 additions & 0 deletions deconnexion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
include('includes/config.php');
session_start();
$db = connect();
$db->query('UPDATE users SET online = false WHERE id = '.$_SESSION['id']);
$_SESSION['id'] = null;
$_SESSION['login'] = null;
$_SESSION['mail'] = null;
$_SESSION['pwon'] = null;
$_SESSION['ploose'] = null;
session_destroy();
header('Location: index.php?justdelog');
?>
1 change: 1 addition & 0 deletions includes/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function auth($login, $pass) {
$_SESSION['mail'] = $data['mail'];
$_SESSION['pwon'] = $data['pwon'];
$_SESSION['ploose'] = $data['ploose'];
$db->query('UPDATE users SET online = true WHERE id = '.$data['id']);
return (true);
}
return (false);
Expand Down
8 changes: 7 additions & 1 deletion includes/footer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php include('includes/config.php');
$db = connect();
$query = $db->query("SELECT COUNT(*) FROM users WHERE online = true");
$query = $query->fetch();
?>
<footer>
dat footer
<?php echo "Il y a ".$query[0]." utilisateur(s) en ligne<br />";?>
dat footer, such git <a href="https://github.com/N0ich/attlestar"><i class="icon-github3"></i></a>
</footer>
</body>
</html>
23 changes: 12 additions & 11 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/style/style.css">
<link rel="stylesheet" type="text/css" href="/style/compiled.css">
<link rel="stylesheet" type="text/css" href="/style/icomoon.css">
<link rel="stylesheet" type="text/css" href="/style/nav.css">
<link rel="stylesheet" type="text/css" href="style/style.css">
<link rel="stylesheet" type="text/css" href="style/compiled.css">
<link rel="stylesheet" type="text/css" href="style/icomoon.css">
<link rel="stylesheet" type="text/css" href="style/nav.css">

<script src="/scripts/script.js"></script>
<script src="scripts/script.js"></script>
</head>
<body>
<div class="wrapper">
<header>
<!-- Menu -->
<nav class="menu">
<ul>
<li><a href="/"><i class="icon-home2"></i>Home</a></li>
<li><a href="index.php"><i class="icon-home2"></i>Home</a></li>
<li><a href="ladder.php"><i class="icon-trophy"></i>Ladder</a></li>
<?php
if (!$_SESSION['id']) { ?>
<li><a href="/inscription.php"><i class="icon-rocket"></i>Inscription</a></li>
<li><a href="/connexion.php"><i class="icon-key"></i>Connexion</a></li>
<li><a href="inscription.php"><i class="icon-rocket"></i>Inscription</a></li>
<li><a href="connexion.php"><i class="icon-key"></i>Connexion</a></li>
<?php } else { ?>
<li><a href="/play.php"><i class="icon-pacman"></i>Jouer</a></li>
<li><a href="/profile.php"><i class="icon-user"></i><?php echo $_SESSION['login'] ?></a></li>
<li><a href="/deconnexion.php"><i class="icon-switch"></i>Deconnexion</a></li>
<li><a href="play.php"><i class="icon-pacman"></i>Jouer</a></li>
<li><a href="profile.php?id=<?php echo $_SESSION['id']?>"><i class="icon-user"></i><?php echo $_SESSION['login'] ?></a></li>
<li><a href="deconnexion.php"><i class="icon-switch"></i>Deconnexion</a></li>
<?php } ?>
</ul>
</nav>
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
include('includes/chat.php');
?>
</div>
<script> envoi('2e36f5748d06238ecb29f42458090a4d')</script>
<?php include('includes/footer.php');
38 changes: 38 additions & 0 deletions ladder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
include('includes/config.php');
include('includes/header.php');

echo "<div class='content'><center>";
echo "<table>";
echo "<tr>
<th>Position</th>
<th>Login</th>
<th>Victoires</th>
<th>Defaites</th>
<th>Ratio</th>
</tr>";
$db = connect();
$i = 1;
$query = $db->query('SELECT * FROM `users` ORDER BY (pwon / (pwon + ploose)) DESC');
while ($data = $query->fetch()) {
if ($i == 1) {
$image = "icon-rocket";
} else if ($i == 2) {
$image = "icon-evil";
} else if ($i == 3) {
$image = "icon-fire";
} else {
$image = "icon-thumbs-up";
}
echo "<tr>
<td>$i <i class='".$image."'></i></td>
<td><a href='profile.php?id=".$data['id']."'>".$data['login']."</a></td>
<td style='color: green;'>".$data['pwon']."</td>
<td style='color: red'>".$data['ploose']."</td>
<td>".intval(($data['pwon'] / ($data['pwon'] + $data['ploose']) * 100), 100)."%</td>
</tr>";
$i++;
}
echo "</table></center>";
include('includes/footer.php');
?>
23 changes: 23 additions & 0 deletions php/add_lobby.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include('../includes/config.php');
session_start();
if ($_SESSION['id'] && $_GET['player']) {
if ($_GET['player'] == "2" || $_GET['player'] == "3" || $_GET['player'] == "4") {
$db = connect();
$myquery = "SELECT ".$_GET['player']."player FROM lobby";
$query = $db->query($myquery);
$data = $query->fetch();

if ($data[$_GET['player']."player"]) {
$tab = explode(',', $data[$_GET['player']."player"]);
for ($i = 0; $tab[$i] != $_SESSION['id'] && $i < count($tab); $i++);
if (!$tab[$i]) {
$newparse = $data[$_GET['player']."player"].",".$_SESSION['id'];
$myquery = "UPDATE lobby SET `".$_GET['player']."player` = '".$newparse."'";
$query = $db->query($myquery);
}
} else
$db->query('INSERT INTO lobby('.$_GET['player'].'player) VALUES("'.$_SESSION['id'].'")');
}
}
?>
10 changes: 10 additions & 0 deletions php/wait_players.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
include('../includes/config.php');
$db = connect();
$query = $db->query('SELECT '.$_GET['player'].'player FROM lobby');
$query = $query->fetch();
if (count(explode(',', $query[$_GET['player']."player"])) == $_GET['player'])
echo "ok";
else
echo "Veuillez patienter, ".(count(explode(',', $query[$_GET['player']."player"])) - 1)." joueurs trouves...";
?>
15 changes: 15 additions & 0 deletions play.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
include('includes/header.php');
include('includes/play.php');
?>
<div class="content">
<h1>Jouer!</h1>
<h3>Nombre de joueurs</h3>
<select id="player">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="submit" value="Chercher des adversaires!" onclick="lobby()">
<div id="wait_players"></div>
</div>
37 changes: 37 additions & 0 deletions profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
include('includes/config.php');
include('includes/header.php');
?>
<div class="content">
<?php
$db = connect();
$query = $db->prepare("SELECT * FROM users WHERE id = :id");
$query->execute(array(
'id' => $_GET['id']
));
$data = $query->fetch();
if ($data) {
echo "<h1>".$data['login']."</h1>";
if ($data['online'])
echo "<h3 style='color: green;'>Online</h3>";
else
echo "<h3 style='color: red'>Offline</h3>";
echo "<h4>Ratio de victoire</h4>";
$ratio = intval(($data['pwon'] / ($data['pwon'] + $data['ploose']) * 100), 100);
echo $ratio."% ";
if ($ratio < 10) {
echo "<i class='icon-neutral'></i>";
} else if ($ratio < 50) {
echo "<i class='icon-smiley'></i>";
} else if ($ratio < 70) {
echo "<i class='icon-cool2'></i>";
} else if ($ratio < 90) {
echo "<i class='icon-shocked2'></i>";
} else {
echo "<i class='icon-evil'></i>";
}
} else {
echo "<h1>Profile not found :(</h1>";
}
?>
</div>
23 changes: 23 additions & 0 deletions redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include('includes/config.php');
include('includes/header.php');
?>
<div class="content">
<?php
$db = connect();
$query = $db->query("SELECT ".$_GET['player']."player FROM lobby");
$data = $query->fetch();
$tab = explode(',', $data[$_GET['player']."player"]);
for ($i = 0; $tab[$i] != $_SESSION['id'] && $i < count($tab[$i]); $i++);
if ($tab[$i]) {
echo "<h1>La partie va commencer! Tenez-vous pret!</h1>";
for ($i = 0; $i < count($tab); $i++) {
if ($result)
$result .= "player".($i + 1)."=".$tab[$i]."&";
else
$result = "player".($i + 1)."=".$tab[$i]."&";
}
header('Location: attlestar/index.php?'.$result);
}
?>
</div>
18 changes: 17 additions & 1 deletion scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@ function efface() {
}

function envoi(message) {
result = file('/php/shoutbox.php?message=' + message);
result = file('php/shoutbox.php?message=' + message);
document.getElementById('chat').innerHTML = result;
element = document.getElementById('chat');
element.scrollTop = element.scrollHeight;
setTimeout("envoi('2e36f5748d06238ecb29f42458090a4d')", 5000);
}

function lobby() {
player = document.getElementById('player').value;
file('php/add_lobby.php?player='+player);
wait_players(player);
}

function wait_players(player) {
result = file("php/wait_players.php?player="+player);
if (result == "ok") {
document.getElementById('wait_players').innerHTML = "Match Trouve! Vous allez etre redirige sous peu...<meta http-equiv='refresh' content='2; URL=redirect.php?player=" + player +"'>";
} else {
document.getElementById('wait_players').innerHTML = result;
setTimeout("wait_players(" + player + ")", 2000);
}
}
11 changes: 10 additions & 1 deletion style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ footer {
width: 100%;
margin: 0 auto;
padding: 10px;
font-size: 10px;
font-size: 15px;
bottom:0;
}

Expand Down Expand Up @@ -186,3 +186,12 @@ li {
height: 0px;
background-color: #0A4C95;
}

table {
border-collapse: collapse;
}

table td, th {
border: 3px solid #05242B;
padding: 1em;
}

0 comments on commit f686eff

Please sign in to comment.