Skip to content

Instantly share code, notes, and snippets.

@GrantSchiller
Forked from anonymous/Card class
Created September 19, 2013 15:36
Show Gist options
  • Save GrantSchiller/6625322 to your computer and use it in GitHub Desktop.
Save GrantSchiller/6625322 to your computer and use it in GitHub Desktop.
function Card(val,st) {
this.value = val;
this.suit = st;
}
Card.prototype.getValue = function() {
return this.value;
}
Card.prototype.getSuit = function() {
return this.suit;
}
function Deck() {
this.cards = new Array();
var values = new Array("A","2","3","4","5","6","7","8","9","10","J","Q","K");
var suits = new Array("Spade","Club","Jack","Diamond");
for(var i = 0; i < 13; i++) {
for(var j = 0; j < 4; j++) {
this.cards.push(new Card(values[i], suits[j]));
}
}
}
function shuffle() {
var temp = new Array();
while(this.cards.length > 0) {
var index = Math.floor(Math.random() * this.cards.length);
temp.push(this.cards.splice(index,1));
}
this.cards = temp;
}
function takeCard() {
var temp = this.cards[0];
this.cards.splice(0,1);
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment