Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ module.exports = {
// Allow function param reassign for array or object elements or properties
'no-param-reassign': ['error', { props: false }],
},
};
options: {
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: false,
}],
},
};
Binary file added background/pixel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/10_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/10_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/10_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/10_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/2_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/2_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/2_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/2_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/3_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/3_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/3_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/3_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/4_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/4_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/4_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/4_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/5_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/5_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/5_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/5_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/6_of_clubs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/6_of_diamonds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/6_of_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/6_of_spades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added card_images/7_of_clubs.png
Binary file added card_images/7_of_diamonds.png
Binary file added card_images/7_of_hearts.png
Binary file added card_images/7_of_spades.png
Binary file added card_images/8_of_clubs.png
Binary file added card_images/8_of_diamonds.png
Binary file added card_images/8_of_hearts.png
Binary file added card_images/8_of_spades.png
Binary file added card_images/9_of_clubs.png
Binary file added card_images/9_of_diamonds.png
Binary file added card_images/9_of_hearts.png
Binary file added card_images/9_of_spades.png
Binary file added card_images/ace_of_clubs.png
Binary file added card_images/ace_of_diamonds.png
Binary file added card_images/ace_of_hearts.png
Binary file added card_images/ace_of_spades.png
Binary file added card_images/card_back.png
Binary file added card_images/card_empty.png
Binary file added card_images/jack_of_clubs.png
Binary file added card_images/jack_of_diamonds.png
Binary file added card_images/jack_of_hearts.png
Binary file added card_images/jack_of_spades.png
Binary file added card_images/joker_of_black.png
Binary file added card_images/joker_of_red.png
Binary file added card_images/king_of_clubs.png
Binary file added card_images/king_of_diamonds.png
Binary file added card_images/king_of_hearts.png
Binary file added card_images/king_of_spades.png
Binary file added card_images/queen_of_clubs.png
Binary file added card_images/queen_of_diamonds.png
Binary file added card_images/queen_of_hearts.png
Binary file added card_images/queen_of_spades.png
138 changes: 138 additions & 0 deletions deck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* -------------------------------------------------------------------------- */
/* create the poker deck */
/* -------------------------------------------------------------------------- */

/* ---- Get a random index ranging from 0 (inclusive) to max (exclusive). --- */
const getRandomIndex = (max) => Math.floor(Math.random() * max);

/* ------------------------ Shuffle an array of cards function ----------------------- */
const shuffleCards = (cards) => {
// Loop over the card deck array once
for (let currentIndex = 0; currentIndex < cards.length; currentIndex += 1) {
// Select a random index in the deck
const randomIndex = getRandomIndex(cards.length);
// Select the card that corresponds to randomIndex
const randomCard = cards[randomIndex];
// Select the card that corresponds to currentIndex
const currentCard = cards[currentIndex];
// Swap positions of randomCard and currentCard in the deck
cards[currentIndex] = randomCard;
cards[randomIndex] = currentCard;
}
// Return the shuffled deck
return cards;
};

/* ------------------------- get random joker color function ------------------------- */
const getRandomJokerColor = () => {
// create array of joker colors
const jokerColor = ['black', 'red'];
// get random index of joker colors in array
const randomJokerIndex = getRandomIndex(jokerColor.length);
// get random joker color from the random index
const randomJokerColor = jokerColor[randomJokerIndex];
console.log(randomJokerColor);
// return the random joker color
return randomJokerColor;
};

/* -------------------------------- make deck function ------------------------------- */
const makeDeck = () => {
// Initialise an empty deck array
const newDeck = [];
// Initialise an array of the 4 suits in our deck. We will loop over this array.
const suits = ['hearts', 'diamonds', 'clubs', 'spades'];

// joker color variable
let jokerColor;

// Loop over the suits array
for (let suitIndex = 0; suitIndex < suits.length; suitIndex += 1) {
// Store the current suit in a variable
const currentSuit = suits[suitIndex];

// Loop from 1 to 13 to create all cards for a given suit
// Notice rankCounter starts at 1 and not 0, and ends at 13 and not 12.
// This is an example of a loop without an array.
for (let rankCounter = 0; rankCounter <= 13; rankCounter += 1) {
// By default, the card name is the same as rankCounter
let cardName = `${rankCounter}`;

// If rank is 1, 11, 12, or 13, set cardName to the ace or face card's name
if (cardName === '1') {
cardName = 'ace';
} else if (cardName === '11') {
cardName = 'jack';
} else if (cardName === '12') {
cardName = 'queen';
} else if (cardName === '13') {
cardName = 'king';
// if card name is 0 change it to joker
} else if (cardName === '0') {
cardName = 'joker';
// get random joker color
jokerColor = getRandomJokerColor();
}

// Create a new card with the current name, suit, and rank
const card = {
name: cardName,
suit: currentSuit,
rank: rankCounter,
// random joker color
joker: jokerColor,
};

// Add the new card to the deck
newDeck.push(card);
}
}

// Return the completed card deck
return newDeck;
};

