1. Go to this page and download the library: Download granam/dice-rolls library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
granam / dice-rolls example snippets
use Granam\DiceRolls\Templates\Rollers\Roller1d6;
use Granam\DiceRolls\Templates\Rollers\Roller2d6DrdPlus;
$roller1d6 = new Roller1d6();
$rolledValue = $roller1d6->roll();
if ($rolledValue === 6) {
echo 'Hurray! You win!';
} else {
echo 'Try harder';
}
$roller2d6Granam = new Roller2d6DrdPlus();
while (($roll = $roller2d6Granam->roll()) && $roll->getValue() <= 12) {
echo 'Still no bonus :( ...';
}
echo 'There it is! Bonus roll comes, with final value of '
. $roll->getValue() . '
Rolls were quite dramatic, consider by yourself: ';
foreach ($roll->getDiceRolls() as $diceRoll) {
echo 'Rolled number ' . $diceRoll->getRolledNumber() . ', evaluated as value ' . $diceRoll->getValue();
}
use Granam\DiceRolls\Templates\Dices\CustomDice;
use Granam\Integer\IntegerObject;
use Granam\DiceRolls\Templates\Dices\Dices;
use Granam\DiceRolls\Roller;
use Granam\DiceRolls\Templates\Evaluators\OneToOneEvaluator;
use Granam\DiceRolls\Templates\RollOn\NoRollOn;
$dice1d5 = new CustomDice(new IntegerObject(1) /* minimum of the dice */, new IntegerObject(5) /* maximum of the dice */);
$dice1d74 = new CustomDice(new IntegerObject(1) /* minimum of the dice */, new IntegerObject(74) /* maximum of the dice */);
$diceCombo = new Dices([$dice1d5, $dice1d74, $dice1d74, $dice1d74]);
$roller = new Roller(
$diceCombo,
new IntegerObject(1) /* roll with them all just once */,
new OneToOneEvaluator() /* "what you roll is what you get" */,
new NoRollOn() /* no bonus roll at all */,
new NoRollOn() /* no malus roll at all */
);
// here it is!
$roller->roll();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.