Customize the right-hand Minesweeper
Mine-clicks in the right-hand Minesweeper: 0
Minesweeper is a JavaScript library that defines a Javascript object Minesweeper which can be easily embedded in any web page. It depends only on the (reasonably up-to-date) JavaScript engine; no APIs nor other libraries are required.
Minesweeper is a well know game and this one follows the well-known rules as much as possible: you can click on the tiles to “visit” them and you can flag the tiles by right-clicking them. If you double-click or right-click on a tile with the number x on it (meaning it has x mines among its 8 neighbor tiles) and exactly x of its neighbors are flagged, the non-flagged fields shall be automatically “visited”. The same happens if you “visit” a tile with no mines around it.
The only differences to the standard implementations of the game are nonexistent middle-click (as some browsers have trouble coping with it, so the right- and the double-click have taken this role) and the option “Easy start” which, when turned on, makes sure that the first clicked tile will have no mines among its neighbors.
Anyone really hooked up on the game might want to visit Authoritative Minesweeper.
So, hours after getting here and playing the two Minesweepers above (yes, they are playable, not just screenshots), your curiosity probably got the best of you and you have clicked the above link. In other words, you have most likely downloaded the ZIP package and in it you will find the following marvelous things:
“Installing” this script is easy. You just need to:
And that's it! A completely functional JavaScript Minesweeper for your web page, no Flash, Java, big libraries, APIs,... no nothing! Of course, many customizations are available...
Just check the CSS file in your downloaded package and you should be fine. Also, “Inspect element” function in Firefox and Chrome might help you quite a bit (I recommend the one in Firefox, as it is visually easier and more intuitive for use).
The game offers several events you might want to use. One of them, onOpenTiles(row, col), is used on this page to display the number of “Mine-clicks in the right-hand Minesweeper” in this page, so you may check the source code of this page to see how to use this. The currently supported events are:
If you need some more, feel free to drop me a line and I might add it.
Apart from the constructor itself, there are several methods you might want to call from somewhere in your page:
Only the first seventeen billion unique visitors of this page can also get the ms-bg.zip file containing the minesweeper.pl – a PERL program which, using PerlMagick, creates random Minesweeper backgrounds (like the one used on this page).
In case you do not see this section, you're obviously not among the first seventeen billion unique visitors of this page and we wish you better luck on some less populated planet.
I needed a page to provide the download link and the basic info on the Minesweeper class. I am not charging for this or anything like it, as the purpose of both the script and the page is educational. So, I thought I'd have a bit of fun with the CSS and the background image. It's unprofessional... deliberately. Or I just suck at the web page design and am only making excuses here. You'll never know.
By the way, when was the last time you've seen a horizontal rule at the end of a web page? And what about the <address> tag? Ah, the good ol' days...