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
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
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
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
Share on other sites

that helped a lot, pretty easy to understand, i just one more question though, for the Player 1 Wins or Player 2 Wins, if i wanted to use the players names (signed in usernames), would it just be getting username info from their cookies set at sign in?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.