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
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);
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);
41.
42.   if (hasBust(playerHand)) {
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') {
57. while (dealerTotal < 17) {
58. dealerHand.push(dealCard());
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) {
66.   } else if (playerTotal < dealerTotal) {
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);
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);
100.
101. if (hasBust(playerHand)) {
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) {
117.   } else if (playerTotal < dealerTotal) {
119.   } else {
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

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