botsArena/src/arenas/Battleship/functions.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2015-12-10 20:53:13 +01:00
<?php
function get_Post_Params($botsCount){
$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] > $botsCount)){
error(400,"wrong parameters");
die;
}
}
return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']);
}
2015-12-10 22:40:08 +01:00
function generate_numeric_select($start,$end,$selected,$name,$id){
$out="<select";
if($name !== ""){
2015-12-10 22:41:21 +01:00
$out.=' name="'.$name.'"';
2015-12-10 22:40:08 +01:00
}
if($id !== ""){
2015-12-10 22:41:45 +01:00
$out.=' id="'.$id.'"';
2015-12-10 22:40:08 +01:00
}
$out.=">";
2015-12-10 22:42:16 +01:00
if($selected == -1){
2015-12-10 22:40:08 +01:00
for($i=$start; $i <= $end; $i++ ){
$out.='<option value="'.$i.'">'.$i.'</option>';
}
}else{
for($i=$start; $i < $selected; $i++ ){
$out.='<option value="'.$i.'">'.$i.'</option>';
}
$out.='<option value="'.$selected.'" selected="selected">'.$selected.'</option>';
for($i=$selected + 1; $i <= $end; $i++ ){
$out.='<option value="'.$i.'">'.$i.'</option>';
}
}
return $out."</select>";
2015-12-12 10:25:40 +01:00
}
function get_IA_Response($iaUrl,$postParams){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $iaUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return htmlentities($output);
2015-12-10 22:40:08 +01:00
}