skbanta Posted August 2, 2008 Share Posted August 2, 2008 can someone provide some help on what functions i'd need to code a little game where two people both roll 2 six sided dice and their rolls are added up and whoever has the higher total wins, with graphics for the dice Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 This can't be done in PHP, because PHP can't use animations. You could do it in flash or similar, and return the value of the dice to a PHP script though. ---------------- Now playing: Linkin Park & Jay-Z - Big Pimpin'/Papercut via FoxyTunes Quote Link to comment Share on other sites More sharing options...
pankirk Posted August 2, 2008 Share Posted August 2, 2008 Or you could use javascript and php random number functions to get a random number which will be the result of the dice. or instead of javascript you could make an animated gif dice which will show. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 That's a point, yes. If you had a different animation for each dice outcome, it could be done in AJAX ---------------- Now playing: Linkin Park & Jay-Z - Jigga What/Faint via FoxyTunes Quote Link to comment Share on other sites More sharing options...
skbanta Posted August 2, 2008 Author Share Posted August 2, 2008 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? Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 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 Quote Link to comment Share on other sites More sharing options...
skbanta Posted August 2, 2008 Author Share Posted August 2, 2008 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 Quote Link to comment Share on other sites More sharing options...
xoligy Posted August 2, 2008 Share Posted August 2, 2008 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 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? Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 rand(1,6) ---------------- Now playing: Linkin Park & Jay-Z - Numb/Encore via FoxyTunes Quote Link to comment Share on other sites More sharing options...
xoligy Posted August 2, 2008 Share Posted August 2, 2008 You can do more than that you can display the right image and even have comments like "Snake Eyes!" Quote Link to comment Share on other sites More sharing options...
skbanta Posted August 2, 2008 Author Share Posted August 2, 2008 so how would i do two rand(1,6) for each person? i'd give each die a variable like $die1 and $die2 and then add them, but how would i choose a different random for each one and display the picture according to the number generated? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 2, 2008 Share Posted August 2, 2008 $dice1 = rand(0, 6); $dice2 = rand(0, 6); for each roll... Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 $dice1 = rand(0, 6); $dice2 = rand(0, 6); for each roll... rand(1,6). rand(0,6) returns 7 values. There are only 6 ---------------- Now playing: Dance Gavin Dance - Strawberry André via FoxyTunes Quote Link to comment Share on other sites More sharing options...
Adam Posted August 2, 2008 Share Posted August 2, 2008 or for 2 rolls for each user.. $user1dice1 = rand(0, 6); $user1dice2 = rand(0, 6); $user2dice1 = rand(0, 6); $user2dice2 = rand(0, 6); Quote Link to comment Share on other sites More sharing options...
Adam Posted August 2, 2008 Share Posted August 2, 2008 yeah sorry.. rand(1, 6); Quote Link to comment Share on other sites More sharing options...
PHPTOM Posted August 2, 2008 Share Posted August 2, 2008 <?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 } ?> Quote Link to comment Share on other sites More sharing options...
skbanta Posted August 2, 2008 Author Share Posted August 2, 2008 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? Quote Link to comment Share on other sites More sharing options...
PHPTOM Posted August 3, 2008 Share Posted August 3, 2008 Yeah. When they login, you would check them against a database table, then if successfull set a cookie or a session. If you need help in that area, create a new topic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.