Add xyzzy to minesweeper

This commit is contained in:
Dragon Fire
2021-01-17 17:37:59 -05:00
parent 3ad416e881
commit 805a32085d
3 changed files with 16 additions and 9 deletions
+2 -2
View File
@@ -62,7 +62,6 @@
"In the `roman` command, typing \"zero\" will give you \"_nulla_\", the latin word for zero. This is because zero does not exist in roman numerals.", "In the `roman` command, typing \"zero\" will give you \"_nulla_\", the latin word for zero. This is because zero does not exist in roman numerals.",
"The `horse-race` command contains several references: real horse names, My Little Pony characters, and various pop culture jokes. Even a few Xiao jokes are snuck in there!", "The `horse-race` command contains several references: real horse names, My Little Pony characters, and various pop culture jokes. Even a few Xiao jokes are snuck in there!",
"In `horse-race`, you will occasionally encounter horses named \"Donald Trump\" and \"Dragon Fire\". Be careful, as these aren't horses, their times are based on the actual human running the race!", "In `horse-race`, you will occasionally encounter horses named \"Donald Trump\" and \"Dragon Fire\". Be careful, as these aren't horses, their times are based on the actual human running the race!",
"To this day, no one has actually tried to date Dragon Fire after using the `dating` command. Several irl friends thought the joke was funny, though.",
"The `screenshot` command uses a massive 2,000,000 entry array to check for adult sites. Some _still_ fall through the cracks.", "The `screenshot` command uses a massive 2,000,000 entry array to check for adult sites. Some _still_ fall through the cracks.",
"The `ship` command will call you a narcissist if you test yourself with yourself.", "The `ship` command will call you a narcissist if you test yourself with yourself.",
"Whenever Dragon Fire gets a real fortune cookie, he adds the fortune to the `fortune` command.", "Whenever Dragon Fire gets a real fortune cookie, he adds the fortune to the `fortune` command.",
@@ -70,5 +69,6 @@
"The `pokedex` command will play the Pokémon's cry if both you and the bot are in a voice channel when the command is used.", "The `pokedex` command will play the Pokémon's cry if both you and the bot are in a voice channel when the command is used.",
"Answers from `would-you-rather` and `will-you-press-the-button` are sent to their respective sites in order to improve their results.", "Answers from `would-you-rather` and `will-you-press-the-button` are sent to their respective sites in order to improve their results.",
"Reminders in the `remind` command have a maximum length of ~24.84 days. This is due to how JavaScript timeouts work, anything higher than this will fire early, or possibly even instantly.", "Reminders in the `remind` command have a maximum length of ~24.84 days. This is due to how JavaScript timeouts work, anything higher than this will fire early, or possibly even instantly.",
"For a very long time, `yu-gi-oh-gen` only supported Effect Monsters. `yu-gi-oh-token` was also a seperate command, and did not allow any customization outside of the image." "For a very long time, `yu-gi-oh-gen` only supported Effect Monsters. `yu-gi-oh-token` was also a seperate command, and did not allow any customization outside of the image.",
"In `minesweeper`, typing \"xyzzy\" at any point in the game will activate cheat mode, displaying where mines are on the board. No high scores can be saved in this mode, however."
] ]
+13 -6
View File
@@ -40,18 +40,20 @@ module.exports = class MinesweeperCommand extends Command {
game.onLoss = () => { win = false; }; game.onLoss = () => { win = false; };
const flagged = []; const flagged = [];
const startTime = new Date(); const startTime = new Date();
let cheatMode = false;
while (win === null) { while (win === null) {
const currentTime = moment.duration(new Date() - startTime).format('mm:ss'); const currentTime = moment.duration(new Date() - startTime).format('mm:ss');
await msg.say(stripIndents` await msg.say(stripIndents`
${msg.author}, what coordinates do you pick (ex. 4,5)? Type \`end\` to forefeit. ${msg.author}, what coordinates do you pick (ex. 4,5)? Type \`end\` to forefeit.
Type \`flag <coordinates>\` to flag a spot as a bomb. To remove a flag, run it again. Type \`flag <coordinates>\` to flag a spot as a bomb. To remove a flag, run it again.
${this.displayBoard(game.board, game.mask, flagged)} ${this.displayBoard(game.board, game.mask, flagged, cheatMode)}
**Total Mines:** ${size + 1} | **Flagged:** ${flagged.length} | **Time:** ${currentTime} **Total Mines:** ${size + 1} | **Flagged:** ${flagged.length} | **Time:** ${currentTime}
`); `);
const filter = res => { const filter = res => {
if (res.author.id !== msg.author.id) return false; if (res.author.id !== msg.author.id) return false;
const pick = res.content; const pick = res.content;
if (pick.toLowerCase() === 'xyzzy' && !cheatMode) return true;
if (pick.toLowerCase() === 'end') return true; if (pick.toLowerCase() === 'end') return true;
const coordPicked = pick.match(turnRegex); const coordPicked = pick.match(turnRegex);
if (!coordPicked) return false; if (!coordPicked) return false;
@@ -74,6 +76,11 @@ module.exports = class MinesweeperCommand extends Command {
win = false; win = false;
break; break;
} }
if (choice.toLowerCase() === 'xyzzy') {
cheatMode = true;
await msg.say('Cheat mode is now active. No high score will be saved.');
continue;
}
const coordPicked = choice.match(turnRegex); const coordPicked = choice.match(turnRegex);
const x = Number.parseInt(coordPicked[2], 10); const x = Number.parseInt(coordPicked[2], 10);
const y = Number.parseInt(coordPicked[3], 10); const y = Number.parseInt(coordPicked[3], 10);
@@ -101,7 +108,7 @@ module.exports = class MinesweeperCommand extends Command {
const highScoreGet = await this.client.redis.get(`minesweeper-${size}`); const highScoreGet = await this.client.redis.get(`minesweeper-${size}`);
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null; const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
const highScoreUser = await this.client.redis.get(`minesweeper-${size}-user`); const highScoreUser = await this.client.redis.get(`minesweeper-${size}-user`);
const scoreBeat = win && (!highScore || highScore > newScore); const scoreBeat = !cheatMode && win && (!highScore || highScore > newScore);
const user = await fetchHSUserDisplay(this.client, highScoreUser); const user = await fetchHSUserDisplay(this.client, highScoreUser);
if (scoreBeat) { if (scoreBeat) {
await this.client.redis.set(`minesweeper-${size}`, newScore); await this.client.redis.set(`minesweeper-${size}`, newScore);
@@ -123,7 +130,7 @@ module.exports = class MinesweeperCommand extends Command {
} }
} }
displayBoard(board, mask, flagged) { displayBoard(board, mask, flagged, cheatMode = false) {
let str = ''; let str = '';
str += '⬛'; str += '⬛';
str += nums.slice(0, board.length).join(''); str += nums.slice(0, board.length).join('');
@@ -131,12 +138,12 @@ module.exports = class MinesweeperCommand extends Command {
for (let i = 0; i < board.length; i++) { for (let i = 0; i < board.length; i++) {
str += nums[i]; str += nums[i];
board[i].forEach((item, j) => { board[i].forEach((item, j) => {
if (!mask || mask[i][j]) { if (cheatMode || !mask || mask[i][j]) {
if (item === '*') { if (item === '*') {
str += '💣'; str += '💣';
} else if (item === 0) { } else if (!cheatMode && item === 0) {
str += '⬜'; str += '⬜';
} else { } else if (!cheatMode) {
str += nums[item - 1]; str += nums[item - 1];
} }
} else if (flagged.includes(`${j},${i}`)) { } else if (flagged.includes(`${j},${i}`)) {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "126.6.2", "version": "126.6.3",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {