Jump to content

php dice roller


skbanta

Recommended Posts

i dont mean it has to be animated, i meant that in when the result is shown it shows a picture of whatever side the dice was rolled for both dice and pictures of what the opponent rolled , like your on one page both players click roll and then another page loads on each's browser displaying pictures of the side of the dice that was rolled with their totals scores under the dice pictures and the winner at the top, is it possible?

Link to comment
https://forums.phpfreaks.com/topic/117851-php-dice-roller/#findComment-606166
Share on other sites

what kinda of functions am i going to need to make that script? ive never used any number generator with php yet, just simpler stuff

 

Oh, ok then. In which case, have a script in PHP that generates the numbers, and use AJAX to display and manipulate the returned values.

 

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

Now playing: Linkin Park & Jay-Z - Numb/Encore

via FoxyTunes

Link to comment
https://forums.phpfreaks.com/topic/117851-php-dice-roller/#findComment-606177
Share on other sites

i have something like this in an ebook at home tho its only the one dice unfortunatly but im sure you could figure out how to make it work with two :P i wount have access to the internet till monday now but if your send me your email via pm i'll gladly send you the book then if that helps?

Link to comment
https://forums.phpfreaks.com/topic/117851-php-dice-roller/#findComment-606185
Share on other sites

<?PHP

/*

Basically have an animate image for a dice being roled or something. This is the basis of the script on what you can build on

*/

if($_POST['submit']){ //if they have pressed the submit button

$player1roll1 = rand(1,6);

$player1roll2 = rand(1,6);

 

$player2roll1 = rand(1,6);

$player2roll2 = rand(1,6);

 

$player1sum = $player1roll1 + $player1roll2;

$player2sum = $player2roll1 + $player2roll2;

 

if($player1sum > $player2sum){

echo "Player 1 won";

}elseif($player2sum > $player1sum){

echo "Player 2 won";

}else{

echo "Draw";

}

echo '<img src="'.$player1roll1.'.jpg" />'; //echo the image for roll 1 of player 1

echo '<img src="'.$player1roll2.'.jpg" />'; //echo the image for roll 2 of player 1

 

echo '<img src="'.$player2roll1.'.jpg" />'; //echo the image for roll 1 of player 2

echo '<img src="'.$player2roll2.'.jpg" />'; //echo the image for roll 2 of player 2

 

}else{

?>

<form method="post">

<input type="submit" name="submit" value="Roll dice" />

</form>

<?PHP } ?>

Link to comment
https://forums.phpfreaks.com/topic/117851-php-dice-roller/#findComment-606261
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.