-
-
Save GrantSchiller/6625322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Card(val,st) { | |
this.value = val; | |
this.suit = st; | |
} | |
Card.prototype.getValue = function() { | |
return this.value; | |
} | |
Card.prototype.getSuit = function() { | |
return this.suit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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