![]() |
Testing outcomes in a dice game - help!
Hello everyone!
I've been coding a dice game and have run into a bit of trouble. My dice game works like this: 1: First the user makes a deposit by clicking an image ($500, $600 etc) 2: The user then makes a bet (of either $100 or $200) 3: The user then makes a prediction on the outcome of the dice roll (1-4, 5-8, 9-12) 4: The user then clicks a button which "rolls" two dice. 5: The total of the two dice detemines whether they win or lose. Eg. If the dice roll total equals 5, and the user predicted an outcome of 5-8, they win. I am stuck on no. 5 - I need to compare the prediction to the dice roll total to see if the user has won or lost. I am hopelessly stuck. I was thinking of somehow making the prediction 1-4 equal 'a' and then the dice rolls 1, 2, 3 and 4 equal to 'a' as well so that I can test to see if they match. 5-8 would be 'b' and 9-12 would be 'c', the rolls of 5, 6, 7 and 8 would equal 'b' etc. But how can I do it? Here's my code for the prediction bit: :
<form name="choice">And the script for my dice roll bit is: :
<script language=JavaScript>Can anyone lend a hand? I'm getting so frustrated! If you want to see my "almost working" prototype for the game click: HERE Thank you! |
I didn't examine your code or look at your page. Have you considered things like,
:
if (roll < 5) |
Thanks for replying. :)
Yeah, that's what I had in mind. But my problem is getting to that stage in the first place. I need to take the dice roll outcome and then test it against the user's prediction. I just need a way to compare my variables "user_choice" and "dice_total". But if my users can choose 1-4, 5-8 and 9-12, how do I let my program know that a dice roll of 7 is equal to the user prediction of 5-8? Am I making sense? Lol :: Pulls at hair :: |
Just expand the comments, that was gonna be YOUR job!
:
if (roll < 5) |
:
if (userChoice == groupA) userWins = true;.. or .. :
userWins = (userChoice == groupA);Sorry for the rather useless post, just a simple comment on semantics... as Dawei mentioned, there's a million ways... |
| All times are GMT -5. The time now is 8:46 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC