• Stars
    star
    825
  • Rank 55,281 (Top 2 %)
  • Language
    HTML
  • License
    BSD 2-Clause "Sim...
  • Created over 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MineSweeper implemented in CSS + HTML using the Space Toggle trick (no JavaScript!)

James0x57

css-sweeper from PropJockey

MineSweeper implemented in CSS + HTML using the Space Toggle trick (no JavaScript!)

PLAY IT HERE!

NOTE: this is another stress test, expect lag for the next several years of average computer advancement!

Win Condition

Since it's not practical to clear all the spaces when you expose an empty area (without loops or causing cyclic references), the win condition has been reduced to:

  1. Flag all the bombs
  2. Do not flag non-bombs
  3. Clear all non-bomb spaces

This also allows you to win when it comes down to a forced-guess since you can flag without consequence. If you pick right and haven't flagged any non-bombs, you win.

Mine Field Generation

The fields are only defined by where the bombs are (and that those spaces are not not-bombs).

The rest of the game, counter, numbers, etc flow from there, so the bombs can be placed anywhere, and in any number.

This is the (lazy/inefficient) script I ran before hand to generate the 16 included Fields:

var levels = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
var genlvl = (lvl) => {
  var y = ~~(Math.random() * 16)
  var x = ~~(Math.random() * 30)
  var key = `bomb-${y}-${x}`
  lvl[key] = `--${key}: ; --not-${key}: initial;`
}
levels.forEach(lvl => {
  while (Object.keys(lvl).length < 99) { genlvl(lvl) }
})
var cssoutput = ""
levels.forEach((lvl, i) => {
  var out = `    #level-${ i.toString(10).padStart(2, "0") }:checked ~ #ram {
      --level: "${ (i + 1).toString(10).padStart(2, "0") }";
      ${Object.values(lvl).join("\n      ")}
    }
`
  cssoutput += out
})
// cssoutput is the only css necessary to create new fields

CSS is a programming language thanks to the Space Toggle trick

Basics of Space Toggle:

  • if your --css-var holds a space --toggler: ;, then it can be added to anything (any number of times) without changing the value
      --toggler: ;
      --red-if-toggler: var(--toggler) red;
      background: var(--red-if-toggler, green); /* will be red! */
  • if your --css-var holds initial --toggler: initial; (or was never defined), then it can be added to anything to force-fallback when referenced
      --toggler: initial;
      --red-if-toggler: var(--toggler) red;
      background: var(--red-if-toggler, green); /* will be green! */
  • Space Toggles can be combined for AND logic:
      --red-if-togglersalltrue: var(--tog1) var(--tog2) var(--tog3) red;
  • Space Toggles can be combined for OR logic:
      --red-if-anytogglertrue: var(--tog1, var(--tog2, var(--tog3))) red;
  • Checkboxes (and radio buttons) make a great source for space toggles (shout out to @RockStarwind for that idea)
      #common-css-var-area { /* default any "not" values to truthy */ --not-flagged: ; }
      #mycheckbox:checked ~ #common-css-var-area { --flagged: ; --not-flagged: initial; }
      #anotherbox:checked ~ #common-css-var-area { --open: ; }
      #common-css-var-area {
        --yellow-if-flagged-and-open: var(--open) var(--flagged) yellow;
        --white-if-not-flagged-and-open: var(--open) var(--not-flagged) white;
        --red-if-flagged: var(--flagged) red;
        color: var(--yellow-if-flagged-and-open, var(--white-if-not-flagged-and-open, var(--red-if-flagged, black)))
      }
      /* color will be black if not flagged and not open */

For reference, here's where Space Toggle has been discussed recently:

Space Toggle has been independently discoverd a handful of times:

  • @anatudor probably the first to discover it - about 3 years ago!
  • @JamesOx57 in April 2020 which kickstarted development of augmented-ui v2 because it allows augs to be equipped without extra class names.
  • @DavidKPiano in June 2020 and instead of just space, he includes an empty comment --pnl: /**/; and calls it prop-and-lock

Socials

Follow me on Twitter for more web dev insanity! (and feel free to ask questions!)

More Repositories

1

augmented-ui

Cyberpunk-inspired web UI made easy. Get augmented.
CSS
1,260
star
2

css-media-vars

A brand new way to write responsive CSS. Named breakpoints, DRY selectors, no scripts, no builds, vanilla CSS.
CSS
293
star
3

DOMinion-build-demo

Demo of a build produced by a 3D CSS editor in development
HTML
115
star
4

aug-attr-spliced.js

augmented-ui plugin: adds augmented-ui attribute to elements automatically from CSS
JavaScript
96
star
5

bcd7sdd

Binary Coded Decimal 7 Segment Display Decoder implemented with CSS via the Space Toggle trick
HTML
88
star
6

css-peeps

One CSS file | One <div> | 5 Million Open Peeps combinations | Infinite Customization
28
star
7

css-conways-game-of-life

100% CSS + HTML implementation of Conway's Game of Life. 60 generation simulation @ 20x20
CSS
18
star
8

eased-gradient

generate css gradients with an easing function applied to the spectrum
JavaScript
7
star
9

css-breakout

Breakout implemented in 100% CSS
CSS
6
star
10

css-peeps-website

CSS-Peeps website
HTML
6
star
11

css-var-listener

JavaScript
5
star
12

analog-array

read values between array indexes
JavaScript
3
star
13

css-inherit-fn

--var: calc(inherit(--var, 0) + 1);
JavaScript
3
star
14

Augooiigooey

#NoCode WYSIWYG Editor for designing augmented-ui elements. Sci-Fi and CyberPunk web design has never been more accessible.
3
star
15

houdini-hud

augmented-ui implemented in Houdini with hopes of future enhancements to the paint api
JavaScript
3
star
16

propjockey

JavaScript
2
star
17

css-badge

css-only badge component
HTML
2
star
18

propjockey.io

CSS
2
star
19

css-bin-bits

a vanilla CSS API for binary operations and bit manipulation of 16 bit numbers
CSS
2
star
20

propjockey-brand

PropJockey pngs, svgs, favicons, and more
CSS
2
star
21

houdini-hud-website

documentation website for houdini-hud
JavaScript
1
star
22

aug-compile

Get the most out of your runtime performance by compiling static augmented-ui configurations up front
JavaScript
1
star
23

propgun

PropJokey propgun - generate a function from position:value pairs that takes t [0, 1] and returns the corresponding tween value.
JavaScript
1
star
24

css-screensize

Capture CSS <number> vars for screen --width and --height. 100% CSS, Zero JS
CSS
1
star
25

ezLight

The easiest, Zero-Build, way to set up your light & dark CSS themes with an expressive list of classes automatically available ~
1
star
26

nth-vars.css

CSS --nth-child & --nth-of-type variables for every element πŸŽ‰
CSS
1
star