coinflip game

This commit is contained in:
fred 2023-11-13 00:37:35 +01:00
parent 0a70f266c5
commit 240b8cdb31
6 changed files with 272 additions and 7 deletions

BIN
earth/coinflip/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

114
earth/coinflip/index.html Normal file
View File

@ -0,0 +1,114 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<title>Coin Flip App</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
#coin {
width: 100px;
height: 100px;
cursor: pointer;
transition: transform 0.6s ease-out; /* Transition for flipping effect */
}
</style>
<script src="/ipfs/Qmae5v9zydax9u6C9ceDijURu5PYdd5avmv4NkenCw7RFv/astro.js"></script>
</head>
<body>
<h1>Coin Flip Game</h1>
<div id="ainfo">
<img id="coin" src="/ipfs/QmYCKyYnYDGq6U7WuMmUoF7v5okvzoEThgYyKj9AzJPeP2" alt="Coin">
</div>
<div id="message"><p>Click on the coin to flip!</p></div>
<div id="countdown"></div>
<script>
// Extract the hostname (e.g., "https://ipfs.domain.tld" or "http://ipfs.localhost:8080")
var currentURL = new URL(window.location.href);
var hostname = currentURL.hostname;
var port = currentURL.port;
var protocol = currentURL.protocol.split(":")[0];
// Check and replace the port if it's 8080
if (port === "8080") {
port = "1234";
}
var zHost = hostname.replace("ipfs", "astroport");
// Create the "station" variable with the specified format
var station = protocol + "://" + zHost + (port ? (":" + port) : "");
console.log(station)
// Function to extract URL parameters
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
const results = regex.exec(location.search);
return results === null ? '' : results[1];
}
const AstroID = getUrlParameter('qrcode') || "";
const AstroPASS = getUrlParameter('pass') || "";
const G1PUB = getUrlParameter('g1pub') || "";
const MAX = getUrlParameter('max') || "";
let isFlipping = false;
let consecutiveHeads = 1;
document.getElementById('coin').addEventListener('click', (event) => {
if (!isFlipping) {
isFlipping = true;
document.getElementById('coin').style.transform = 'rotateY(360deg)';
setTimeout(() => {
const result = Math.random() < 0.5 ? 'Heads' : 'Tails';
if (result === 'Heads') {
consecutiveHeads++;
document.getElementById('coin').src = '/ipfs/QmZ6jrZGTWo4eimrGxu7BfKjYfRLqknb18WhmekNxppFg9';
document.getElementById('message').innerHTML = `<p>Pile! ${consecutiveHeads - 1} fois.</p>`;
} else {
// as descibed in https://en.wikipedia.org/wiki/St._Petersburg_paradox
// TODO : make use of MAX parameter
var vousgagnez = Math.pow(2, (consecutiveHeads - 1));
vousgagnez /= 10; // ZEN CONVERSION
// STOP CLIC
event.stopPropagation();
event.preventDefault();
var myU = station + '/?qrcode=' + AstroID +'&pass=' + AstroPASS + '&pay=' + vousgagnez + '&g1pub=' + G1PUB + '&max=' + MAX;
console.log('myU:' + myU);
document.getElementById('message').innerHTML = `<p><b>Face!<br>VOUS GAGNEZ</b><h2>${Math.pow(2, (consecutiveHeads - 1))} ZEN</h2></p>`;
consecutiveHeads = 1; // Reset the count for consecutive heads
document.getElementById('coin').src = '/ipfs/QmeZhZ6yR6YHhiZ9qfBUCA1RKUP83dZL6MtU4PCBrdzjWn'; // Coin Pile Icon
window.history.replaceState({}, document.title, "/"); // Forget Page URL in Browser History
// Astroport CALL
homeAstroportStation(myU, 'parent', 12000)
}
isFlipping = false;
document.getElementById('coin').style.transform = 'rotateY(0deg)';
}, 600); // Delay must match the transition time in CSS
}
});
</script>
</body>
</html>

View File

@ -0,0 +1 @@
ZEN MACHINE - SCAN -

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

File diff suppressed because one or more lines are too long

View File

@ -186,14 +186,24 @@ a {
</body>
<script type="text/javascript">
// Extract the hostname (e.g., "ipfs.copylaradio.com")
var hostname = window.location.hostname;
var currentURL = window.location.href;
var protocol = currentURL.split("://")[0];
var astroURL = hostname.replace("ipfs", "astroport");
var modifiedURL = astroURL.replace(":8080", ":1234");
// Extract the hostname (e.g., "https://ipfs.domain.tld" or "http://ipfs.localhost:8080")
var currentURL = new URL(window.location.href);
var hostname = currentURL.hostname;
var port = currentURL.port;
var protocol = currentURL.protocol.split(":")[0];
// Check and replace the port if it's 8080
if (port === "8080") {
port = "1234";
}
var zHost = hostname.replace("ipfs", "astroport");
// Create the "station" variable with the specified format
var station = protocol + "://" + modifiedURL;
var station = protocol + "://" + zHost + (port ? (":" + port) : "");
console.log(station)
async function fetchAstroport(myURL) {