Jump to content

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...