-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeLayout.js
153 lines (153 loc) · 6.58 KB
/
ChangeLayout.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"use strict";
exports.__esModule = true;
exports.disableAllButtons = exports.letPlayerChooseCards = exports.hidePlayerCardLayout = exports.revealPlayerCardLayout = exports.resetTableLayout = exports.changeTableLayout = void 0;
var Reference_js_1 = require("./Reference.js");
/////////////////////////////////
//
//
/* SECTION BELOW: things to deal with changing player card layout */
//
//
/////////////////////////////////
// REQUIRES: cardObject is an HTML element representing a single card slot
// EFFECTS: change and update a player's card layout (the player being whoever owns the array of cards)
function makeCardSlotEmpty(cardObject) {
// COMMENTS: need to remove any unwanted classes
cardObject.className = "card card-empty";
}
// REQUIRES: updatedCard is a Card object that is providing the information
// REQUIRES: cardObject is a HTML element representing the card slot to be updated
// EFFECTS: change and update a single card slot based on the updatedCard
function revealSingleCardSlot(updatedCard, cardObject) {
// COMMENTS: change the card object based on the updateCard
var cardName = updatedCard.getName();
var cssName = Reference_js_1.mapCardNameToCSS.get(cardName);
cardObject.className = "card " + cssName;
}
// REQUIRES: allCards is an array of Card objects showing all of player's current cards
// REQUIRES: cardObjectsArray is an array of HTML elements representing the player's card slots
// EFFECTS: change and update a player's card layout (the player being whoever owns the array of cards)
function revealPlayerCardLayout(allCards, cardObjectsArray) {
// COMMENTS: first need to make it so that all of player's other cards are empty
for (var i = allCards.length; i < allCards.length + 5 && i < 13; ++i) {
makeCardSlotEmpty(cardObjectsArray[i]);
}
// COMMENTS: now change each of the cards and update them
for (var i = 0; i < allCards.length; ++i) {
revealSingleCardSlot(allCards[i], cardObjectsArray[i]);
}
}
exports.revealPlayerCardLayout = revealPlayerCardLayout;
// REQUIRES: cardObject is a HTML element representing the card slot to be updated
// EFFECTS: hide card slot
function hideSingleCardSlot(cardObject) {
cardObject.className = "card " + "card-back";
}
// REQUIRES: allCards is an array of Card objects showing all of player's current cards
// REQUIRES: cardObjectsArray is an array of HTML elements representing the player's card slots
// EFFECTS: change and update a player's card layout (the player being whoever owns the array of cards)
function hidePlayerCardLayout(allCards, cardObjectsArray) {
// COMMENTS: first need to make it so that all of player's other cards are empty
for (var i = allCards.length; i < allCards.length + 5 && i < 13; ++i) {
makeCardSlotEmpty(cardObjectsArray[i]);
}
// COMMENTS: now change each of the cards and update them
for (var i = 0; i < allCards.length; ++i) {
hideSingleCardSlot(cardObjectsArray[i]);
}
}
exports.hidePlayerCardLayout = hidePlayerCardLayout;
/////////////////////////////////
//
//
/* SECTION BELOW: things to deal with changing table card layout */
//
//
/////////////////////////////////
// REQUIRES: allCards is an array of Card objects showing best cards played so far
// REQUIRES: cardObjectsArray is an array of HTML elements representing the table's card slots
// EFFECTS: change and update the table's card layout
function changeTableLayout(bestHandSoFar) {
var bestCardsSoFar = bestHandSoFar.getCardObjectsInHand();
// COMMENTS: now change each of the cards and update them
for (var i = 0; i < bestCardsSoFar.length; ++i) {
revealSingleCardSlot(bestCardsSoFar[i], Reference_js_1.mainCardsHTML[i]);
}
}
exports.changeTableLayout = changeTableLayout;
// REQUIRES: cardObjectsArray is an array of HTML elements representing the table's card slots
// EFFECTS: reset the table's card layout
function resetTableLayout() {
// COMMENTS: make all cards empty
for (var i = 0; i < 5; ++i) {
makeCardSlotEmpty(Reference_js_1.mainCardsHTML[i]);
}
}
exports.resetTableLayout = resetTableLayout;
/////////////////////////////////
//
//
/* SECTION BELOW: things to deal with player selecting cards */
//
//
/////////////////////////////////
// REQUIRES: current player is selecting cards
// REQUIRES: cardAmount is a number showing how many cards player has
// REQUIRES: cardObjectsArray is an array of HTML elements representing the player's card slots
// EFFECTS: activate the card object buttons temporarily
function activateButtons(cardAmount, cardObjectsArray) {
// COMMENTS: change the card object based on the updateCard
for (var i = 0; i < cardAmount; ++i) {
cardObjectsArray[i].disabled = false;
}
}
// REQUIRES: current player is done cards
// REQUIRES: cardObjectsArray is an array of HTML elements representing the player's card slots
// EFFECTS: disable the card object buttons
function disableAllButtons(cardObjectsArray) {
// COMMENTS: change the card object based on the updateCard
for (var i = 0; i < 13; ++i) {
var specificCardObject = cardObjectsArray[i];
specificCardObject.disabled = true;
if (specificCardObject.classList.contains("card-highlighted")) {
specificCardObject.classList.remove("card-highlighted");
}
}
}
exports.disableAllButtons = disableAllButtons;
// EFFECTS: change card display of a cardObject
function highlightSelectedCard(cardObject) {
if (cardObject.classList.contains("card-highlighted")) {
cardObject.classList.remove("card-highlighted");
}
else {
cardObject.classList.add("card-highlighted");
}
}
// EFFECTS: basic sleep function
function sleep(milliseconds) {
var date = Date.now();
var currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
// REQUIRES: current player is selecting cards
// REQUIRES: cardAmount is a number showing how many cards player has
// REQUIRES: cardObjectsArray is an array of HTML elements representing the player's card slots
// EFFECTS: let player choose cards
function letPlayerChooseCards(cardAmount, cardObjectsArray, trackSelection) {
// COMMENTS: allow user to choose cards
activateButtons(cardAmount, cardObjectsArray);
var _loop_1 = function (i) {
cardObjectsArray[i].onclick = function () {
trackSelection[i] = !trackSelection[i];
highlightSelectedCard(cardObjectsArray[i]);
};
};
// COMMENTS: this is so that the user can select and unselect the cards
for (var i = 0; i < cardAmount; ++i) {
_loop_1(i);
}
}
exports.letPlayerChooseCards = letPlayerChooseCards;