This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcards.js
95 lines (84 loc) · 2.13 KB
/
cards.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
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* card constructor
* @param {*} color
* @param {*} value
*/
function Card(color, value) {
this.color = color;
this.value = value;
this.getColorValue = function () {
switch (this.color) {
case "Red":
return "#A60000";
case "Blue":
return "#0000FF";
case "Green":
return "#004f19";
case "Yellow":
return "#e5bf00";
default:
return "#333333";
}
};
}
/**
* Function draws a specific card for cheat
*/
function drawSpecificCard(cardColor, cardValue) {
players[gameTurn].playerDeck.drawSpecificCard(cardColor, cardValue);
}
/**
* Function draws a specific card for cheat code
*/
function removeManyCards(numberOfCards) {
if (numberOfCards > players[gameTurn].playerDeck.amtCards - 2) {
return;
}
for (let i = 0; i < numberOfCards; i++) {
players[gameTurn].playerDeck.removeCard(0);
}
players[gameTurn].playerDeck.reloadHand();
}
/**
* Function draws cards and adds them to playerhand
*/
function drawACard() {
if (drawStack.stackAmt != 0) {
let drawTimes = drawStack.cardType * drawStack.stackAmt;
drawStack.clearVisual();
for (let i = 0; i < drawTimes; i++) {
players[gameTurn].playerDeck.drawCard();
}
drawStack.stackAmt = 0;
rotatePlayers();
play();
} else if (forcePlay()) {
let audio = new Audio("error.mp3");
audio.play();
} else {
players[gameTurn].playerDeck.drawCard();
}
}
$(drawCardPile).click(function () {
drawACard();
});
/**
* Changes the global card object to random color/value assignment
*/
function selectPlayfieldCard() {
let colorArray = ["Red", "Green", "Blue", "Yellow"];
let randColor = colorArray[Math.floor(Math.random() * colorArray.length)];
let randValue = Math.floor(Math.random() * 10);
let tempCard = new Card(randColor, randValue);
discard(tempCard);
}
function discard(card) {
discardPile.addCard(card);
if (discardPile.cards.length > 5) discardPile.removeCard(0);
}
function forcePlay() {
for (let i = 0; i < players[gameTurn].playerDeck.cards.length; i++) {
if (players[gameTurn].playerDeck.isValid(i)) return true;
}
return false;
}