ブラウザ版輪廻シミュレーション
おみくじアプリをいじってブラウザ版輪廻ゲームを書いたけど、走らせ方がわからない - おぼえがきの続き。
ちゃんと動いたけど、ワンクリックでページを表示できるような公開の仕方がわからない。
ので、ソースコードを張って置く。
index.html
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="main.css"> <title>輪廻シミュレーション</title> </head> <body> <div id="rinne"> <h1>輪廻</h1> <p id="output">あなたの来世…?</p> <button id="btn">死</button> <script src="main.js"></script> </div> </body> </html>
main.css
#rinne > #output > h2 { font-size: 30px; font-family: serif; margin: 0; text-shadow: 0 -1px 0 #222; } #rinne { text-align: center; width: 500px; background-color: #EDA; border: 3px double #990; } #rinne > h1 { color: #630; font-family: serif; font-size: 15px; font-family: serif; margin: 0; } #rinne > #output { background-color: #04A6EB; color: #FFF; margin: 10px auto; padding: 5px; } #rinne > #btn { background: #740; border: 0; color: #FFF; cursor: pointer; font-size: 20px; font-family: serif; margin: 10px auto 20px auto; padding: 5px 20px; } #rinne > #btn:hover { background: #960; } #rinne > #btn:active { background: #630; }
main.js
(function () { 'use-strict'; const spieces = ['ヒト', 'ヒグマ', 'センチニクバエ', 'ヒトスジシマカ', 'アカウシアブ', 'チャバネゴキブリ', 'チンパンジー', 'イエネコ', 'オオバコ', 'AI']; var message = ''; var random_spieces = ''; var key = 0; const btn = document.getElementById('btn'); const output = document.getElementById('output'); var deg = 0; btn.onclick = () => { if (key == 0 && Math.random() < (1 / 3)) { message = '<h2>解脱</h2>'; output.innerHTML = message; btn.remove(); return; } key = Math.floor(Math.random() * spieces.length); random_spieces = spieces[key]; message = '<h2>' + random_spieces + 'として生まれる</h2>'; output.innerHTML = message; } const rinne = document.getElementById('rinne'); function rotateGedats() { if (message == '<h2>解脱</h2>') { rinne.style.transform = 'rotateZ(' + deg + 'deg)'; deg = deg + 6; } } setInterval(rotateGedats, 20); })();