コード例 #1
0
ファイル: verifytags.php プロジェクト: jadecrow/phpbb3roller
function dotags($tags, $forum, $topic)
{
    global $auth, $db, $user, $config, $template;
    global $phpEx, $phpbb_root_path;
    include_once $phpbb_root_path . 'roller/commands.' . $phpEx;
    include_once $phpbb_root_path . 'roller/utilities.' . $phpEx;
    $results;
    foreach ($tags as $tag) {
        $tag = str_replace(array('{', '}'), '', $tag);
        $tag = explode(" ", $tag);
        switch (strtoupper($tag[0])) {
            case "ROLL":
                // Do attack post
                $results .= roll($tag[1]) . "<br>";
                break;
            case "MULTIROLL":
                if ($tag[2]) {
                    $results .= multiroll($tag[1], $tag[2]) . "<br>";
                } else {
                    $results .= multiroll($tag[1]) . "<br>";
                }
                break;
            default:
                $results .= "<br />The {$tag['0']} command is not recognized. <br />";
                echo $results;
                die;
                // return false;
        }
    }
    post($forum, $topic, $results);
    return $results;
}
コード例 #2
0
function avg($n)
{
    $sum = 0;
    for ($i = 0; $i < $n; $i++) {
        $sum += roll(5);
    }
    echo $sum / $n . "<br />";
}
コード例 #3
0
function sev($n)
{
    $sum = 0;
    $min = 20;
    for ($i = 0; $i < $n; $i++) {
        $t = roll(4);
        if ($min > $t) {
            $min = $t;
        }
        $sum += $t;
    }
    return ($sum - $min) / ($n - 1);
}
コード例 #4
0
ファイル: verifytags.php プロジェクト: jadecrow/phpbb3roller
function roll($dice = 1)
{
    $dice = intval($dice, $again = 10);
    if ($dice < 1) {
        $chancedie = true;
    }
    if ($dice > 50) {
        return "Too many dice at once.";
    }
    $result = "";
    $reroll = 0;
    $successes = 0;
    $rdotorg = true;
    $rollbunch = randnum($dice, 1, 10);
    for ($i = 0; $i < $dice; $i++) {
        $thisgo = $rollbunch[$i];
        if (!is_int($thisgo) or !$rdotorg) {
            $thisgo = mt_rand(1, 10);
            $rdotorg = false;
        }
        if ($thisgo > $again - 1) {
            $reroll++;
        }
        if ($chance and $thisgo > 9) {
            $success++;
        } else {
            if ($thisgo > 7) {
                $successes++;
            }
        }
        $result .= $thisgo . " ";
    }
    if (!$rdotorg) {
        $result = "* " . $result;
    }
    if ($chancedie) {
        return "Chance Roll! " . mt_rand(1, 10) . "*<br>";
    } else {
        if ($reroll < 1) {
            return $result . "// Successes: " . $successes . "<br>";
        } else {
            return $result . "// Successes: " . $successes . "<br> Rerolls: " . roll($reroll);
        }
    }
}
コード例 #5
0
ファイル: test01-dice.php プロジェクト: foolishwang/duck-adv
<?php

defined('BASE') or die('No access');
/* dice rolls test */
$arr = [];
$max = 100000;
for ($i = 0; $i < $max; $i++) {
    $num = roll();
    if (isset($arr[$num])) {
        $arr[$num]++;
    } else {
        $arr[$num] = 1;
    }
}
foreach ($arr as $key => $value) {
    tag('p', $key . ': ' . $value);
}
コード例 #6
0
<?php

/*
 * 3d10-die-roller.php
 * by Duane O'Brien - http://chaoticneutral.net
 * written for IBM DeveloperWorks
 */
/* A really basic function to simulate rolling a simple die with N sides */
function roll($sides)
{
    return mt_rand(1, $sides);
}
/* Next we put in a sloppy bit of form to allow you to pick the number of sides, and roll away */
?>
<form method="post">
Sides : <input type="text" name="sides" value="<?php 
echo @$_POST['sides'];
?>
"/> 
Result : <?php 
echo roll((int) @$_POST['sides']);
?>
 
