Bonjour à tous
je développe un calculateur de points pour un jeu, et je recontre un problème avec les conditions "if" / "else" imbriquées
jusque-là tout fonctionne, sauf si l'adversaire a plus de points que le joueur au départ... ce qui correspond aux "else" dans le code
je vois vraiment pas où se trouve le problème par contre (il doit bien y en avoir un pourtant )
je développe un calculateur de points pour un jeu, et je recontre un problème avec les conditions "if" / "else" imbriquées
- Code:
<form method="POST">
<p><label>Vos points : <input type="text" name="startPoint" /></label></p>
<p><label>Points adversaire : <input type="text" name="enemyPoint" /></label></p>
<p><label>Victoire :
<input type="radio" name="victoire" value="oui" checked="checked" /> <label for="oui">Oui</label>
<input type="radio" name="victoire" value="non" /> <label for="non">Non</label></p>
<p><label>Coefficient :
<input type="radio" name="coef" value="0.5" /> <label for="0.5">0.5</label>
<input type="radio" name="coef" value="0.75" /> <label for="0.5">0.75</label>
<input type="radio" name="coef" value="1" checked="checked" /> <label for="0.5">1</label>
<input type="radio" name="coef" value="1.25" /> <label for="0.5">1.25</label>
<input type="radio" name="coef" value="1.50" /> <label for="0.5">1.50</label>
</p>
<p><input type="submit" value="Calculer" /></p>
</form>
<?php
$victoire = $_POST['victoire'];
$startPoint = $_POST['startPoint'];
$enemyPoint = $_POST['enemyPoint'];
$diff = $startPoint - $enemyPoint;
if ($victoire == "oui") {
if ($diff >= 0 && $diff <= 24) {
if ($startPoint >= $enemyPoint) {$gain = 6;}
else {$gain = 6;}
}
if ($diff >= 25 && $diff <= 49) {
if ($startPoint >= $enemyPoint) {$gain = 5.5;}
else {$gain = 7;}
}
if ($diff >= 50 && $diff <= 99) {
if ($startPoint >= $enemyPoint) {$gain = 5;}
else {$gain = 8;}
}
if ($diff >= 100 && $diff <= 149) {
if ($startPoint >= $enemyPoint) {$gain = 4;}
else {$gain = 10;}
}
if ($diff >= 150 && $diff <= 199) {
if ($startPoint >= $enemyPoint) {$gain = 3;}
else {$gain = 13;}
}
if ($diff >= 200 && $diff <= 299) {
if ($startPoint >= $enemyPoint) {$gain = 2;}
else {$gain = 17;}
}
if ($diff >= 300 && $diff <= 399) {
if ($startPoint >= $enemyPoint) {$gain = 1;}
else {$gain = 22;}
}
if ($diff >= 400 && $diff <= 499) {
if ($startPoint >= $enemyPoint) {$gain = 0.5;}
else {$gain = 28;}
}
if ($diff >= 500) {
if ($startPoint >= $enemyPoint) {$gain = 0;}
else {$gain = 40;}
}
}
elseif ($victoire == "non") {
if ($diff >= 0 && $diff <= 24) {
if ($startPoint <= $enemyPoint) {$gain = -5;}
else {$gain = -5;}
}
if ($diff >= 25 && $diff <= 49) {
if ($startPoint <= $enemyPoint) {$gain = -4.5;}
else {$gain = -6;}
}
if ($diff >= 50 && $diff <= 99) {
if ($startPoint <= $enemyPoint) {$gain = -4;}
else {$gain = -7;}
}
if ($diff >= 100 && $diff <= 149) {
if ($startPoint <= $enemyPoint) {$gain = -3;}
else {$gain = -8;}
}
if ($diff >= 150 && $diff <= 199) {
if ($startPoint <= $enemyPoint) {$gain = -2;}
else {$gain = -10;}
}
if ($diff >= 200 && $diff <= 299) {
if ($startPoint <= $enemyPoint) {$gain = -1;}
else {$gain = -12.5;}
}
if ($diff >= 300 && $diff <= 399) {
if ($startPoint <= $enemyPoint) {$gain = -0.5;}
else {$gain = -16;}
}
if ($diff >= 400 && $diff <= 499) {
if ($startPoint <= $enemyPoint) {$gain = 0;}
else {$gain = -20;}
}
if ($diff >= 500) {
if ($startPoint <= $enemyPoint) {$gain = 0;}
else {$gain = -29;}
}
}
$coef = $_POST['coef'];
$endPoint = $startPoint + ($gain * $coef);
?>
<table>
<tr>
<td>Points adversaire</td>
<td>Victoire / défaite</td>
<td>Gain</td>
<td>Coef.</td>
<td>Résultat</td>
</tr>
<tr>
<td><?php echo $_POST['enemyPoint'] ?></td>
<td><?php echo $_POST['victoire'] ?></td>
<td><?php echo $gain ?></td>
<td><?php echo $coef ?></td>
<td><?php echo $endPoint ?></td>
</tr>
</table>
jusque-là tout fonctionne, sauf si l'adversaire a plus de points que le joueur au départ... ce qui correspond aux "else" dans le code
je vois vraiment pas où se trouve le problème par contre (il doit bien y en avoir un pourtant )