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">
<P><B>Pick your outcome:</B></P>
<input type="button" name="outcome1" value="1-4" onmousedown="no_choice()" onclick="user_choice = 1, document.chosen.userchoice.value='1-4', pick()">
<input type="button" name="outcome2" value="5-8" onmousedown="no_choice()" onclick="user_choice = 2, document.chosen.userchoice.value='5-8', pick()">
<input type="button" name="outcome3" value="9-12" onmousedown="no_choice()" onclick="user_choice = 3, document.chosen.userchoice.value='9-12', pick()">
</form>
<form name="chosen">
<input type="text" name="userchoice" value="" size="4">
</form>
<script language="Javascript">
var user_choice = 0
function pick(form) {
if (user_choice == 1) {
alert("You have chosen 1-4") }
else {
if (user_choice == 2) {
alert("You have chosen 5-8") }
else {
if (user_choice == 3) {
alert("You have chosen 9-12") }
}}}
</script>
And the script for my dice roll bit is:
<script language=Javascript>
function dice_roll() {
var randice = new Array
randice[0] = "images/1.gif"
randice[1] = "images/2.gif"
randice[2] = "images/3.gif"
randice[3] = "images/4.gif"
randice[4] = "images/5.gif"
randice[5] = "images/6.gif"
var ranimage=Math.round(Math.random()*5)
var ranimage2=Math.round(Math.random()*5)
document.randoimage2.src=randice[ranimage2]
document.randoimage1.src=randice[ranimage]
var dice_total = (Number(ranimage) + Number(ranimage2) + 2);
alert("Your roll = " + dice_total);
}
</script>
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!
This post has been edited by Elvellon: 28 November 2005 - 07:12 AM

New Topic/Question
Reply



MultiQuote



|