If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

[RESOLVED] Javascript logic question

Hi,

I created a dice game using the code below. I would like to build on it, to build a craps game, asking for help on the programming logic either using if else, or switch statements. The dice can roll random numbers, would like to be able to:

1) First roll, if the dice roll 7 or 11 you win
2) First roll, if the dice roll 2,3,12 you lose
3) First roll, if the dice roll 4,5,6,8,9,10 - that becomes the point, you must roll one of these to win before you roll a 7, if you roll 7 you lose

I don't think I understand your third rule but in any case I think if/else statements might be the better way to go here. I only say that because with a case/switch you'll have a case for each dice total (and a default), and with if/else statements you'll only need 3 or 4 logical statements to achieve your game rules. I can't say that one is faster than the other in terms of processing but if we are being honest here there is very little chance it will have any impact on the performance of your game. Frankly I just feel it gives you fewer lines as you can group the conditions.

It looks like you should add a global array that holds the dice totals (since rule 3 seems to apply to more than one roll). Other than that you just seem to need to add up the dice rolls (adding +1 to each since you are using the dice rolls as array indexes) and then running them through a set of if/else statements. For functionality you would probably set it up similar to: