示例#1
0
文件: DiceGame.php 项目: frsd1/bth
 public function ThrowDice()
 {
     $dice = new CDice();
     $this->current_throw = $dice->RollDice(1);
     /* Check if its = 1 */
     if ($this->current_throw == 1) {
         $this->current_score = 0;
         $_SESSION['score'] = 0;
     } else {
         $this->SaveScore();
     }
     $output = "<p class='dicethrow'>Ditt kast blev: " . $this->current_throw . "</p>\n";
     /* Draw dice */
     $output .= "<div class='dice" . $this->current_throw . "'></div>\n";
     $output .= $this->GameRound();
     return $output;
 }
示例#2
0
文件: index.php 项目: bthurvi/oophp
$sp->DisplayVar();
$sp->var = "a new value";
echo "<p>";
$sp->DisplayVar();
?>
	</article>

	<article>
	<h2>Steg 3 - en tärningsklass</h2>
	<p>Simulera tärningsslag genom att ange ett värde för GET-parametern <strong>rolls</strong>
	<?php 
$d = new CDice();
if (isset($_GET['rolls'])) {
    $n = (int) filter_input(INPUT_GET, 'rolls');
    echo "<p>Slår tärningen {$n} gånger";
    $d->RollDice($n);
    echo '<p> Resultat:' . $d->GetRolls();
    echo '<p> Summa: ' . $d->GetSum();
    echo '<p> Medelvärde: ' . $d->GetAverage();
}
?>
	</article>

	<article>
	<h2>Steg 4 - klasser i separata filer</h2>
	<p>Frekvensdiagram över den senaste omgången tärningsslag:
	<?php 
$hist = new CHistogram();
$freq = $hist->GetHistogram($d->results);
foreach ($freq as $key => $value) {
    echo "<br />{$key} : {$value}";