Skip to content

Commit

Permalink
Create minesweeper game
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbowen committed Oct 5, 2023
1 parent 1b11bed commit e52a962
Show file tree
Hide file tree
Showing 10 changed files with 774 additions and 3 deletions.
56 changes: 56 additions & 0 deletions packages/mrwhale-core/src/data/minesweeper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { MinesweeperOptions } from "../types/minesweeper-options";

export const minesweeperLostMessages = [
"And you lost your head in the process. Tough luck mate!",
"You failed your country!",
"It took 40 days to clean up the mess.",
"Pizza tastes good. Too bad you lost your tongue... somehow.",
"*Dolphin noises*",
];

export const minesweeperWonMessages = [
"A winner is you!",
"And you only lost one arm!",
"Get some beer!",
"Momma be proud of you",
];

export const minesweeperEasy: MinesweeperOptions = {
gridXSize: 10,
gridYSize: 10,
bombCount: 10,
gameDuration: 360,
};

export const minesweeperMedium: MinesweeperOptions = {
gridXSize: 15,
gridYSize: 15,
bombCount: 20,
gameDuration: 600,
};

export const minesweeperHard: MinesweeperOptions = {
gridXSize: 20,
gridYSize: 20,
bombCount: 35,
gameDuration: 900,
};

export const minesweeperErrorMessages = {
invalidCoordinate: (prefix: string, command: string) =>
`Please provide a valid coordinate. (\`${
prefix + command
} <number> <letter>\`) \n` + `ex: \`${prefix + command} 15 c\``,
coordinateOutOfRange: () =>
"Please provide a valid coordinate. The coordinate you passed in is not on the board!",
alreadyFlaggedTile: () =>
"That tile is flagged! No revealing a flagged tile!",
alreadyRevealed: () => "That tile is already revealed!",
noGameRunning: () => "No game of minesweeper is underway.",
cantEndGame: () => "You can't end the game when no game is running.",
notGameOwner: () => "You have to be the game starter to end the game!",
gameAlreadyRunning: (prefix: string) =>
`A game of minesweeper has already started! Use \`${prefix}help minesweeper\` for more info.`,
timedOut: () => "Time's up!",
timedOutStartingNewGame: () => "Last game is timed out! Starting new game...",
};
27 changes: 27 additions & 0 deletions packages/mrwhale-core/src/helpers/minesweeper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MinesweeperGame } from "../types/minesweeper-game";
import {
minesweeperEasy,
minesweeperHard,
minesweeperMedium,
} from "../data/minesweeper";

/**
* A helper for setting up a new minesweeper game.
* @param authorId The author of the game.
* @param difficulty The difficulty of the game.
*/
export function createMinesweeperGame(
authorId: string,
difficulty: string
): MinesweeperGame {
switch (difficulty) {
case "easy":
return new MinesweeperGame(minesweeperEasy, authorId);
case "medium":
return new MinesweeperGame(minesweeperMedium, authorId);
case "hard":
return new MinesweeperGame(minesweeperHard, authorId);
}

return new MinesweeperGame(minesweeperMedium, authorId);
}
11 changes: 11 additions & 0 deletions packages/mrwhale-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ export { CommandRateLimiter } from "./client/command/command-rate-limiter";
export { levelToExp, getLevelFromExp, getRemainingExp } from "./helpers/levels";
export { HangmanGame } from "./types/hangman-game";
export { GuessingGame } from "./types/guessing-game";
export { MinesweeperGame } from "./types/minesweeper-game";
export { MinesweeperOptions } from "./types/minesweeper-options";
export { getCommandName, getCommandArgs, dispatch } from "./helpers/command";
export { createMinesweeperGame } from "./helpers/minesweeper";
export { eyes } from "./data/eyes";
export { genres, goals, items, environments, rules } from "./data/game-idea";
export {
minesweeperLostMessages,
minesweeperWonMessages,
minesweeperErrorMessages,
minesweeperEasy,
minesweeperMedium,
minesweeperHard,
} from "./data/minesweeper";
export {
bold,
code,
Expand Down
Loading

0 comments on commit e52a962

Please sign in to comment.