Advertisement
Notrew3

Fight.php

May 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  * Description of Fight
  11.  *
  12.  * @author Positivo
  13.  */
  14. class Fight {
  15.  
  16.     private $fighter_1;
  17.     private $fighter_2;
  18.  
  19.     function __construct($fighter_1, $fighter_2) {
  20.         $this->fighter_1 = $fighter_1;
  21.         $this->fighter_2 = $fighter_2;
  22.     }
  23.  
  24.     function calculate() {
  25.         if (rand(0, 100) > $this->fighter_1->getBase_hit_chance()) {
  26.             echo "<big class='redtext'>MISS</big>";
  27.             return 0;
  28.         } else {
  29.             echo "<br><big class='yellowtext'>" . $this->fighter_1->getNickname() . "</big>'s Base Damage is: <big>" . $this->fighter_1->getBase_damage() . "</big>";
  30.             echo "<br><big class='yellowtext'>" . $this->fighter_2->getNickname() . "</big>'s Health Points is: <big>" . $this->fighter_2->getHealth_poits() . "</big>";
  31.             if (rand(0, 100) > $this->fighter_1->getBase_critical_chance()) {
  32.                 $damage = $this->fighter_1->getBase_damage() - (rand(0, $this->fighter_2->getBase_defense()));
  33.             } else {
  34.                 echo "<br><h2>Critical Hit!!!</h2>";
  35.                 $damage = ($this->fighter_1->getBase_damage() * $this->fighter_1->getBase_critical_damage_multiplier()) - (rand(0, $this->fighter_2->getBase_defense()));
  36.             }
  37.             if ($damage < 0) {
  38.                 echo "<br><big class='bluetext'>WEAK!!!</big>";
  39.                 return 0;
  40.             } elseif ($damage == 0) {
  41.                 echo "<br><big class='orangetext'>BLOCK</big>";
  42.                 return 0;
  43.             } else {
  44.                 if (rand(0, 100) <= $this->fighter_2->getBase_dodge_chance()) {
  45.                     echo "<br><big class='bluetext'>DODGE</big>";
  46.                     return 0;
  47.                 } else {
  48.                     echo "<br>Damage dealt to <big>" . $this->fighter_2->getNickname() . "</big>: <big>" . $damage . "</big>";
  49.                     return $damage;
  50.                 }
  51.             }
  52.         }
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement