Skip to content

Commit

Permalink
added timeout function
Browse files Browse the repository at this point in the history
  • Loading branch information
zephaniahong committed Jan 13, 2021
1 parent a60cba2 commit e0f5e3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<h1 id="header">SWE101! 🚀</h1>
<!-- Import program logic -->
</div>
<script src="script.js"></script>
</body>
</html>
34 changes: 28 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,30 @@ const createCard = (cardInfo) => {

const deck = shuffleCards(makeDeck());

const cardInfo = {
suitSymbol: '♦️',
suit: 'diamond',
name: 'queen',
display: 'Q',
color: 'red',
rank: 12,
}

const player1Click = () => {
if (playersTurn === 1) {
player1Card = deck.pop();
cardContainer.innerHTML = ''
cardContainer.appendChild(createCard(player1Card));
playersTurn = 2;
if (playersTurn === 1 && canClick === true) {
canClick = false;

setTimeout(() => {
player1Card = deck.pop();
cardContainer.innerHTML = ''
cardContainer.appendChild(createCard(player1Card));
playersTurn = 2;
canClick = true
}, 500);
}
setTimeout(() => {
output("It's player 2's turn. Click to draw a card")
}, 1000);
};

const player2Click = () => {
Expand All @@ -140,12 +157,16 @@ const player2Click = () => {
output('tie');
}
}
setTimeout(() => {
output("It's player 1's turn. Click to draw a card!")
}, 1500)
};


let player1Card
let playersTurn = 1; // matches with starting instructions
let cardContainer;
let canClick = true

//creating permanent elements
const mainDiv = document.createElement('div')
Expand All @@ -171,9 +192,10 @@ const initGame = () => {
player2Button.addEventListener('click', () => {player2Click()});

// fill game info div with starting instructions
gameInfo.innerText = 'Its player 1 turn. Click to draw a card!';
gameInfo.innerText = "It's player 1's turn. Click to draw a card!";
document.body.appendChild(gameInfo);
}


// initGame()
initGame()

0 comments on commit e0f5e3a

Please sign in to comment.