if (isset($_POST['numeroscelto']) && isset($_POST['tipogiocatore']) && isset($_POST['userSfidante']) && isset($_POST['userSfidato'])) {
    $azione = 'Caricamento';
    $num = htmlspecialchars($_POST['numeroscelto']);
    $tipogiocatore = htmlspecialchars($_POST['tipogiocatore']);
    $usernameSfidante = htmlspecialchars($_POST['userSfidante']);
    $usernameSfidato = htmlspecialchars($_POST['userSfidato']);
    $Services = new Services();
    $res = $Services->setNumber($num, $tipogiocatore, $usernameSfidante, $usernameSfidato);
}
// GIOCA
if (isset($_POST['Sfidante']) && isset($_POST['Sfidato']) && isset($_POST['tipogiocatore']) && isset($_POST['numero'])) {
    $azione = 'Risultato';
    $usernameSfidante = htmlspecialchars($_POST['Sfidante']);
    $usernameSfidato = htmlspecialchars($_POST['Sfidato']);
    $tipogiocatore = htmlspecialchars($_POST['tipogiocatore']);
    $num = htmlspecialchars($_POST['numero']);
    $service = new Services();
    $res = $service->game($usernameSfidante, $usernameSfidato, $tipogiocatore, $num);
}
// RECUPERARE TENTATIVI
if (isset($_POST['tipoplayer']) && isset($_POST['uSfidante']) && isset($_POST['uSfidato'])) {
    $azione = "Tentativi";
    $tipogiocatore = htmlspecialchars($_POST['tipoplayer']);
    $usernameSfidante = htmlspecialchars($_POST['uSfidante']);
    $usernameSfidato = htmlspecialchars($_POST['uSfidato']);
    $service = new Services();
    $res = $service->useGetTentativi($tipogiocatore, $usernameSfidante, $usernameSfidato);
}
$json = array($azione => $res);
header('Content-type: application/json');
echo json_encode($json);