Skip to content

Commit

Permalink
fwd
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeghe committed Apr 7, 2024
1 parent 1036627 commit 9f318e3
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 1,422 deletions.
1,499 changes: 87 additions & 1,412 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1>Leonardo demos</h1>
<li><a href="monalisa/">mona lisa</a></li>
<li><a href="vitruvian/">vitruvian</a></li>
<li><a href="minefield/">minefield</a></li>
<li><a href="minefield2/">minefield 2</a></li>
<li><a href="import.html">import from string svg</a></li>
</ul>
</body>
Expand Down
1 change: 0 additions & 1 deletion source/demo/minfield.json → source/demo/minefield.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"mkdir -p demo/minefield/js demo/minefield/css"
],
"source/demo/minefield/index.js": "demo/minefield/js -vars=source/vars.json",
"source/demo/minefield/minefield.js": "demo/minefield/js -vars=source/vars.json -options=placeholderMode:'func'",
"source/demo/minefield/index.less": "demo/minefield/css -plugins=malta-less -vars=source/vars.json",
"source/demo/minefield/index.html": "demo/minefield -plugins=malta-browser-refresh -vars=source/vars.json"
}
3 changes: 1 addition & 2 deletions source/demo/minefield/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
$$../_commonHead.html$$
<title>$DEMO.MINEFIELD.TITLE$</title>
<script src="./js/minefield.js"></script>
<!-- <script src="./js/index.js"></script> -->
<script src="./js/index.js"></script>
<style>
svg{
outline: 1px solid #777 !important;
Expand Down
28 changes: 22 additions & 6 deletions source/demo/minefield/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ window.onload = function () {
var target = document.getElementById('root'),
startTime = false,
endTime = false,
levelCut = 0.8,
levelCut = 0.2,
width = 1200,
height = 1000,
tileSize = 25,
Expand Down Expand Up @@ -31,13 +31,13 @@ window.onload = function () {
return neighbours;
};

function Tile(i, j) {
function Tile(i, j, isBomb) {
var self = this;
this.i = i;
this.j = j;
this.solved = false;
this.flagged = false;
this.bomb = Math.random() > levelCut;
this.bomb = isBomb;//Math.random() > levelCut;
this.tag = L.group().setAttributes({
// fill: this.bomb ? 'gray' : color1,
fill: color1,
Expand All @@ -60,6 +60,7 @@ window.onload = function () {
'font-weight': 'bold',
'font-size': 2*tileSize/3,
});
if (this.bomb)this.txt.move(-5,0);
this.tag.append(this.tile, this.txt);
this.tag.on('contextmenu', e => {
if (self.solved) {
Expand Down Expand Up @@ -127,6 +128,8 @@ window.onload = function () {
this.tag.setAttributes({
fill: 'red'
})
this.txt.tag.innerHTML = '💥'
this.txt.move(-5,0)
};

Tile.prototype.solveNeighbours = function(){
Expand Down Expand Up @@ -167,7 +170,6 @@ window.onload = function () {
});
stats.tot = nr*nc


if (stats.flaggedBombs === stats.bombs){
endTime = +new Date;
alert(`you won in ${((endTime - startTime) / 1e3).toFixed(1)} seconds`)
Expand All @@ -193,14 +195,28 @@ window.onload = function () {
}
};

function scramble(a, n) {
var out = a
do {
out = out.sort(() => Math.random() > .5 ? 1 : -1);
} while (n--)
return out;
}
function start(){
startTime = false;
outG.clear();
// console.log({bb: outG.getBbox()});
// prerandomize bombs

var nrBombs = parseInt(nr * nc * levelCut, 10),
tls = scramble(
Array.from({length: nr*nc}, (_, i) => i < nrBombs),
3
);
console.log({nrBombs, tls});
for (var i = 0, j; i < nr; i++) {
tiles[i] = [];
for (j = 0; j < nc; j++) {
var t = new Tile(i, j);
var t = new Tile(i, j, tls[i*nc +j]);
tiles[i].push(t);
}
outG.append(tiles[i].map(t => t.tag));
Expand Down
8 changes: 8 additions & 0 deletions source/demo/minefield2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"EXE": [
"mkdir -p demo/minefield2/js demo/minefield2/css"
],
"source/demo/minefield2/index.js": "demo/minefield2/js -vars=source/vars.json -options=placeholderMode:'func'",
"source/demo/minefield2/index.less": "demo/minefield2/css -plugins=malta-less -vars=source/vars.json",
"source/demo/minefield2/index.html": "demo/minefield2 -plugins=malta-browser-refresh -vars=source/vars.json"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions source/demo/minefield2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
$$../_commonHead.html$$
<title>$DEMO.MINEFIELD2.TITLE$</title>
<script src="./js/index.js"></script>
<style>
svg{
outline: 1px solid #777 !important;
border-radius: 5px;
box-shadow: 2px 2px 5px #999;
display: flex;
text {
user-select: none
}
}
#root{
width:100vw;
height:100vh;
display:flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div id="root"/>
</body>
</html>
File renamed without changes.
52 changes: 52 additions & 0 deletions source/demo/minefield2/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@panelHeight: 80px;

body{
margin:0;
padding: 0;
font-family: verdana;
background-color: blue;
svg{
outline:1px solid white;
text {
user-select: none
}
}
.root{
// background-color: red;
}
.panel{
display:flex;
justify-content: space-between;
height: @panelHeight;
background-color: gray;
.mines{
display:flex;
background-color: aqua;
width: 100px;
display:flex;
justify-content: center;
align-items: center;
}
.facey{
display:flex;
background-color:brown;
width: 100px;
display:flex;
justify-content: center;
align-items: center;
}
.time{
display:flex;
background-color: coral;
width: 100px;
display:flex;
justify-content: center;
align-items: center;
}
}
.board{
height: calc(100vh - @panelHeight);
background-color: green;

}
}
3 changes: 2 additions & 1 deletion source/demo/require.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"source/demo/god.json": true,
"source/demo/monalisa.json": true,
"source/demo/vitruvian.json": true,
"source/demo/minfield.json": true,
"source/demo/minefield.json": true,
"source/demo/minefield2.json": true,
"source/demo/svg/*.svg": "source/demo/png -plugins=malta-svg2png"
}
3 changes: 3 additions & 0 deletions source/vars.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
},
"MINEFIELD": {
"TITLE": "Minefield"
},
"MINEFIELD2": {
"TITLE": "Minefield 2"
}
},
"SERVER": {
Expand Down

0 comments on commit 9f318e3

Please sign in to comment.