B
B
Bicbai2020-04-30 07:56:48
PHP
Bicbai, 2020-04-30 07:56:48

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;
          }

What's wrong with my loops, why when $pitxp has a higher number, it's a defeat. How to make everything work smoothly. It's weird when a monster has 2 health and you lose with your 9 health. Now it does not always give out a victory, I can not understand why (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-04-30
@rpsv

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 question

Ask a Question

731 491 924 answers to any question