Привет, я делаю PHP игру, которая работает на терминале. (Текстовая игра) на php.
Когда я вызываю функцию в самом низу кода, я получаю фатальную ошибку. (я пытаюсь получить ввод пользователя и добавить его в переменную, чтобы он мог вызываться функцией BattleStart, и каждый раз он будет иметь атрибуты выбранного персонажа)
Вот код.
<?php
class Combatant{
public $name;
public $health;
public $strength;
public $defence;
public $speed;
public $luck;
function setName($x){
$this -> name = $x;
}
}
class Battle extends Combatant{
function BattleStart($comb1,$comb2){
$damagecomb1 = $comb1 -> strength - $comb2 -> defence;
$damagecomb2 = $comb2 -> strength - $comb1 -> defence;
if ($comb1 -> health > $comb2 -> health){
$comb2 -> health = $comb2 -> health - damagecomb1;
}elseif ($comb2 -> health > $comb1 -> health) {
$comb1 -> health = $comb1 -> health - damagecomb2;
}elseif ($comb1 -> health == $comb2 -> health) {
if ($comb1 -> defence < $comb2 -> defence){
$comb2 -> health = $comb2 -> health - damagecomb1;
}elseif ($comb1 -> defence > $comb2 -> defence) {
$comb1 -> health = $comb1 -> health - damagecomb2;
}
}
for ($rounds <=30; $rounds >=1; $rounds++){
}
}
}
//swordman attributes
$swordman = new Combatant;
$swordman -> setName('swordman');
$swordman -> health = rand(40,60);
$swordman -> strength = rand(60,70);
$swordman -> defence = rand(20,30);
$swordman -> speed = rand(90,100);
$swordman -> luck = rand(0.3, 0.5);
//Brute attributes
$brute = new Combatant;
$brute -> setName('brute');
$brute -> health = rand(90,100);
$brute -> strength = rand(65,75);
$brute -> defence = rand(40,50);
$brute -> speed = rand(60,80);
$brute -> luck = rand(0.3, 0.35);
//Grappler
$grappler = new Combatant;
$grappler -> setName('grappler');
$grappler -> health = rand(60,100);
$grappler -> strength = rand(75,80);
$grappler -> defence = rand(35,40);
$grappler -> speed = rand(60,80);
$grappler -> luck = rand(0.3, 0.4);
echo "Choose your Character: ";
$input ='';
$input = trim(fgets(STDIN,1024));
$comb1;
$comb2;
if ($input == 'sword') {
$comb1 = $swordman;
echo $swordman -> name, ("\n");
echo $swordman -> health, ("\n");
echo $swordman -> strength, ("\n");
echo $swordman -> defence, ("\n");
echo $swordman -> speed, ("\n");
echo $swordman -> luck, ("\n");
}elseif($input =='brute'){
$comb1 = $brute;
echo $brute -> name, ("\n");
echo $brute -> strength, ("\n");
echo $brute -> defence, ("\n");
echo $brute -> speed, ("\n");
echo $brute -> health, ("\n");
echo $brute -> luck, ("\n");
}elseif ($input == 'grappler') {
$comb1 = $grappler;
echo $grappler -> name, ("\n");
echo $grappler -> health, ("\n");
echo $grappler -> strength, ("\n");
echo $grappler -> defence, ("\n");
echo $grappler -> speed, ("\n");
echo $grappler -> luck, ("\n");
}else {
echo 'you didnt type the right thing.. Try again';
}
echo "Choose your Oponent: ";
$input1 ='';
$input1 = trim(fgets(STDIN,1024));
if ($input == 'sword') {
$comb2 = $swordman;
echo $swordman -> name, ("\n");
echo $swordman -> health, ("\n");
echo $swordman -> strength, ("\n");
echo $swordman -> defence, ("\n");
echo $swordman -> speed, ("\n");
echo $swordman -> luck, ("\n");
}elseif($input =='brute'){
$comb2 = $brute;
echo $brute -> name, ("\n");
echo $brute -> strength, ("\n");
echo $brute -> defence, ("\n");
echo $brute -> speed, ("\n");
echo $brute -> health, ("\n");
echo $brute -> luck, ("\n");
}elseif ($input == 'grappler') {
$comb2 = $grappler;
echo $grappler -> name, ("\n");
echo $grappler -> health, ("\n");
echo $grappler -> strength, ("\n");
echo $grappler -> defence, ("\n");
echo $grappler -> speed, ("\n");
echo $grappler -> luck, ("\n");
}else {
echo 'you didnt type the right thing.. Try again';
}
BattleStart($comb1, $comb2);
?>