#native_company# #native_desc#
#native_cta#

Virtual Virtual Dice

By Hkon Brten
on April 17, 2008

Version: 1.2

Type: Full Script

Category: Games

License: Other

Description: Virtual Virtual Dice
–Its just like playing virtual dice
This is a game of craps:
conditions for win:

Roll:1 must roll 7 or 11;
if not roll until roll[i]==roll[1]

lose if 7 or ll is rolled when i > 1 or if 2 is rolled on any roll

**COMMENT FROM CODE**

This program was written by Leonard Burton and is released under unrestricted terms. If you include this in a commercial program please send me an email and alert me to that fact and such notification shall constitute your payment for using this program

Email: [email protected]
URL: http://www.discountsexpress.com/PHPFJ
Site Name: PHP Function Junction

<?php
/*
This program was written by Leonard Burton and is released under unrestricted terms.  If you include this in a commercial program please send me an email and alert me to that fact and such notification shall constitute your payment for using this program

		Email:  [email protected]
		URL:	http://www.discountsexpress.com/PHPFJ
		Site Name: PHP Function Junction
*/ 


//Guarantee Clear roll Count
$toss =0;
$dice = array();
$win = "";

function throw_dice($dice, $toss)
{

	//Get dice info
	$dice[$toss][0] = rand(1,6);
	$dice[$toss][1] = rand(1,6);
	$dice[$toss][2] = $dice[$toss][0] + $dice[$toss][1];

	//get odds
	switch ($dice[$toss][2])
	{
		case 2:
			$odds="1 out of 6";
			break;

		case 12:
			$odds="1 out of 6";
			break;

		case 3:
			$odds="2 out of 6";
			break;

		case 11:
			$odds="2 out of 6";
			break;

		case 4:
			$odds="3 out of 6";
			break;

		case 10:
			$odds="3 out of 6";
			break;

		case 5:
			$odds="4 out of 6";
			break;

		case 9:
			$odds="4 out of 6";
			break;

		case 6:
			$odds="5 out of 6";
			break;

		case 8:
			$odds="5 out of 6";
			break;

		case 7:
			$odds="6 out of 6";
			break;

	}
	$dice[$toss][3]=$odds;


	return $dice;
}

function win_or_loose($dice, $toss)
{
	$win = "";
	$toss1 = $toss - 1;

	if ($dice[0][2]==7  or $dice[0][2]==11)
	{
		$win="win";
	}
	elseif ($dice[$toss][2]==2)
	{
		$win="snake eyes";
	}
	elseif ($toss > 0)
	{
		if ($dice[$toss][2]==7 or $dice[$toss][2]==11)
		{
			$win="loss";
		}
		elseif ($dice[$toss][2] == $dice[0][2])
		{
			$win="win";
		}
		else
		{
			$win="retoss";
		}

	}
	return $win;
}

//Play Button
print "<form action=dice.php method=post>n";
print "Want to Play <b>Virtual Virtual Dice</b> with me? <br>Its just
like playing virtual dice<br><br><br>n";
print "<input type=submit name=play value=go>n";


//Start Game
if (!empty($_POST["play"]))
{
	$play = $_POST["play"];
	
	if ($play=="go")
	{
		print "<table border=1 align=1><tr><td colspan=5 align=center><font 
				color=blue><h1>Throws</h1></font></td></tr>n";
		print "<tr><td>Toss #</td><td>Dice 1</td><td>Dice 
				2</td><td>total</td><td>Odds</td></tr>n";
		do
		{
			$dice = throw_dice($dice, $toss);
			$toss1 = $toss + 1;
			print 	"<tr><td>".$toss1."</td><td>".$dice[$toss][0]."</td><td>" 								
					.$dice[$toss][1]."</td><td>".$dice[$toss][2]."</td><td>".$dice[$toss][3]. "</tr>n";
			$win = win_or_loose($dice, $toss);
			
			if ($win == "win")
			{
				print "<tr><td colspan=5><font color=red><h1>WINNER</h1></font></td></tr>";
				print "</table>";
				break;
			}
			elseif ($win == "snake eyes")
			{
				print "<tr><td colspan=5><h1>Snake Eyes Turkey</h1></td></tr></table>";
				break;
			}
			elseif ($win == "loss")
			{
				print "<tr><td colspan=5><h1>Loss</h1></td></tr></table>";
				break;
			}
			$toss ++;
		}	while ($win != "win");
	}
}
else
{
	echo "You failed!";
}
?>