Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fe974e5
non working version of video poker.
gysiang Dec 6, 2021
0983757
added functions to check for win. aligned divs to center.
gysiang Dec 8, 2021
a256a3d
cards selected will be appended into cardsToSwap array.
gysiang Dec 9, 2021
1c10c19
added functionality to swap cards and calculate score.
gysiang Dec 10, 2021
ab5d49a
added calcHandScore helper function. Working version of poker.
gysiang Dec 11, 2021
880776a
added gif as header and changed background color.
gysiang Dec 12, 2021
5506261
added poker table and sound effects.
gysiang Dec 12, 2021
e3d71b4
added font and score tab.
gysiang Dec 12, 2021
02fc584
added win sound effect.
gysiang Dec 12, 2021
b9fe8fc
add lose music.
gysiang Dec 12, 2021
87248d8
added mute and play button. Music not working.
gysiang Dec 13, 2021
2757491
working play and mute bgm button.
gysiang Dec 13, 2021
a1bca1b
added images of poker card to be appended.
gysiang Dec 13, 2021
1e987c2
did several test hands and fixed checkstraightflush and fullhouse fun…
gysiang Dec 14, 2021
4c18304
fixed royal straight function.
gysiang Dec 15, 2021
84cd4f3
fixed canSwap & canClick for deal and swap buttons.
gysiang Dec 15, 2021
042c202
changed names for several cards to fix bug.
gysiang Dec 16, 2021
a71465a
refactor script.js into several files.
gysiang Dec 16, 2021
0d1c388
added jsdocs and refactor game.
gysiang Dec 16, 2021
9ec2f62
Update README.md
gysiang Dec 17, 2021
afe1af0
changed image location.
gysiang Dec 18, 2021
397b7ba
renamed cards.
gysiang Dec 18, 2021
0ac656c
changed file source const filepath.
gysiang Dec 18, 2021
38f1fcb
removed cards.
gysiang Dec 18, 2021
fb26af0
reinserted cards.
gysiang Dec 18, 2021
815c0cf
changed filepath for folderPath.
gysiang Dec 18, 2021
5422f77
changed file path.
gysiang Dec 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ module.exports = {
'no-param-reassign': ['error', { props: false }],
},
};

options: {
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: false,
}],
},
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Rocket Academy Coding Bootcamp: Video Poker
https://gysiang.github.io/video-poker-bootcamp/
49 changes: 49 additions & 0 deletions audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const muteBtn = document.querySelector('.mute');
const bgMusic = new Audio('sounds/casino-bgm.mp3');
bgMusic.volume = 0.1;
/**
* Enables play and pause of bgm music
*/
const playPause = () => {
if (bgMusic.paused) {
bgMusic.play();
muteBtn.className = 'unmute';
} else {
bgMusic.pause();
muteBtn.className = 'mute';
}
};

muteBtn.addEventListener('click', playPause);

/**
* Plays the insert coin effect when called
*/
const insertCoinEffect = () => {
const audio = new Audio('sounds/insert-coin.mp3');
audio.volume = 0.5;
audio.play();
};
/**
* Plays the flip card effect when called
*/
const flipEffect = () => {
const audio = new Audio('sounds/flip-card.mp3');
audio.play();
};
/**
* Plays the win sound effect when called
*/
const winSoundEffect = () => {
const audio = new Audio('sounds/win-sound.mp3');
audio.volume = 0.1;
audio.play();
};
/**
* Plays the lose sound effect when called
*/
const loseSoundEffect = () => {
const audio = new Audio('sounds/lose-sound.mp3');
audio.volume = 0.5;
audio.play();
};
227 changes: 227 additions & 0 deletions checkHands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/**
* Calculates the total number of ranks and suits and push it to rankTally and suitTally
* @returns array containing the objects rankTally & suitTally
*/
const tallyHand = () => {
for (let i = 0; i < playerHand.length; i += 1)
{
const card = playerHand[i];
if (card.rank in rankTally) {
rankTally[`${card.rank}`] += 1;
}
else {
rankTally[`${card.rank}`] = 1;
}

if (card.suit in suitTally) {
suitTally[`${card.suit}`] += 1;
}
else {
suitTally[`${card.suit}`] = 1;
}
}
return [rankTally, suitTally];
};
/**
* Deletes the values for each key in the object
* @param {object}
*/
const clearTally = (object) => {
Object.keys(object).forEach((key) => delete object[key]);
};

