コード例 #1
0
ファイル: CDiceLogic.php プロジェクト: EmilSjunnesson/rental
 protected function Roll()
 {
     $this->GetSession();
     $dice = new CDice();
     $dice->Roll();
     $roll = $dice->GetRollScore();
     // If the outcome is one reset the round
     if ($roll === 1) {
         $this->dices = array(1);
         $this->sum = 0;
         $this->rounds++;
         $this->ses->SetDiceArray($this->dices);
         $this->ses->SetSum($this->sum);
         $this->ses->SetRounds($this->rounds);
         return 'Kastade: ' . $roll . ', omgången är s**t och alla osparade poäng går förlorade. Kasta igen';
         // Else add the outcome to the rounds score
     } else {
         $this->dices[] = $roll;
         $this->sum += $roll;
         $this->ses->SetDiceArray($this->dices);
         $this->ses->SetSum($this->sum);
         return 'Kastade: ' . $roll;
     }
 }
コード例 #2
0
ファイル: dice.php プロジェクト: emiliastk/oophp
/**
 * This is a Lisa pagecontroller.
 *
 */
// Include the essential config-file which also creates the $lisa variable with its defaults.
include __DIR__ . '/config.php';
// Demonstration of module CDice
$dice = new CDice();
$roll = isset($_GET['roll']) && is_numeric($_GET['roll']) ? $_GET['roll'] : 0;
if ($roll > 100) {
    throw new Exception("To many rolls on the dice. Not allowed.");
}
$html = null;
if ($roll) {
    $dice->Roll($roll);
    $html = "<p>Du gjorde {$roll} kast och fick följande resultat.</p>\n<ul>";
    foreach ($dice->GetResults() as $val) {
        $html .= "\n<li>{$val}</li>";
    }
    $html .= "\n</ul>\n";
    $html .= "<p>Totalt fick du " . $dice->GetTotal() . " poäng på dina kast.</p>";
}
// Do it and store it all in variables in the Lisa container.
$lisa['title'] = "Kasta tärning";
$lisa['main'] = <<<EOD
<h1>Kasta tärning</h1>
<p>Detta är en exempelsida som visar hur Lisa fungerar tillsammans med återanvändbara moduler.</p>
<p>Hur många kast vill du göra, <a href='?roll=1'>1 kast</a>, <a href='?roll=3'>3 kast</a> eller <a href='?roll=6'>6 kast</a>? </p>
{$html}
EOD;