Frontend Forever App
We have a mobile app for you to download and use. And you can unlock many features in the app.
Get it now
Intall Later
Run
HTML
CSS
Javascript
Output
Document
To win, either get
all
zeros
, or all
zeros
,
-1
and
1
.
Left click (pull) - add 2, subtract 1 from each neighbor
Right click (push) - subtract 2, add 1 to each neighbor
1
-8
5
7
-2
-3
Play again
@charset "UTF-8"; @import url(https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800); *, :after, :before { box-sizing: border-box; padding: 0; margin: 0; } body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #232b2b; margin: 0; gap: 10px; font-family: Arial, Helvetica, sans-serif; color: #fff; } .center { display: flex; justify-content: center; align-items: center; } .zeros { color: rgb(180, 180, 180); } #negone { color: rgb(255, 128, 128); } #one { color: rgb(128, 255, 128); } .container { } .triangle { stroke: #000; /* fill: #7f7ddb; */ stroke-width: 1px; cursor: pointer; } .triangle-text:hover { cursor: pointer; } .triangle-text { fill: #fff; font-size: 3em; paint-order: stroke; stroke: #000; stroke-width: 2px; stroke-linecap: butt; stroke-linejoin: miter; } .btn { font-size: 2em; padding: 10px; border-radius: 10px; border: none; background-color: #ffec5e; cursor: pointer; } .btn:hover { background-color: #fff6b5; } .btn:active { background-color: #ffec5e; } #play-again { opacity: 0; transition: 200ms ease-in-out; } .lower-left { fill: hsl(120deg 10% 50%); } .upper-left { fill: hsl(0deg 80% 50%); } .upper-middle { fill: hsl(120deg 50% 50%); } .upper-right { fill: hsl(120deg 70% 50%); } .lower-right { fill: hsl(0deg 20% 50%); } .lower-middle { fill: hsl(0deg 30% 50%); }
console.log("Event Fired") let triangles = document.getElementsByClassName("triangle"); let triangleText = document.getElementsByClassName("triangle-text"); let playAgainButton = document.getElementById("play-again"); let triangleValues = Array(triangles.length); const maxValue = 9; let triangleLighten = Array(triangles.length); playAgainButton.onclick = () => { resetTriangleValues(); renderTriangles(); playAgainButton.style.opacity = "0"; }; document.addEventListener("contextmenu", (e) => { e.preventDefault(); }); for (let i = 0; i < triangles.length; i++) { triangleLighten[i] = 0; triangles[i].addEventListener("mouseover", (e) => { triangleLighten[i] = 20; renderTriangles(); }); triangles[i].addEventListener("mouseout", (e) => { triangleLighten[i] = 0; renderTriangles(); }); triangles[i].addEventListener("mousedown", (e) => { triangleLighten[i] = 10; renderTriangles(); addTriangle(i, e.button); }); triangles[i].addEventListener("mouseup", (e) => { triangleLighten[i] = 20; renderTriangles(); }); triangleText[i].addEventListener("mouseover", (e) => { triangleLighten[i] = 20; renderTriangles(); }); triangleText[i].addEventListener("mouseout", (e) => { triangleLighten[i] = 0; renderTriangles(); }); triangleText[i].addEventListener("mousedown", (e) => { triangleLighten[i] = 10; renderTriangles(); addTriangle(i, e.button); let allInRange = triangleValues.every((num) => num >= -1 && num <= 1); if (allInRange) { playAgainButton.style.opacity = "1"; } }); triangleText[i].addEventListener("mouseup", (e) => { triangleLighten[i] = 20; renderTriangles(); }); } resetTriangleValues(); renderTriangles(); function addTriangle(index, button) { let neighborLeft = (index + 5) % 6; let neighborRight = (index + 1) % 6; if (button == 0) { triangleValues[neighborLeft] -= 1; triangleValues[neighborRight] -= 1; triangleValues[index] += 2; } if (button == 2) { triangleValues[neighborLeft] += 1; triangleValues[neighborRight] += 1; triangleValues[index] -= 2; } } function resetTriangleValues() { let sum = 0; for (let i = 0; i < triangles.length - 1; i++) { triangleValues[i] = randomInt(maxValue * 2 + 1) - maxValue; sum += triangleValues[i]; triangleText[i].innerHTML = triangleValues[i]; } triangleValues[5] = -sum; if (triangleValues[5] > 9 || triangleValues[5] < -9) { return resetTriangleValues(); } } function renderTriangles() { for (let i = 0; i < triangles.length; i++) { triangleText[i].innerHTML = triangleValues[i]; let textX = triangleText[i].getAttribute("x"); console.log(textX); if (triangleValues[i] == 0) { triangles[i].style.fill = `hsl(60deg 0.2 ${50 + triangleLighten[i]}%)`; triangleText[i].setAttribute("transform", `translate(${10}, ${0})`); } if (triangleValues[i] > 0) { triangles[i].style.fill = `hsl(120deg ${ (triangleValues[i] / maxValue) * 100 }% ${50 + triangleLighten[i]}%)`; triangleText[i].setAttribute("transform", `translate(${10}, ${0})`); } if (triangleValues[i] < 0) { triangles[i].style.fill = `hsl(0deg ${ (Math.abs(triangleValues[i]) / maxValue) * 100 }% ${50 + triangleLighten[i]}%)`; } } } function randomInt(max) { return Math.floor(Math.random() * max); }