CHAISCRIPT   44
xidach.js
Guest on 15th March 2023 11:59:51 AM


  1. const cardValues = ['Ace', 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two'];
  2. const cardSuits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'];
  3.  
  4. // Lấy giá trị ngẫu nhiên cho bài
  5. cho bài
  6. const randomValue = cardValues[Math.floor(Math.random() * cardValues.length)];
  7. const randomSuit = cardSuits[Math.floor(Math.random() * cardSuits.length)];
  8. const randomCard = `${randomValue} of ${random// Gửi kết quả bài ngẫu nhiên cho người chơi
  9. ên cho người chơi
  10. message.reply(`Your car// Function to deal a card from the deck
  11. l a card from the deck
  12. function dealCard() {
  13. let card = deck.// Play the game
  14. d;
  15. }
  16.  
  17. // Play t// Deal cards to player and dealer
  18. s to player and dealer
  19. playerHand.push(dealCard());
  20. dealerHand.push(dealCard());
  21. playerHand.push(dealCard());
  22. dealerH// Show player's hand and ask for hit or stand
  23. d ask for hit or stand
  24. let playerTotal = getTotal(playerHand);
  25. message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTot// Get player's decision
  26.  Get player's decision
  27. let decision;
  28. do {
  29. decision = await message.channel.awaitMessages(
  30. (m) => m.author.id === message.author.id,
  31. { max: 1, time: 30000 }
  32. ).then((collected) => collected.first().content.toLowerCase());
  33. } while (!['hit', 'stand']// Player hits
  34. ion));
  35.  
  36. // Player hits
  37. while (decision === 'hit') {
  38. playerHand.push(dealCard());
  39. playerTotal = getTotal(playerHand);
  40. message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Hit or stand?`);
  41.  
  42.   if (hasBust(playerHand)) {
  43.   message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. You bust!`);
  44.   break;
  45. }
  46.  
  47. decision = await message.channel.awaitMessages(
  48.   (m) => m.author.id === message.author.id,
  49.   { max: 1, time: 30000 }
  50. ).then((collected) => collected.first().cont// Player stands
  51. );
  52. }
  53.  
  54. // Player stands
  55. if (decision === 'stand') {
  56. let dealerTotal = getTotal(dealerHand);
  57. while (dealerTotal < 17) {
  58. dealerHand.push(dealCard());
  59. dealerTotal = getTotal(dealerHand);
  60. }
  61.   if (hasBust(dealerHand)) {
  62.   message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer busts! You win!`);
  63. } else {
  64.   if (playerTotal > dealerTotal) {
  65.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. You win!`);
  66.   } else if (playerTotal < dealerTotal) {
  67.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer wins!`);
  68.   } else {
  69.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${deale// Function to deal a card from the deck
  70. l a card from the deck
  71. function dealCard() {
  72. let card = deck.// Play the game
  73. d;
  74. }
  75.  
  76. // Play t// Deal cards to player and dealer
  77. s to player and dealer
  78. playerHand.push(dealCard());
  79. dealerHand.push(dealCard());
  80. playerHand.push(dealCard());
  81. dealerH// Show player's hand and ask for hit or stand
  82. d ask for hit or stand
  83. let playerTotal = getTotal(playerHand);
  84. message.reply(Your hand: ${playerHand.join(', ')}. Total: ${playerTo// Get player's decision
  85.  Get player's decision
  86. let decision;
  87. do {
  88. decision = await message.channel.awaitMessages(
  89. (m) => m.author.id === message.author.id,
  90. { max: 1, time: 30000 }
  91. ).then((collected) => collected.first().content.toLowerCase());
  92. } while (!['hit', 'stand']// Player hits
  93. ion));
  94.  
  95. // Player hits
  96. while (decision === 'hit') {
  97. playerHand.push(dealCard());
  98. playerTotal = getTotal(playerHand);
  99. message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Hit or stand?`);
  100.  
  101. if (hasBust(playerHand)) {
  102.   message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. You bust!`);
  103.   break;
  104. }
  105.  
  106. decision = await message.channel.awaitMessages(
  107.   (m) => m.author.id === message.author.id,
  108.   { max: 1, time: 30000 }
  109. ).then((collected) => collected.first().content.toLowerCase());
  110. }
  111.  
  112.   if (hasBust(dealerHand)) {
  113.   message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer busts! You win!`);
  114. } else {
  115.   if (playerTotal > dealerTotal) {
  116.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. You win!`);
  117.   } else if (playerTotal < dealerTotal) {
  118.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Dealer wins!`);
  119.   } else {
  120.     message.reply(`Your hand: ${playerHand.join(', ')}. Total: ${playerTotal}. Dealer's hand: ${dealerHand.join(', ')}. Total: ${dealerTotal}. Tie!`)
  121.   }
  122.                 }
  123. }
  124.   let playAgain;
  125. do {
  126. playAgain = await message.channel.awaitMessages(
  127. (m) => m.author.id === message.author.id,
  128. { max: 1, time: 30000 }
  129. ).then((collected) => collected.first().content.toLowerCase());
  130. } while (!['yes', 'no'].includes(playAgain));
  131.   if (playAgain === 'no') {
  132. break;
  133. } else {
  134. playerHand = [];
  135. dealerHand = [];
  136. deck = [];
  137.     for (let suit in suits) {
  138.   for (let value in values) {
  139.     deck.push(values[value] + ' of ' + suits[suit])

Raw Paste

Login or Register to edit or fork this paste. It's free.