-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.js
59 lines (49 loc) · 1.05 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
//**********
//Card Class
//**********
class Card {
constructor (rank, suite) {
this.rank = rank;
this.suite = suite;
//calculates points based on rank
this.points = (function (rank) {
if(rank === 'J' || rank === 'Q' || rank === 'K') {
return 10;
} else if(rank === 'A') {
return 11;
} else {
return parseInt(rank);
}
})(rank);
//set name to rank + suite
this.name = (function (rank, suite) {
return rank + suite;
})(rank, suite);
//set image path to name
var name = this.name;
this.imagePath = (function (name) {
return 'cards/' + name + '.gif';
})(name);
//checks if Ace for scoring
this.isAce = (function (rank) {
return rank === 'A' ? true : false;
})(rank);
}
// Find img tag in html and set path
//
getCardImage() {
var img = document.createElement("img");
img.src = this.imagePath;
return img;
}
// Sets card to show back image
//
setBackImage(isBack) {
this.back = isBack;
}
// Return boolean to see if card is showing back
//
getBackImage() {
return this.back;
}
}