Skip to content

Commit

Permalink
feat: add Minesweeper channel (#23)
Browse files Browse the repository at this point in the history
* feat:add Minesweeper channel

* refactor createTileCluster to simplify logic

* Add credit, store grid state in persistent replicant, grab event name from currentEvent object

* Add question marks at random intervals

* Change to heart eyes face on donation event

* remove tile reveal decay in favor of minimum tile reveal threshold to make tile revealing a bit more realistic
  • Loading branch information
rshigg authored Jan 12, 2024
1 parent 95f7f7b commit 83b952f
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/assets/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@
@font-face {
font-family: Reactor7;
src: url('fonts/Reactor7.ttf') format('truetype');
}
}

@font-face {
font-family: minesweeper;
src: url('fonts/Minesweeper.woff2') format('woff2');
}
Binary file added src/assets/fonts/Minesweeper.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions src/channels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ import './dragon-warrior';
import './ff-shop';
import './template';
import './papers-please';
import './minesweeper';

export * from './channels';
29 changes: 29 additions & 0 deletions src/channels/minesweeper/Face.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { css } from '@emotion/react';
import { FACE_DIMENSION, FACE_ORDER } from './constants';

import faces from './assets/faces.png';

export type FaceType = (typeof FACE_ORDER)[number];

function getFaceOffset(face: FaceType) {
const faceIndex = FACE_ORDER.indexOf(face);
return faceIndex * FACE_DIMENSION;
}

type FaceProps = {
face: FaceType;
};

export function Face({ face }: FaceProps) {
return (
<div
css={css`
transform: scale(1.25);
width: ${FACE_DIMENSION}px;
height: ${FACE_DIMENSION}px;
background: url(${faces}) no-repeat;
background-position: -${getFaceOffset(face)}px;
`}
/>
);
}
25 changes: 25 additions & 0 deletions src/channels/minesweeper/Tile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { css } from '@emotion/react';
import { TILE_DIMENSION } from './constants';

import tiles from './assets/tiles.png';

export type TileData = {
id: string;
tileType: readonly [number, number];
isMine: boolean;
};

export function Tile({ tileType }: TileData) {
const [x, y] = tileType;

return (
<div
css={css`
width: 16px;
height: 16px;
background: url(${tiles}) no-repeat;
background-position: -${x * TILE_DIMENSION}px -${y * TILE_DIMENSION}px;
`}
/>
);
}
Binary file added src/channels/minesweeper/assets/faces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/channels/minesweeper/assets/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/channels/minesweeper/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const FACE_DIMENSION = 24;
export const FACE_ORDER = ['smile', 'smile_pressed', 'open_mouth', 'sunglasses', 'heart_eyes'] as const;

export const MINE_CHANCE = 0.17;

export const GRID_ROWS = 16;
export const GRID_COLUMNS = 67;

export const TILE_DIMENSION = 16;

export const TILE_MAP = {
HIDDEN: [0, 0],
ONE: [0, 1],
TWO: [1, 1],
THREE: [2, 1],
FOUR: [3, 1],
FIVE: [4, 1],
SIX: [5, 1],
SEVEN: [6, 1],
EIGHT: [7, 1],
EMPTY: [1, 0],
FLAGGED: [2, 0],
QUESTION_MARK: [3, 0],
} as const;

export const mineNumberTiles = [
TILE_MAP.EMPTY,
TILE_MAP.ONE,
TILE_MAP.TWO,
TILE_MAP.THREE,
TILE_MAP.FOUR,
TILE_MAP.FIVE,
TILE_MAP.SIX,
TILE_MAP.SEVEN,
TILE_MAP.EIGHT,
];

export const MIN_REVEAL_DONATION = 20;
/** maximum donation amount for determining reveal threshold */
export const REVEAL_DONATION_CAP = 500;
export const MIN_REVEALED_TILES = 1;
export const MAX_REVEALED_TILES = 25;
Loading

0 comments on commit 83b952f

Please sign in to comment.