I know this is a widely asked question, but I cannot, for the love of me find the answer. I have a method that I am calling in another class, but I get the Fatal Error: Uncaught Error: Call to undefined function bla bla. Can anyone help me with this? Thanks in advance, and here is the code, the error is in the last method, on the while(alliesDefend >= 0)
<?php
class Duel{
public $_maxHealth;
public $_currentHealth = 0;
public $_specialAttack, $_mainAttack;
public $_specialChance, $deflectChance;
public $startHealth;
public $size1 , $size2;
function __construct($_size1, $_size2)
{
$this->size1 = $_size1;
$this->size2 = $_size2;
}
function baseNumberOne()
{
$baseNumber = rand(1, 2) * $this->size1;
return $baseNumber;
}
function baseNumberTwo()
{
$baseNumberTwo = rand(1, 2) * $this->size2;
return $baseNumberTwo;
}
function specialAttack(){
$_specialChance = rand(0, 20);
$_specialAttack = 0;
if ($_specialChance < 10) {
$_specialAttack = 0;
} elseif ($_specialChance < 15) {
$_specialAttack = (int) rand(0, 5);
} elseif ($_specialChance <= 20) {
$_specialAttack = (int) rand(5, 10);
}
return $_specialAttack;
}
function enemyAttack()
{
$_mainAttackOne = $this->specialAttack() + $this->baseNumberOne();
echo "The Enemy has attacked allied forces for $_mainAttackOne damage! <br/>";
return $_mainAttackOne;
}
function alliesAttack()
{
$_mainAttackTwo = $this->specialAttack() + $this->baseNumberTwo();
echo "The allies have attacked enemy forces for $_mainAttackTwo damage! <br/>";
return $_mainAttackTwo;
}
function startHealth()
{
$startHealth = (int) (10 * $this->baseNumberOne());
return $startHealth;
}
function startEnemyHealth()
{
$startEnemyHealth = (int) (10 * $this->baseNumberTwo());
return $startEnemyHealth;
}
function deflect(){
$deflectChance = rand(1, 10);
$deflect = 0;
if ($deflectChance < 5) {
$deflect = 0;
echo 'attack cannot be deflected<br/>';
} elseif ($deflectChance > 5) {
$deflect = (int) rand(0, 3);
echo "attack is deflected for {$deflect} damage <br/>";
}
return $deflect;
}
function enemyDefend()
{
$_currentHealth = $this->startHealth();
$_currentHealth = $_currentHealth + $this->deflect() - $this->alliesAttack();
echo "Enemies have has dropped to $_currentHealth HP <br/>";
return $_currentHealth;
}
public function alliesDefend()
{
$_currentHealth = $this->startEnemyHealth();
$_currentHealth = $_currentHealth + $this->deflect() - $this->EnemyAttack();
echo "Allies have has dropped to $_currentHealth HP <br/>";
return $_currentHealth;
}
function war(){
do{
$this->enemyAttack();
$this->alliesDefend();
$this->alliesAttack();
$this->enemyDefend();
}while(alliesDefend() >= 0);
}
} //end of class
Aucun commentaire:
Enregistrer un commentaire