$this->reverseCoins(); } } public function reverseCoins() { if (count($this->coinContainer) < 0) { return; } foreach ($this->coinContainer as $coin) { if ($coin->isPositive()) { $coin->randomSurface(); } else { $coin->setSurface(true); } $this->statisticsCount(); } } public function statisticsCount() { $count = 0; foreach ($this->coinContainer as $coin) { if ($coin->isPositive()) { $count++; } } var_dump(" 正面占用比例为:" . $count / count($this->coinContainer)); } } $robot = new Robot(); $robot->newCoins(); $robot->reverseCoinsForever();