-
Notifications
You must be signed in to change notification settings - Fork 0
/
setInterval.js
51 lines (44 loc) · 1.39 KB
/
setInterval.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
// Every 2 seconds, a card is put down
// Play a turn every 2 seconds (ie. call playTurn function every 2 seconds)
let playerCount, computerCount, discardCount; // counts
let playerDeck, computerDeck; // card decks
let previousCard, currentCard; // matching cards
let turn = 0; // turn count
const startGame = () => {
// call playTurn function every ? interval
// update the Counts variables
// stop the interval (clearInterval) when SNAP button is clicked (or computer presses SNAP). Else, continue putting down cards.
};
// while (playerDeck.length > 0 && computerDeck.length > 0) {}
const playTurn = () => {
turn++;
discardCount++;
if (turn === 1) {
// for the first turn only
currentCard = playerDeck.pop();
} else {
if (turn % 2 !== 0) {
// on odd turns
previousCard = currentCard;
currentCard = playerDeck.pop();
} else {
// on even turns
previousCard = currentCard;
currentCard = computerDeck.pop();
}
}
console.log("Turn", turn); // check turn number
console.log("prev", previousCard, "current", currentCard); // check previous and current card
console.log(
// check remaining deck length
"player length",
playerDeck.length,
"computer length",
computerDeck.length
);
};
const printHello = () => {
console.log("hello");
};
const myInterval = setInterval(printHello, 1000);
clearInterval(playTurnInterval);