-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from DhairyaShah01/Dhairya-Shah-Step3
Step 3
- Loading branch information
Showing
11 changed files
with
183 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Activating the next player | ||
function activatePlayer(game){ | ||
const playerList = document.getElementById('root').children | ||
const currentPlayer = playerList[game.turn + 1] | ||
const activate = currentPlayer.querySelectorAll('.Card') | ||
const buttonactive = currentPlayer.querySelectorAll('.buttons')[0] | ||
activate.forEach((Card) => { | ||
Card.style['pointer-events'] = 'auto' // Activating all Cards for current player | ||
}) | ||
buttonactive.disabled = false // Activating the button for current player | ||
const currentPlayerName = currentPlayer.getElementsByTagName('h1')[0].textContent | ||
document.getElementsByTagName('h2')[1].innerHTML = 'Current Player: ' + currentPlayerName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable no-unused-vars */ | ||
// Storing data if the player bluffed or not | ||
function bluffData(game, centralStack, initialNoOfCards, finalNoOfCards) { | ||
if(game.currentRank === '') { // Checking if it is the first chance or not | ||
document.getElementById('cardModal').style.display = "block" // Displaying the modal | ||
document.getElementById('submit').onclick = function() { // Adding an onClick to the submit button of the modal | ||
game.currentRank = submitCard(game, centralStack, initialNoOfCards, finalNoOfCards) // Storing the current rank to game.currentRank | ||
} | ||
} | ||
else { | ||
check(game, game.currentRank, centralStack, initialNoOfCards, finalNoOfCards) // If not the first turn, check if the player bluffed or not | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Function to check whether the player bluffed or not | ||
function check(game, currentRank, centralStack, initialNoOfCards, finalNoOfCards) { | ||
let j = 0 // Initialise a flag | ||
for (let i = initialNoOfCards; i < finalNoOfCards; i++) { // Looping through cards added in this chance | ||
if (centralStack[i].value !== 'Joker') { // Checking if value is not a joker | ||
if(centralStack[i].value === currentRank) { // Comparing the value of newly added cards added to the data entered | ||
j += 1 // Adding 1 to the flag if true card is added | ||
} | ||
} | ||
else { | ||
j += 1 // Also, adding 1 to the flag if the card added is a joker | ||
} | ||
} | ||
const noOfCardsMoved = finalNoOfCards - initialNoOfCards // Calculating the number of cards added in this chance | ||
const msg = game.players[game.turn - 1].playerName + ' added ' + noOfCardsMoved + ' card(s) to the stack.' | ||
window.alert(msg) | ||
// If value of flag is equal to the number of cards added in this turn | ||
// Set record to not bluffed | ||
if (j === noOfCardsMoved) { | ||
game.record = 'Not Bluffed' | ||
} | ||
// Set record to Bluffed | ||
else { | ||
game.record = 'Bluffed' | ||
} | ||
if(game.turn === game.players.length) { | ||
game.turn = 1 | ||
activatePlayer(game) // Activating the next player | ||
} | ||
else { | ||
game.turn += 1 | ||
activatePlayer(game) // Activating the next player | ||
} | ||
console.log(game.record) // To see whether last player bluffed or not | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Deactivating the previously active player | ||
function deactivatePlayer(game) { | ||
const playerList = document.getElementById('root').children | ||
const currentPlayer = playerList[game.turn + 1] | ||
const activate = currentPlayer.querySelectorAll('.Card') | ||
const buttonactive = currentPlayer.querySelectorAll('.buttons')[0] | ||
activate.forEach((Card) => { | ||
Card.style['pointer-events'] = 'none' // Activating all Cards for current player | ||
}) | ||
buttonactive.disabled = true // Activating the button for current player | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Function which executes when the submit button is clicked | ||
function submitCard(game, centralStack, initialNoOfCards, finalNoOfCards) { | ||
const modal = document.getElementById('cardModal') | ||
modal.style.display = 'none' // Removing the modal from the screen | ||
const selectedCard = document.getElementById('selectCard') // Storing all the options in select menu | ||
let optSelected = null | ||
// Looping thropugh the options to check if the option was selected or not | ||
for ( let i = 0; i < selectedCard.options.length; i++) { | ||
optSelected = selectedCard.options[i] | ||
if ( optSelected.selected === true) { | ||
break // If option was selected | ||
} | ||
} | ||
const h2 = document.getElementsByTagName('h2')[0] | ||
h2.innerHTML = 'Current Rank: ' + optSelected.value // Updating the h2 inside centralStack | ||
check(game, optSelected.value, centralStack, initialNoOfCards, finalNoOfCards) // Calling check for the first time | ||
return optSelected.value // Return the value of selected option | ||
} |