<input type="submit" value="roll" />
</form>
コード例 #7
0
$female = explode("\n", file_get_contents('names.female.txt'));
$last = explode("\n", file_get_contents('names.last.txt'));
/* Shuffle the name arrays, or you'll get the same results every time */
shuffle($male);
shuffle($female);
shuffle($last);
for ($i = 0; $i <= 10; $i++) {
    echo "<br />Male Name : " . $male[$i] . ' ' . $last[$i] . "<br />\n";
    echo "Female Name : " . $female[$i] . ' ' . $last[$i] . "<br />\n";
    foreach ($rules as $stat => $rule) {
        if (preg_match("/^[0-9]+\$/", $rule)) {
            // This is only a number, and is therefore a static value
            $character[$stat] = $rule;
        } else {
            if (preg_match("/^([0-9]+)d([0-9]+)/", $rule, $matches)) {
                // This is a die roll
                $val = 0;
                for ($n = 0; $n < $matches[1]; $n++) {
                    $val = $val + roll($matches[2]);
                }
                $character[$stat] = $val;
            } else {
                if (preg_match("/^([a-z]+)\\/([0-9]+)\$/", $rule, $matches)) {
                    // This is a derived value of some kind.
                    $character[$stat] = $character[$matches[1]] / $matches[2];
                }
            }
        }
        echo $stat . ' : ' . $character[$stat] . "<br />\n";
    }
}
コード例 #8
0
ファイル: system.php プロジェクト: jechiy/ChenBBS
function touzi()
{
    $a1 = roll();
    $a2 = roll();
    $a3 = roll();
    return $a1 . ',' . $a2 . ',' . $a3;
}
コード例 #9
0
        renderTravelTo();
        break;
    case 2:
        $dest = $_SESSION["destination"];
        tag('h2', 'Traveling to the nearest ' . $dest['name'] . '&hellip;');
        if ($_SESSION["hazards"] > 0) {
            $num = roll() * 10 + roll();
            doHazard($num);
        } else {
            tag('p', 'You reached your destination. You may enter the ' . $dest['name'] . '. ');
            $_SESSION["step"] = 3;
            // in a settlement
            $_SESSION["day"] = 1;
        }
        tag('a href=""', 'Continue');
        break;
    case 3:
        // in a settlement
        $dest = $_SESSION["destination"];
        tag('h2', 'In ' . $dest['name'] . ', day ' . $_SESSION["day"] . '&hellip;');
        // each warrior:
        // do stuff, then:
        $num = roll() * 10 + roll();
        doSettlementEvent($num);
        $_SESSION["day"]++;
        tag('a href=""', 'Continue');
        break;
    default:
        tag('p', 'Error: no rule for step ' . $step);
        debug($_SESSION);
}
コード例 #10
0
ファイル: game.php プロジェクト: 05caniffa/yahtzee
function roll_form()
{
    global $dice, $gv;
    if ($_SESSION['turn_num'] > 0) {
        if ($_SESSION['turn_num'] <= 3) {
            roll();
        }
        show_dice();
    }
    if ($_SESSION['turn_num'] < 3) {
        printf("<input type=\"submit\" value=\"Roll\">\n");
        printf("<input type=\"hidden\" name=\"_roll\" value=\"true\">\n");
    } else {
        if ($_SESSION['has_yahtzee']) {
            $si_arr = $gv->get_score_items();
            $si = $si_arr['yahtzee'];
            if ($si->verify($dice)) {
                printf("Yahtzee bonus! 100 points will automatically be added to the Yahtzee Bonus entry<br>");
                $_SESSION['_bonus'] = true;
            }
        }
        printf("<input type=\"submit\" value=\"Make Selection\">\n");
        printf("<input type=\"hidden\" name=\"_select\" value=\"true\">\n");
    }
}
コード例 #11
0
 * 3d10-damage-calculator.php
 * by Duane O'Brien - http://chaoticneutral.net
 * written for IBM DeveloperWorks
 */
/* A really basic function to simulate rolling a simple die with N sides */
function roll($sides)
{
    return mt_rand(1, $sides);
}
?>

<table border="1">
<tr><td>Weapon Name</td><td>Damage</td><td>Result</td></tr>

<?php 
$weapons = array('littlestick' => array('name' => 'Little Stick', 'roll' => '1d6', 'bonus' => '0'), 'bigstick' => array('name' => 'Big Stick', 'roll' => '1d6', 'bonus' => '4'), 'chainsaw' => array('name' => 'Chainsaw', 'roll' => '2d8', 'bonus' => '0'));
foreach ($weapons as $weapon) {
    list($count, $sides) = explode('d', $weapon['roll']);
    $result = 0;
    for ($i = 0; $i < $count; $i++) {
        $result = $result + roll($sides);
    }
    echo "<tr><td>" . $weapon['name'] . "</td><td>" . $weapon['roll'];
    if ($weapon['bonus'] > 0) {
        echo "+" . $weapon['bonus'];
        $result = $result + $weapon['bonus'];
    }
    echo "</td><td>" . $result . "</td></tr>";
}
?>
</table>