/**
* Checks the hand for flush
* @param {Object} suitTally
* @returns either true or false
*/

const checkFlush = (suitTally) => {
for (suit in suitTally) {
if (suitTally[suit] === 5) {
return true;
}
}
return false;
};

/**
* Checks the hand for four of a kind
* @param {object} rankTally
* @returns either true or false
*/
const checkFourOfAKind = (rankTally) => {
for (rank in rankTally) {
if (rankTally[rank] === 4) {
return true;
}
}
return false;
};

/**
* Checks the hand for three of kind
* @param {object} rankTally
* @returns either true or false
*/
const checkThreeOfKind = (rankTally) => {
for (rank in rankTally) {
if (rankTally[rank] === 3) {
return true;
}
}
return false;
};
/**
* Checks hand for a pair
* @param {object} rankTally
* @returns either true or false
*/
const checkPair = (rankTally) => {
for (rank in rankTally) {
if (rankTally[rank] === 2) {
return true;
}
}
return false;
};
/**
* Checks hand for full house
* @param {object} rankTally
* @returns either true or false
*/
const checkFullHouse = (rankTally) => {
if (checkThreeOfKind(rankTally) === true && (checkPair(rankTally) === true)) {
return true;
}
return false;
};
/**
* Checks hand for two pair
* @param {object} rankTally
* @returns either true or false
*/
const checkTwoPair = (rankTally) => {
let pairCount = 0;
for (rank in rankTally) {
if (rankTally[rank] === 2) {
pairCount += 1;
}
if (pairCount === 2) {
return true;
}
}
return false;
};
/**
* Checks hand for straight
* @param {object} rankTally
* @returns either true or false
*/
const checkStraight = () => {
let count = 0;
for (let i = 0; i < (playerHand.length - 1); i += 1) {
if (playerHand[i].rank - playerHand[i + 1].rank === 1) {
count += 1;
}
}
if (count === 4) {
return true;
}
return false;
};
/**
* Checks hand for straight flush
* @param {object} suitTally
* @param {object} rankTally
* @returns either true or false
*/
const checkStraightFlush = (suitTally, rankTally) => {
if (checkFlush(suitTally) === true && (checkStraight(rankTally) === true)) {
return true;
}
return false;
};
/**
* Checks hand for Royal Straight
* @param {object} rankTally
* @returns either true or false
*/
const checkRoyalStraight = (rankTally) => {
if (
rankTally['1'] === 1
&& rankTally['13'] === 1
&& rankTally['12'] === 1
&& rankTally['11'] === 1
&& rankTally['10'] === 1) {
return true;
}
return false;
};

/**
* Checks hand for Royal Flush
* @param {object} rankTally
* @param {object} suitTally
* @returns either true or false
*/
const checkRoyalFlush = (rankTally,suitTally) => {
if (checkRoyalStraight(rankTally) === true && checkFlush(suitTally) === true) {
return true;
}
return false;
};
/**
* Checks hand for Jacks or better
* @param {object} rankTally
* @returns either true or false
*/
const checkJacksOrBetter = (rankTally) => {
if (rankTally['11'] === 2 || rankTally['12'] === 2 || rankTally['13'] === 2 || rankTally['1'] === 2) {
return true;
}
return false;
};

/**
* Calculates the handscore from the hand
* @param {object} rankTally - key: rank, value: number of cards with rank
* @param {object} suitTally - key: suit, value: number of cars with suit
* @returns handscore as number
*/

const calcHandScore = (rankTally, suitTally) => {
if (checkRoyalFlush(rankTally, suitTally) === true) {
handScore = 800;
return handScore;
} if (checkStraightFlush(suitTally) === true) {
handScore = 50;
return handScore;
} if (checkFlush(suitTally) === true) {
handScore = 6;
return handScore;
} if (checkFourOfAKind(rankTally) === true) {
handScore = 25;
return handScore;
} if (checkFullHouse(rankTally) === true) {
handScore = 9;
return handScore;
} if (checkThreeOfKind(rankTally) === true) {
handScore = 3;
return handScore;
} if (checkTwoPair(rankTally) === true) {
handScore = 2;
return handScore;
} if (checkRoyalStraight(rankTally) === true) {
handScore = 4;
return handScore;
} if (checkStraight(rankTally) === true) {
handScore = 4;
return handScore;
} if (checkJacksOrBetter(rankTally) === true) {
handScore = 1;
return handScore;
}
handScore = 0;
return handScore;
};
Loading