Sigmahokies Posted May 26, 2016 Share Posted May 26, 2016 Hi everyone, I am trying to find source or tutorial how to create the random. I will like to learn how to create the random in poker card, but i need to make sure it must show the display that card is used. For example, I click on back of card to draw card, then show number or royal on card, then click it, moved to left-top or right-top to keep tracking those random poker card...do you have any idea? those card can't be repeated. Thank you so much Link to comment Share on other sites More sharing options...
davej Posted May 26, 2016 Share Posted May 26, 2016 Here is a basic text example of a random card draw... <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Cards</title> <script> window.onload = init; function init(){ document.getElementById('btn1').onclick = drawc; document.getElementById('btn2').onclick = shuffle; } var str = ""; var cards = ['Ace','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King']; var suit = ['Clubs','Diamonds','Hearts','Spades']; var cardcount = suit.length * cards.length; var facecount = cards.length; var i = 0; function drawc() { var n; var f; var c; if (i >= cardcount){ return; } do{ f = Math.floor(facecount * Math.random()); n = Math.floor(4 * Math.random()); c = cards[f] + ' of ' + suit[n]; }while(str.indexOf(c) != -1); i++; str = i + ' ' + c + '<br/>' + str; document.getElementById("out1").innerHTML = str; } function shuffle(){ document.getElementById("out1").innerHTML = ""; str = ""; i = 0; } </script> </head> <body> <p>Click the button to display a random card.</p> <button id="btn1">Draw Card</button> <button id="btn2">Shuffle Cards</button><br/><br/> <div id="out1"></div> </body> </html> Link to comment Share on other sites More sharing options...
Sigmahokies Posted May 26, 2016 Author Share Posted May 26, 2016 (edited) Oh cool, it worked, it is in JavaScript, right? Can i make an image in this script? But why i get "undefine of shade", "undefine of heart"...I will like to remove this "undefine" Thanks! Edited May 26, 2016 by Sigmahokies Link to comment Share on other sites More sharing options...
davej Posted May 26, 2016 Share Posted May 26, 2016 I'm sure you can find many sets of card images if you search the web. You deleted the joker. See the revised code above. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now