Example #1
0
 /**
  * Init the dice
  *
  */
 public function Roll()
 {
     if (isset($_SESSION['hand2'])) {
         $hand2 = $_SESSION['hand2'];
         $hand2->Roll();
         $_SESSION['hand2'] = $hand2;
     } else {
         $hand2 = new CDiceHand(1);
         $hand2->Roll();
         $_SESSION['hand2'] = $hand2;
     }
 }
Example #2
0
 public function View()
 {
     if (isset($_SESSION['dicehand'])) {
         $hand = $_SESSION['dicehand'];
     } else {
         $hand = new CDiceHand(1);
         $_SESSION['dicehand'] = $hand;
     }
     // Get the arguments from the query string
     $roll = isset($_GET['roll']) ? true : false;
     $init = isset($_GET['init']) ? true : false;
     $save = isset($_GET['save']) ? true : false;
     $destroy = isset($_GET['destroy']) ? true : false;
     /** Roll the dice **/
     if ($roll) {
         $hand->Roll();
     } else {
         if ($init) {
             $hand->initRound();
         } else {
             if ($save) {
                 $hand->saveRound();
             } else {
                 if ($destroy) {
                     if (isset($_GET['destroy'])) {
                         // Unset all of the session variables.
                         $_SESSION = array();
                     }
                     // Finally, destroy the session.
                     session_destroy();
                     echo " Sessionen raderas, <a href='?'>klicka här för att spela igen</a>";
                     exit;
                 }
             }
         }
     }
     $html = '<div>';
     // Display game points for player
     if ($roll or $save) {
         $html .= $hand->infoWinner();
         $html .= $hand->GetRollsAsImageList();
         $html .= "<p>Poäng denna runda: " . $hand->GetRoundtotal() . "</p>";
         $html .= $hand->infoLose();
         $html .= "<p>Dina sparade poäng: " . $hand->GetTotalScore() . "</p></div>";
     } else {
         $html .= $hand->GetRollsAsImageList();
         $html .= "<p>Kasta tärningen för att börja spela!</p></div>";
     }
     return $html;
 }
Example #3
0
 /**
  * Init the dice
  *
  */
 public function Roll()
 {
     if (isset($_SESSION['hand2'])) {
         $hand2 = $_SESSION['hand2'];
         $hand2->Roll();
         $_SESSION['hand2'] = $hand2;
     } else {
         $hand2 = new CDiceHand(1);
         $hand2->Roll();
         $_SESSION['hand2'] = $hand2;
     }
     if (isset($_SESSION['rollOFdice'])) {
         $_SESSION['rollOFdice'] += $this->{$rollOFdice}++;
     }
 }
Example #4
0
File: dice.php Project: frsd1/bth
<button type="button" class="b" onclick="location.href='dice.php?roll'">hello</button>

<p><a href='?destroy'>Förstör sessionen</a>.</p>

<?php 
// Get the arguments from the query string
$roll = isset($_GET['roll']) ? true : false;
$test = isset($_GET['test']) ? true : false;
$init = isset($_GET['init']) ? true : false;
// Create the object or get it from the session
if (isset($_SESSION['dicehand'])) {
    echo "<i>Objektet finns redan i sessionen</i>";
    $hand = $_SESSION['dicehand'];
} else {
    echo "<i>Objektet finns inte i sessionen, skapar nytt objekt och lagrar det i sessionen</i>";
    $hand = new CDiceHand(1);
    $_SESSION['dicehand'] = $hand;
}
// Roll the dices
if ($test) {
    $hand->InitRound();
    $hand->Roll();
}
// Roll the dices
if ($roll) {
    $hand->Roll();
} else {
    if ($init) {
        $hand->InitRound();
    }
}