(Addendum)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I guess the .phpsrc is being interpreted as PHP anyhow, so let me 
just include the body of the page, below:

-----------------------

<?php

# (DEBUG) -- foreach ($HTTP_POST_VARS as $key => $value) print ("$key 
=> $value <br>");
# (DEBUG) -- foreach ($HTTP_SERVER_VARS as $key => $value) print 
("$key => $value <br>");
# (DEBUG) -- foreach ($HTTP_ENV_VARS as $key => $value) print ("$key 
=> $value <br>");
print ("<!-- Die Roller for {$HTTP_POST_VARS['roll']} -->");

if (isset($roll)) {
	mt_srand ((double) microtime() * 1000000);  # Seed the random number 
generator
	$x = 0;
	$roll = strtolower($roll);
	if (!(strpos($roll,'d')===false)) {
		$number = substr($roll,0,strpos($roll,'d'));
		if (!$number || $number == 0) $number =1;
		$rest = substr(strstr($roll,'d'),1);
		if (!(strpos($rest,'-')===false)) {
			$highnumber=substr($rest,0,strpos($rest,'-'));
			$rest = strstr($roll,'-');
			if (!(strpos($roll,'k')===false)) { 
				# user has used the "keep" method
				$bonus = substr($rest,0,strpos($rest,'k'));
				$keep = substr(strstr($rest,'k'),1);
			} else {
				$bonus=substr($rest,strpos($rest,'-'));
			}
		} else if (!(strpos($rest,'+')===false)) {
			$highnumber=substr($rest,0,strpos($rest,'+'));
			$rest = strstr($roll,'+');
			if (!(strpos($roll,'k')===false)) { 
				# user has used the "keep" method
				$bonus = substr($rest,0,strpos($rest,'k'));
				$keep = substr(strstr($rest,'k'),1);
			} else {
				$bonus=substr($rest,strpos($rest,'+'));
			}
		} else {
			$bonus = '+0';
			if (!(strpos($roll,'k')===false)) { 
				# user has used the "keep" method
				$highnumber = substr($rest,0,strpos($rest,'k'));
				$keep = substr(strstr($rest,'k'),1);
			} else {
				$highnumber=substr($rest,strpos($rest,'+'));
			}
		} 
		if (!(strpos($roll,'k')===false)) { 
			# user has used the "keep" method
			$keep = trim(substr(strstr($roll,'k'),1));
		}
		if ($keep == null) {
			$keep = $number;
		}
		if ($keep > $number or !is_numeric($keep)) {
			$keep = $number;
			echo ("<b>Invalid value for 'k'</b>. Keeping all dice rolled. <p>");
		}
	} else { 
		print ("Invalid entry. Please use the format: <i>[number]</i>d<i>[number]</i>(+/-
<i>[number]</i>). <br><i>i.e. 3d6+3 or 1d8-1</i><p>");
		$number = 1;
		$highnumber = 6;
		$bonus = '+0';
		$keep = 1;
	}

	print ("number, highnumber, bonus, keep: {$number}, {$highnumber},
{$bonus}, {$keep} <p>");
	echo ("Rolling {$number}d{$highnumber}{$bonus}:<br>\n");
	if ($keep < $number) {
		echo ("Keeping best {$keep} <br>\n");
	}
	echo ("<TABLE BORDER=1>\n\t<TR>\n\t\t<TH>Die #</th>\n\t\t<TH>Value</TH>\n\t</TR>\n");

	$x = 0;
	while (++$x <= $number) {
		$die[$x] = mt_rand(1,$highnumber);
		echo ("\n\t<TR>\n\t\t<td>{$x}</td>\n\t\t<TD>{$die[$x]}</TD>\n\t</tr>\n");

	}
	sort($die);
	$x = trim($keep);
	while ($x++ < $number) {
		array_shift($die);
	}
	$total = array_sum($die) + $bonus;
	echo ("</TABLE>\n\n");
	if ($bonus > 0)	echo ("<B>Bonus:</b> {$bonus} <BR>");
	if ($bonus < 0)	echo ("<B>Penalty:</b> {$bonus} <BR>");
	echo ("<P><FONT SIZE=5><B>Total:</b> {$total}</font>");
} else {
	$number = 3; $highnumber = 6; $keep = 3;
}

?>

<FORM ACTION="" METHOD="POST">
Roll dice:<input type="text" size="30" name="roll" value="<?php 
	echo ($number.'d'.$highnumber); 
	if ($bonus <> 0) echo $bonus;  
	if ($keep != $number) echo "k{$keep}"; 
?>"> <br>
<input type="submit" name="submit" value="Roll">
</form>

Enter the dice as follows: <i>num</i> d <i>num</i> (+/- <i>num</i>) 
(k <i>num</i>) <p> <u>Explanation:</u> The first three parameters 
are self-explanatory, <br> and the fourth number ('k') is an option 
to keep the best (<i>num</i>) rolls.  <br> Obviously k (if it is 
specified) must be less than the total number of dice rolled.<p>
<u>Examples</u>: 4d6 k3  .... 4d10-3 ... 1d8+3 ... 2d20 ... (etc.) <p>




===================================================================
EASY and FREE access to your email anywhere: http://Mailreader.com/
===================================================================



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux