예제 #1
0
파일: DiceGame.php 프로젝트: amitshahc/Code
    //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) {
예제 #2
0
파일: index.php 프로젝트: henceee/1DV607-1
<?php

require_once 'DiceGame.php';
$g = new DiceGame();
if ($g->Play()) {
    echo "You are a winner";
} else {
    echo "Sorry";
}
예제 #3
0
파일: index.php 프로젝트: abdrmdn/DiceGame
<?php

include 'diceGame.php';
$Game = new DiceGame();
$Game->run();