示例#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
 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;
     }
 }
示例#3
0
文件: dice.php 项目: emiliastk/oophp
<?php

/**
 * 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}
示例#4
0
文件: index.php 项目: bthurvi/oophp
	<h2>Steg 2 - att använda en enkel klass</h2>
	<p>
	<?php 
$sp = new SimpleClass();
$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 
示例#5
0
文件: CDiceImage.php 项目: frsd1/bth
 /**
  * Constructor
  *
  */
 public function __construct()
 {
     parent::__construct(self::FACES);
 }