rahagnok Posted October 25, 2007 Share Posted October 25, 2007 Hello everyone,I'm trying to make a simple web-based game. Thanks to some help from another topic, I have 5 images of dice that are randomly assigned a "face" when the user clicks the "roll" button. Now I need a little help with assigning a check box to each die that enables the user to pick and choose which die to keep and which to re-roll. Any help is hugely appreciated, thank you. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 25, 2007 Share Posted October 25, 2007 What part do you need help with? What do you have so far? Link to comment Share on other sites More sharing options...
rahagnok Posted October 25, 2007 Author Share Posted October 25, 2007 Well so far I have been able to make five different images to appear. I also have a button called roll that causes the images to change randomly each time it is clicked. Now my main problem is figuring out how to make it so when the user wishes to keep one or more of the die, they can select it so it won't be "re-rolled". I was thinking that I could achieve this by either creating an onClick event , with the image being mapped, or by somehow making it when the check box value= checked, the assigned image won't be part of the roll function. I just can't figure out how to do this.Thanks for the help Link to comment Share on other sites More sharing options...
justsomeguy Posted October 25, 2007 Share Posted October 25, 2007 I'm thinking Yahtzee. Putting an onclick on the image would be cool. If the images are each in their own container (like a padded inline div), you can change the background color of the container to indicate that it's being kept, like a poker program does.<div style="padding: 5px; background-color: #FFFFFF; display: inline;"><img onclick="toggle_die(this, 1);" src=...></div> var saved_dice = new Array();function toggle_die(el, id){ var parent_div = el.parentNode; if (parent_div.style.backgroundColor == "#FFFFFF") { parent_div.style.backgroundColor = "#CC0000"; saved_dice.push(id); } else { parent_div.style.backgroundColor = "#FFFFFF"; foreach (var i in saved_dice) if (saved_dice[i] == id) saved_dice.splice(i, 1); }} When you're rolling the dice you can loop through the saved_dice array and check if the ID number of the die is in there before rolling it. If the ID is in the array then the die is being saved. Link to comment Share on other sites More sharing options...
rahagnok Posted October 25, 2007 Author Share Posted October 25, 2007 Yeah that sounds good I'll try that and see if I can get it to work. Thank you! Link to comment Share on other sites More sharing options...
justsomeguy Posted October 26, 2007 Share Posted October 26, 2007 An alernate would be to have a different image for each die to be the "selected" state (like a black die with white spots, or the white die with a semi-transparent "saved" over it or something), and instead of changing the background color of the parent div you would change the src of the image. Link to comment Share on other sites More sharing options...
SpOrTsDuDe.Reese Posted October 26, 2007 Share Posted October 26, 2007 Gay. Someone deletes my posts. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.