Como interagir entre objetos?
Vi uma seria de videos sobre POO e estou tentando fazer alguma coisa para testar meus conhecimentos, percebi que estou com muita dificuldade para criar interação entre objetos...
Fiz essa classe player que cria um player
E uma função bem porca de pvp pra criar 2 players e fazer PVP entre eles
<html>
<head><title>Test POO</title></head>
<body>
<?php
require_once 'player.php';
$j[1] = new Player("Bubble", 4);
$j[2] = new Player("Knurd Yep", 1);
var_dump($j[1]);
echo '<br>';
var_dump($j[2]);
echo '<br>';
echo '<br>';
PvP($j[1], $j[2]);
?>
</body>
</html>
<?php
class Player {
private $name;
private $level;
private $vocation;
public function __construct($n, $v) {
$this->setName($n);
$this->setVocation($v);
$this->setLevel(8);
}
// interação entre players
function getAtk($j) {
$atk = $j->getVocation() * $j->getLevel()
return $atk;
}
function PvP($jA, $jB) {
if(getAtk($jA) > getAtk($jB)) {
echo 'Player' .$jA->getName(). 'matou' .$jB->getName().'!';
}
else {
echo 'Player' .$jB->getName(). 'matou' .$jA->getName().'!';
}
}
// getters e setters padrões
function getName() {
return $this->name;
}
function setName($nome) {
$this->name = $nome;
}
function getLevel() {
return $this->name;
}
function setLevel($l) {
$this->level = $l;
}
function getVocation() {
return $this->vocation;
}
function setVocation($v) {
$this->vocation = $v;
}
}
O que eu to fazendo de errado?Discussão (2)
Carregando comentários...