これは私が何かを忘れてしまったようで、今この小さな事を固執したようです。複数のインスタンスで関数を使用できるようにするにはどうすればよいですか?例えばplayer1、player2、
2つのチームで試合の間に複数のプレーヤーがあります。すべてのプレーヤーを処理するために、この関数を書く必要がありますか?
Match.php
public function __construct()
{
$this->redTeam = new Team();
$this->blueTeam = new Team();
$this->player1 = new Player('Bensen');
$this->player2 = new Player('Kicksen');
$this->startMatch();
}
public function fightCreeps()
{
$creeps = 0;
$gold = 0;
for ($this->wave; $this->wave > 0; $this->wave--) {
if ($this->player1->lasthitting >= rand(1, 100)) {
$creeps++;
$gold += 40;
$this->player1->creeps++;
$this->player1->gold += 40;
$this->player1->totalGold += 40;
$this->player1->experience += 40;
$this->player1->health -= rand(5, 10);
}
}
return "<span style=\"color: red;\">{$this->player1->name}</span> has slain {$creeps} Creeps. +{$gold} Gold<br>";
}
ヒント:あなたがしたい場合は、手動で、それを介して収集自分自身と、ループを作成することができますので、のような 'パブリック関数fightCreeps()' => 'パブリック関数fightCreepsを(プレーヤー$プレーヤー) ' – HPierce