Skip to content
Merged
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
21 changes: 13 additions & 8 deletions src/commands/fun/blackjack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class extends Command {
let gameStatus = "Click 'Hit' to draw or 'Stand' to pass";
let gameOver = false;
let win = false;
let tie = false;

// Accounts for two aces drawn at the start, going over 21
if (playerHand === 22) {
Expand All @@ -53,10 +54,12 @@ export default class extends Command {
.setFooter({ text: status });

// Color of the embed on the left changes depending on if it's game over or not
if (gameOver && !win) {
if (gameOver && !win && !tie) {
embed.setColor('Red');
} else if (gameOver && win) {
embed.setColor('Green');
} else if (gameOver && !win && tie) {
embed.setColor('Grey');
} else {
embed.setColor('Blue');
}
Expand Down Expand Up @@ -167,7 +170,7 @@ export default class extends Command {
components: []
});

// Allows user to read game status before continuing
// Allows user to read game status before continuing (1.5 seconds)
await wait(1500);

dealerDrawnCard = Math.floor(Math.random() * 13);
Expand Down Expand Up @@ -200,7 +203,7 @@ export default class extends Command {
});

// Keeps hitting if below 17 point threshold
while (dealerHand <= 16 && dealerHand < playerHand) {
while (dealerHand <= 16 && dealerHand <= playerHand) {
// Allows user to read game status before continuing
await wait(1500);
dealerDrawnCard = Math.floor(Math.random() * 13);
Expand Down Expand Up @@ -295,7 +298,7 @@ export default class extends Command {
{
name: 'Winning',
value: 'The player who doesn\'t bust and has the most points wins!\n' +
'Ties: The dealer automatically wins ties.'
'Ties: When both players have the same score, no one wins.\n'
}
);

Expand All @@ -317,8 +320,7 @@ export default class extends Command {
await i.reply({
content: 'Failed to send you a DM. Here are the rules: \n\n',
embeds: [rulesEmbed],
// eslint-disable-next-line no-mixed-spaces-and-tabs
ephemeral: true
ephemeral: true
});
}
}
Expand All @@ -343,11 +345,14 @@ export default class extends Command {
gameStatus = 'Game timed out.';
} else if (reason === 'stand') {
// Tells user who had the higher points
if (dealerHand >= playerHand) {
if (dealerHand > playerHand) {
gameStatus = 'Sage wins.';
} else {
} else if (dealerHand < playerHand) {
gameStatus = 'You win!';
win = true;
} else if (dealerHand === playerHand) {
gameStatus = 'You tied.';
tie = true;
}
}

Expand Down
Loading