Answer the question
In order to leave comments, you need to log in
Damage system on php loop, not always a win, why?
$mobxp = rand(2,5);//хп моба
$mobyr = 1;//урон
//------------------------
$pitxp = 9;//хп питомца
$pityr = 1;//урон
//------------------------
$vsego = $mobxp;
//------------------------
$sdelanudar = 0;
$x=0;
while ($x <= $vsego)
{
if($sdelanudar == 0) {
if($mobxp == 0){//Если хп нет победил
$sdelanudar = 1;
//$x = $vsego;
break;
} else {
$mobxp - $pityr;//Ударяет монстра
$sdelanudar = 1;
}
} else if($sdelanudar == 1) {
if($pitxp == 0){//Если хп нет проиграл
$sdelanudar = 0;
//$x = $vsego;
break;
} else {
$pitxp - $mobyr;//Ударяет питомца
$sdelanudar = 0;
}
}
$x++; // Увеличение счетчика
//echo $x;
}
if($sdelanudar == 0) {//не смог
exit;
} else if($sdelanudar == 1) {//победил
exit;
}
Answer the question
In order to leave comments, you need to log in
In general, it is strange that something works for you if you do not even assign variables. Instead of:
Needed:
Same story for the pet. And generally use normal names and OOP. So, advice for the future that will probably be ignored.
$mobxp - $pityr;//Ударяет монстра
$mobxp -= $pityr;//Ударяет монстра
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question