// create shuffled deck
const deck = shuffleCards(makeDeck());

/* --------------------------- display cover card function --------------------------- */
const coverCard = () => {
// get directory to cover card
const imgSrc = 'card_images/card_back.png';

// run a loop 5 times to display 5 cover card images
for (let i = 0; i < 5; i += 1) {
// create card image element
const coverCardImg = document.createElement('img');
// add class list to card image
coverCardImg.classList.add('card-image');
// point the card image to card cover image source
coverCardImg.src = imgSrc;

// create cover card image container element
const coverCardImgHolder = document.createElement('div');
// add class list to the cover card holder
coverCardImgHolder.classList.add('card');
// append the cover card to the image holder
coverCardImgHolder.appendChild(coverCardImg);
// append the card image holder to the card container
cardContainer.appendChild(coverCardImgHolder);
}
};

/* --------------------------- get card image url function --------------------------- */
const getCardImg = (card) => {
// create a empty variable to store image source
let imgSrc = '';

// get directory to each card
imgSrc = `./card_images/${card.name}_of_${card.suit}.png`;

// if card name is joker change directory path name
if (card.name === 'joker') {
imgSrc = `./card_images/${card.name}_of_${card.joker}.png`;
}

// return image source
return imgSrc;
};
Binary file added font/AtariClassicChunky-PxXP.ttf
Binary file not shown.
55 changes: 55 additions & 0 deletions gameplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* -------------------------- calculate hand score -------------------------- */
const calcHandScore = () => {
// run play card rank tally
playerCardRankTally();
// run play card suit tally
playerCardSuitTally();

// check winning conditions
checkFiveOfAKind();
checkRoyalFlush();
checkStraightFlush();
checkFlush();
checkStraight();
checkFullHouse();
checkFourOfAKind();
checkThreeOfAKind();
checkTwoPair();
checkPair();
checkHighCard();

// create results
createResult();
};

/* ------------------------ initiate the game function ----------------------- */
const gamePlay = () => {
// show cover cards
if (clicked === false) {
coverCard();
// deal cards
} else if (clicked === true) {
dealHand();
}
};

/* -------------------------------------------------------------------------- */
/* main function to execute game */
/* -------------------------------------------------------------------------- */
const gameInit = () => {
// build over game UI
buildBoard();
// initiate game
gamePlay();
// add game background music
playMusic();
// enable betting
enterBet();
// enable to draw cards
createDealButton();
// enable to keep cards and check results
createKeepButton();
};

// start game
gameInit();
68 changes: 68 additions & 0 deletions globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* -------------------------------------------------------------------------- */
/* global variables */
/* -------------------------------------------------------------------------- */

// containers and buttons
let boardElement;
let cardContainer;
let buttonContainer;
let pointsContainer;
let outputContainer;
let points;
let bet;
let betOne;
let betMax;

// create player hand array of 5 cards
let playerHand = [];

// array of selected cards
let selectedCards = [];

// player points
let playerPoints = Number(100);
const playerBet = [];

// player card tally
let cardRankTally = {};
let cardSuitTally = {};

// set winning hands to false
let fiveOfAKind = false;
let royalFlush = false;
let straightFlush = false;
let fourOfAKind = false;
let fullHouse = false;
let flush = false;
let straight = false;
let threeOfAKind = false;
let twoPair = false;
let onePair = false;
let highCard = false;

// ace high
let aceHigh = false;

// card scoring multiplier
const multipliers = [50, 30, 20, 10, 6, 5, 4, 3, 2, 1, 0];

// button global vars
let clicked = false;
let holdStatus = false;

// game mode
let bettingMode = true;
let dealMode = false;
let holdMode = false;

// to enable coin waterfall
let win = false;

// background game music
let myMusic;
// set audio to false to enable play and pause
let audioPlay = false;
// button click sounds
const buttonSounds = new Audio('sounds/zipclick.flac');
// select card sounds
const cardSelectSounds = new Audio('sounds/vgmenuselect.wav');
Loading