2017 © Pedro PelĂĄez
 

project dice-rolls

Configurable roll of a dice

image

drd-plus/dice-rolls

Configurable roll of a dice

  • Tuesday, July 17, 2018
  • by jaroslavtyc
  • Repository
  • 1 Watchers
  • 0 Stars
  • 637 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 44 % Grown

The README.md

Build Status Test Coverage License, (*1)

Let's roll!, (*2)

Custom dices & rolls, (*3)

Install, (*4)

Let's roll!

<?php
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(); 
}

There are plenty of predefined templates of dices and rolls as 1d4, 1d6, 1d10. You can mix those and any else you create by CustomDice class., (*5)

Just think about your needs and check templates. Your requirements may be already satisfied by them., (*6)

Custom dices & rolls

There can be situations, where you need crazy combinations. Let's say one roll with 1d5 dice and three rolls with 1d74 dice., (*7)

It is easy. The hard part is only to find the way:, (*8)

<?php
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();

Install

composer require drd/dice-roll

The Versions

17/07 2018

dev-master

9999999-dev https://github.com/jaroslavtyc/drd-plus-dice-rolls

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

17/07 2018
17/07 2018

4.1.x-dev

4.1.9999999.9999999-dev https://github.com/jaroslavtyc/drd-plus-dice-rolls

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

19/02 2017

4.0.x-dev

4.0.9999999.9999999-dev https://github.com/jaroslavtyc/drd-dice-rolls

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

19/02 2017
03/03 2016

3.0.0

3.0.0.0 https://github.com/jaroslavtyc/drd-dice-roll

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

04/11 2015

2.0.0

2.0.0.0 https://github.com/jaroslavtyc/drd-dice-roll

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

04/08 2015

1.0.2

1.0.2.0 https://github.com/jaroslavtyc/drd-dice-roll

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

10/05 2015

1.0.1

1.0.1.0 https://github.com/jaroslavtyc/drd-dice-roll

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d

06/05 2015

1.0.0

1.0.0.0 https://github.com/jaroslavtyc/drd-dice-roll

Configurable roll of a dice

  Sources   Download

MIT

The Requires

 

The Development Requires

php configurable dice drd plus roll drd dungeon and dragons drd 2 d and d