- const cardValues = ['Ace', 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two'];
- const cardSuits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'];
- // Lấy giá trị ngẫu nhiên cho bài
- cho bài
- const randomValue = cardValues[Math.floor(Math.random() * cardValues.length)];
- const randomSuit = cardSuits[Math.floor(Math.random() * cardSuits.length)];
- const randomCard = `${randomValue} of ${random// Gửi kết quả bài ngẫu nhiên cho người chơi
- ên cho người chơi
- message.reply(`Your car// Function to deal a card from the deck
- l a card from the deck
- function dealCard() {
- let card = deck.// Play the game
- d;
- }
- // Play t// Deal cards to player and dealer
- s to player and dealer
- playerHand.push(dealCard());
- dealerHand.push(dealCard());
- playerHand.push(dealCard());
- dealerH// Show player's hand and ask for hit or stand
- d ask for hit or stand
- let playerTotal = getTotal(playerHand);
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTot// Get player's decision
- Get player's decision
- let decision;
- do {
- decision = await message.channel.awaitMessages(
- (m) => m.author.id === message.author.id,
- { max: 1, time: 30000 }
- ).then((collected) => collected.first().content.toLowerCase());
- } while (!['hit', 'stand']// Player hits
- ion));
- // Player hits
- while (decision === 'hit') {
- playerHand.push(dealCard());
- playerTotal = getTotal(playerHand);
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Hit or stand?`);
- if (hasBust(playerHand)) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. You bust!`);
- break;
- }
- decision = await message.channel.awaitMessages(
- (m) => m.author.id === message.author.id,
- { max: 1, time: 30000 }
- ).then((collected) => collected.first().cont// Player stands
- );
- }
- // Player stands
- if (decision === 'stand') {
- let dealerTotal = getTotal(dealerHand);
- while (dealerTotal < 17) {
- dealerHand.push(dealCard());
- dealerTotal = getTotal(dealerHand);
- }
- if (hasBust(dealerHand)) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer busts! You win!`);
- } else {
- if (playerTotal > dealerTotal) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. You win!`);
- } else if (playerTotal < dealerTotal) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer wins!`);
- } else {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${deale// Function to deal a card from the deck
- l a card from the deck
- function dealCard() {
- let card = deck.// Play the game
- d;
- }
- // Play t// Deal cards to player and dealer
- s to player and dealer
- playerHand.push(dealCard());
- dealerHand.push(dealCard());
- playerHand.push(dealCard());
- dealerH// Show player's hand and ask for hit or stand
- d ask for hit or stand
- let playerTotal = getTotal(playerHand);
- message.reply(Your hand: ${playerHand.join(', ')}. Total: ${playerTo// Get player's decision
- Get player's decision
- let decision;
- do {
- decision = await message.channel.awaitMessages(
- (m) => m.author.id === message.author.id,
- { max: 1, time: 30000 }
- ).then((collected) => collected.first().content.toLowerCase());
- } while (!['hit', 'stand']// Player hits
- ion));
- // Player hits
- while (decision === 'hit') {
- playerHand.push(dealCard());
- playerTotal = getTotal(playerHand);
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Hit or stand?`);
- if (hasBust(playerHand)) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. You bust!`);
- break;
- }
- decision = await message.channel.awaitMessages(
- (m) => m.author.id === message.author.id,
- { max: 1, time: 30000 }
- ).then((collected) => collected.first().content.toLowerCase());
- }
- if (hasBust(dealerHand)) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer busts! You win!`);
- } else {
- if (playerTotal > dealerTotal) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. You win!`);
- } else if (playerTotal < dealerTotal) {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer wins!`);
- } else {
- message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Tie!`)
- }
- }
- }
- let playAgain;
- do {
- playAgain = await message.channel.awaitMessages(
- (m) => m.author.id === message.author.id,
- { max: 1, time: 30000 }
- ).then((collected) => collected.first().content.toLowerCase());
- } while (!['yes', 'no'].includes(playAgain));
- if (playAgain === 'no') {
- break;
- } else {
- playerHand = [];
- dealerHand = [];
- deck = [];
- for (let suit in suits) {
- for (let value in values) {
- deck.push(values[value] + ' of ' + suits[suit])
Raw Paste