Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tsFiles/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var Card = /** @class */ (function () {
function Card(i) {
var s = "null";
switch (Math.floor(i / 13)) {
case 0:
s = "Hearts";
break;
case 1:
s = "Diamonds";
break;
case 2:
s = "Spades";
break;
case 3:
s = "Clubs";
break;
}
this.suit = s;
this.value = Math.floor(i % 13);
}
Card.prototype.val = function () {
if (this.value < 9)
return (this.value + 2).toString();
else
switch (this.value) {
case 9:
return "Jack";
case 10:
return "Queen";
case 11:
return "King";
case 12:
return "Ace";
}
};
Card.prototype.valNum = function () {
return (this.value < 9) ? this.value + 2 : 10;
};
return Card;
}());
var Deck = /** @class */ (function () {
function Deck() {
this.data = [];
this.currentCard = 0;
for (var i = 0; i < 52; i++) {
this.data.push(new Card(i));
}
this.shuffle();
}
Deck.prototype.printAll = function () {
this.data.forEach(function (c) {
console.log(c.suit + " " + c.value);
});
};
Deck.prototype.shuffle = function () {
for (var j, x, i = this.data.length; i; j = Math.floor(Math.random() * i),
x = this.data[--i],
this.data[i] = this.data[j],
this.data[j] = x)
;
this.currentCard = 0;
};
Deck.prototype.deal = function () {
return this.data[this.currentCard++];
};
return Deck;
}());
68 changes: 68 additions & 0 deletions tsFiles/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class Card {
suit: string;
value: number;
constructor(i: number){
var s = "null";
switch (Math.floor(i / 13)){ // 13 since each type contains 4
case 0:
s = "Hearts"; break;
case 1:
s = "Diamonds"; break;
case 2:
s = "Spades"; break;
case 3:
s = "Clubs"; break;
}
this.suit = s;
this.value = Math.floor(i % 13);
}
val(): string{
if (this.value < 9)
return (this.value + 2).toString();
else
switch(this.value){
case 9:
return "Jack";
case 10:
return "Queen";
case 11:
return "King";
case 12:
return "Ace";
}
}
valNum(): number{
return (this.value < 9) ? this.value + 2 : 10;
}
}

class Deck {
data: Card[] = [];
currentCard: number = 0;

constructor(){
for (var i = 0; i < 52; i++){
this.data.push(new Card(i));
}
this.shuffle();
}
printAll(){
this.data.forEach(function(c){
console.log(c.suit + " " + c.value);
});
}

shuffle(){
for(var j, x, i = this.data.length;
i;
j = Math.floor(Math.random() * i),
x = this.data[--i],
this.data[i] = this.data[j],
this.data[j] = x);
this.currentCard = 0;
}

deal(): Card{
return this.data[this.currentCard++];
}
}
16 changes: 16 additions & 0 deletions tsFiles/rank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var Rank;
(function (Rank) {
Rank[Rank["ACE"] = 0] = "ACE";
Rank[Rank["TWO"] = 1] = "TWO";
Rank[Rank["THREE"] = 2] = "THREE";
Rank[Rank["FOUR"] = 3] = "FOUR";
Rank[Rank["FIVE"] = 4] = "FIVE";
Rank[Rank["SIX"] = 5] = "SIX";
Rank[Rank["SEVEN"] = 6] = "SEVEN";
Rank[Rank["EIGHT"] = 7] = "EIGHT";
Rank[Rank["NINE"] = 8] = "NINE";
Rank[Rank["TEN"] = 9] = "TEN";
Rank[Rank["JACK"] = 10] = "JACK";
Rank[Rank["QUEEN"] = 11] = "QUEEN";
Rank[Rank["KING"] = 12] = "KING";
})(Rank || (Rank = {}));
15 changes: 15 additions & 0 deletions tsFiles/rank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum Rank {
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
}
7 changes: 7 additions & 0 deletions tsFiles/suit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var Suit;
(function (Suit) {
Suit[Suit["SPADE"] = 0] = "SPADE";
Suit[Suit["HEART"] = 1] = "HEART";
Suit[Suit["CLUB"] = 2] = "CLUB";
Suit[Suit["DIAMOND"] = 3] = "DIAMOND";
})(Suit || (Suit = {}));
6 changes: 6 additions & 0 deletions tsFiles/suit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum Suit {
SPADE,
HEART,
CLUB,
DIAMOND
}