-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.js
82 lines (82 loc) · 3.08 KB
/
Card.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
exports.__esModule = true;
exports.Card = void 0;
var Rank_js_1 = require("./Rank.js");
var Suit_js_1 = require("./Suit.js");
/////////////////////////////////
//
//
/* SECTION BELOW: this is the card class */
//t
//
/////////////////////////////////
var Card = /** @class */ (function () {
// REQUIRES: rank is a Rank object and suit is a Suit object
function Card(rank, suit) {
this.suit = suit;
this.rank = rank;
this.name = "".concat(this.rank.getRankName(), " of ").concat(this.suit.getSuitName());
}
//EFFECTS: returns Suit object of card
Card.prototype.getSuit = function () {
return this.suit;
};
//EFFECTS: returns Suit string of card
Card.prototype.getSuitName = function () {
return this.suit.getSuitName();
};
//EFFECTS: returns Rank object of card
Card.prototype.getRank = function () {
return this.rank;
};
//EFFECTS: returns Rank string of card
Card.prototype.getRankName = function () {
return this.rank.getRankName();
};
//EFFECTS: returns name of card
Card.prototype.getName = function () {
return this.name;
};
//REQUIRES: otherCard is a Card object
//EFFECTS: returns true if this object has same suit as otherCard, false otherwise
Card.prototype.hasSameSuitAs = function (otherCard) {
return this.suit.isSameSuitAs(otherCard.getSuit());
};
//REQUIRES: otherCard is a Card object
//EFFECTS: returns true if this object has better suit than otherCard, false otherwise
Card.prototype.hasBetterSuitThan = function (otherCard) {
return this.suit.isBetterSuitThan(otherCard.getSuit());
};
//REQUIRES: otherCard is a Card object
//EFFECTS: returns true if this object has same rank as otherCard, false otherwise
Card.prototype.hasSameRankAs = function (otherCard) {
return this.rank.isSameRankAs(otherCard.getRank());
};
//REQUIRES: otherCard is a Card object
//EFFECTS: returns true if this object has better rank than otherCard, false otherwise
Card.prototype.hasBetterRankThan = function (otherCard) {
return this.rank.isBetterRankThan(otherCard.getRank());
};
// REQUIRES: otherCard is a Card object
// EFFECTS: returns true if this card is equal to the other card
Card.prototype.isEqualTo = function (otherCard) {
return this.rank === otherCard.rank && this.suit === otherCard.suit;
};
Card.compareCards = function (firstCard, secondCard) {
// COMMENTS: first rank has priority
switch (Rank_js_1.Rank.compareTwoRanks(firstCard.getRank(), secondCard.getRank())) {
case 1:
return 1;
case -1:
return -1;
case 0:
// COMMENTS: if ranks are equal, suits have priority
return Suit_js_1.Suit.compareTwoSuits(firstCard.getSuit(), secondCard.getSuit());
}
};
Card.prototype.isThreeOfDiamonds = function () {
return this.getRankName() === "Three" && this.getSuitName() === "Diamonds";
};
return Card;
}());
exports.Card = Card;