//Check if any player got emptied public function isAnyPlayerEmptied() { foreach ($this->arrPlayers as $player) { $cntDice = $this->{$player}->getCurrentDiceCount(); if ($cntDice === 0) { return TRUE; } } return FALSE; } } //Run the code: try { $intDice = 6; $objDiceGame = new DiceGame($intDice); $cntRound = 0; do { $cntRound++; echo "Round " . $cntRound . "<br /><br />\r\n"; $objDiceGame->rollDice(); echo "After dice rolled:<br />\r\n"; $objDiceGame->printStatus(); $objDiceGame->exchangeDice($diceToShift = 1, $diceToRemove = 6); echo "<br />After dice moved/removed:<br />\r\n"; $objDiceGame->printStatus(); echo "<br /><br />"; $isWinnerFound = $objDiceGame->isAnyPlayerEmptied(); } while ($isWinnerFound === FALSE); echo "Winner Found<br /><br />\r\n"; } catch (Exception $e) {
<?php require_once 'DiceGame.php'; $g = new DiceGame(); if ($g->Play()) { echo "You are a winner"; } else { echo "Sorry"; }
<?php include 'diceGame.php'; $Game = new DiceGame(); $Game->run();