tictactoe public

This commit is contained in:
Gnieark 2015-11-28 14:26:11 +01:00
parent 7b50124f62
commit 37fcc72e56
2 changed files with 60 additions and 3 deletions

View File

@ -1,5 +1,22 @@
<?php
function getBotsArray(){
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"));
@ -12,7 +29,7 @@ function getBotsArray(){
}
return $bots;
}
function getIAResponse($youChar,$iaBaseUrl,$grille){
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

View File

@ -2,4 +2,44 @@
require_once(__DIR__."/functions.php");
$bots=getBotsArray();
print_r($bots);
$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>