Merge pull request #4 from gnieark/dev

Dev
pull/9/head
Gnieark 9 years ago
commit 9222b6ff7b

@ -77,13 +77,22 @@ if($currentArena == ""){
<style type="text/css">
@import url(/style.css);
</style>
<?php
//script js de l'arene
if(isset($currentArenaArr['jsFile'])){
echo '<script type="text/javascript"><!--';
echo file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['jsFile']);
echo '--></script>';
}
?>
</head>
<body>
<header>
<h1><?php echo $siteTitle; ?></h1>
<nav id="languages"><a href="-fr">fr</a>&nbsp;<a href="-en">en</a></nav>
<nav id="menus"><a href="/"><?php echo $lang['HOME']; ?></a>
<nav id="menus"><a href="/"<?php if($currentArena == "") echo ' class="selected"'; ?>><?php echo $lang['HOME']; ?></a>
<?php
foreach($arenas as $arena){
if( $arena['id'] == $currentArena){

@ -0,0 +1,48 @@
<?php
function get_Post_Params(){
$keysBots=array('bot1','bot2');
foreach($keysBots as $botKey){
if(!isset($_POST[$botKey])){
return false;
}
if(!is_numeric(($_POST[$botKey]))){
}
if(($_POST[$botKey] < 0) OR ($_POST[$botKey] > count($bots))){
error(400,"wrong parameters");
die;
}
}
return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']);
}
function get_Bots_Array(){
//Recupérer la liste des Bots
$bots=array();
$botsList=explode("\n",file_get_contents(__DIR__."/listOfBots.txt"));
foreach($botsList as $botLigne){
if(preg_match("/\ (http|https):\/\//", $botLigne)){
list($name,$url)=explode(" ",$botLigne);
$bots[]=array("name" => $name, "url" =>$url);
}
}
return $bots;
}
function get_IA_Response($youChar,$iaBaseUrl,$grille){
/*transforme la grille en parametres http GET
* et fait la requete vers $iaBaseUrl
* Retourne la réponse de l'IA
*/
$paramsGrille="";
foreach($grille as $key => $case){
$paramsGrille.="&".$key."=".$case;
}
$url=$iaBaseUrl."?you=".$youChar.$paramsGrille;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return htmlentities($output);
}

@ -0,0 +1,39 @@
function Ajx(){
var request = false;
try {request = new ActiveXObject('Msxml2.XMLHTTP');}
catch (err2) {
try {request = new ActiveXObject('Microsoft.XMLHTTP');}
catch (err3) {
try { request = new XMLHttpRequest();}
catch (err1) {
request = false;
}
}
}
return request;
}
function tictactoe(bot1,bot2,xd_check){
document.getElementById('fightResult').innerHTML = '<p>Please wait...</p>';
var xhr = Ajx();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) {
document.getElementById('fightResult').innerHTML = xhr.responseText;
}
}};
xhr.open("POST", 'index.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + ,xd_check);
}
function refreshBots(){
var xhr = Ajx();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) {
window.location.reload();
}
}};
xhr.open("POST", 'index.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('act=reDownloadBotsList');
}

@ -0,0 +1,3 @@
stupidAI http://morpionmaster.tinad.fr/stupidIa.php
moul http://tictactoe.m.42.am/
Gnieark http://morpionmaster.tinad.fr/gnieark.php

@ -1 +1,45 @@
<h2> tic tac toe </h2>
<?php
require_once(__DIR__."/functions.php");
$bots=get_Bots_Array();
$postParams=get_Post_Params();
if(!$postParams){
$bot1="";
$bot2="";
}else{
$bot1=$postParams['bot1'];
$bot2=$postParams['bot2'];
}
?>
<article>
<h2>Lancer un combat</h2>
<p>
<select name="bot1" id="bot1">
<?php
for($i=0;$i<count($bots);$i++){
if($i==$bot1)
$selected='selected="selected"';
else
$selected='';
echo '<option value="'.$i.'" '.$selected.'>'.$bots[$i]['name'].'</option>';
}
?>
</select>
&nbsp;VS&nbsp;
<select name="bot2" id="bot2">
<?php
for($i=0;$i<count($bots);$i++){
if($i==$bot2)
$selected='selected="selected"';
else
$selected='';
echo '<option value="'.$i.'" '.$selected.'>'.$bots[$i]['name'].'</option>';
}
?>
</select>
</p>
<p><input type="button" value="Fight!" onclick="tictactoe(document.getElementById('bot1').value,document.getElementById('bot2').value);"></p>
</article>
<article id="fightResult"></article>

@ -3,7 +3,8 @@ $arenas=array(
array(
'id' => "tictactoe",
'url' => "/tictactoe",
'title' => "Tic Tac Toe"
'title' => "Tic Tac Toe",
'jsFile'=> "js.js"
),
array(
'id' => "Battleship",

Loading…
Cancel
Save