function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $u =& pfcUserConfig::Instance();
     $nick = $u->nick;
     $ct =& pfcContainer::Instance();
     $text = trim($param);
     // Call parse roll
     require_once dirname(__FILE__) . '/demo27_dice.class.php';
     $dice = new Dice();
     if (!$dice->check($text)) {
         $result = $dice->error_get();
         $cmdp = $p;
         $cmdp["param"] = "Cmd_roll failed: " . $result;
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
     } else {
         $result = $dice->roll();
         $ct->write($recipient, $nick, "send", $result);
     }
 }
        print $this->diceNumber;
    }
}
echo "Dice 1:<br>";
$dice1 = new Dice();
$dice1->setSides(4);
$dice1->roll();
print $dice1->result();
//echo $dice1->roll();
//$dice2 = new Dice();
//echo $dice2->roll();
echo "<br>";
echo "Dice 2:<br>";
$dice2 = new Dice();
$dice2->setSides(300);
$dice2->roll();
print $dice2->result();
var_dump($dice1);
var_dump($dice2);
class Person
{
    //public
    //kan nås av alla alltid - allt möjligt
    //
    //protected
    //kan nås/ändras av saker inuti klassen enbart och dess barn
    //
    //private
    //kan nås enbart denna klass, ej barn
    //public $name;
    protected $age;
Esempio n. 3
0
<?php

class Dice
{
    public $faces = 6;
    public function roll()
    {
        return rand(1, $this->faces);
    }
}
$dice = new Dice();
echo $dice->roll() . "\n";
$dice->faces = 32;
echo $dice->roll() . "\n";
class DiceAlphabetic
{
    public $faces = 6;
    public static $images = ["A", "B", "C", "D", "E", "F"];
    public function roll()
    {
        return self::$images[rand(0, $this->faces - 1)];
    }
}
$dice = new DiceAlphabetic();
echo "\n";
echo $dice->roll() . "\n";
echo $dice->roll() . "\n";
echo print_r(DiceAlphabetic::$images, 1) . "\n";
Esempio n. 4
0
/**
 * Author: Rene Kremer
 * Date: 20.08.15
 * Time: 13:27
 * Version 1.0
 *
 * Description: Main App to roll the dices
 */
include 'templates/template.class.php';
include "dice.class.php";
$template = new Template("templates", "img");
$template->header();
$template->head();
// check if first time or reroll
if (isset($_GET["dice"]) || isset($_GET["numberOfDices"])) {
    $dice = new Dice($_GET["dice"], $_GET["numberOfDices"]);
    $value = $_GET["dice"];
} else {
    if (isset($_POST["dice"]) && isset($_POST["dice"])) {
        $dice = new Dice($_POST["dice"], $_POST["numberOfDices"]);
        $value = $_POST["dice"];
    } else {
        //echo file_get_contents("templates/errorWrongDice.tpl");
        return false;
    }
}
if (!$dice->wrongDice && $template->showDice($value)) {
    $dice->roll();
}
$template->follow();
$template->footer();