Update index.html
Browse files- index.html +151 -78
index.html
CHANGED
|
@@ -1,95 +1,168 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</head>
|
| 20 |
<body>
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
document.getElementById("status").innerText = "Searching for a player...";
|
| 44 |
-
document.getElementById("find-match-btn").disabled = true;
|
| 45 |
-
socket.emit("findMatch");
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
// When server pairs two players together
|
| 49 |
-
socket.on("matchFound", (data) => {
|
| 50 |
-
roomId = data.roomId;
|
| 51 |
-
document.getElementById("status").innerText = "Match Found! Room ID: " + roomId;
|
| 52 |
-
|
| 53 |
-
// Hide lobby screen, show game screen
|
| 54 |
-
document.getElementById("lobby").style.display = "none";
|
| 55 |
-
document.getElementById("game-area").style.display = "block";
|
| 56 |
-
|
| 57 |
-
if(data.isPlayer2) {
|
| 58 |
-
document.getElementById("remote-player").style.display = "block";
|
| 59 |
-
}
|
| 60 |
-
});
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
remote.style.left = pos.left + "px";
|
| 86 |
-
});
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
</body>
|
| 94 |
-
</html>
|
| 95 |
-
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>DarkWard</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root{--ink:#120f1f;--slab:#1d1833;--line:#352b57;--bone:#efe9dc;--mute:#9a91b8;--ember:#ff6b3d;--wraith:#7be0d0}
|
| 9 |
+
*{box-sizing:border-box}
|
| 10 |
+
body{margin:0;min-height:100vh;background:radial-gradient(ellipse at 50% -10%,#35205f,var(--ink) 62%);color:var(--bone);font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;padding:22px 14px}
|
| 11 |
+
h1{font-family:Georgia,serif;font-weight:400;font-size:2.2rem;letter-spacing:.12em;margin:6px 0 2px}
|
| 12 |
+
.tag{color:var(--mute);font-size:.85rem;margin:0 0 20px}
|
| 13 |
+
.card{background:var(--slab);border:1px solid var(--line);border-radius:6px;padding:20px;width:100%;max-width:400px}
|
| 14 |
+
[hidden]{display:none!important}
|
| 15 |
+
.row{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px;font-size:.9rem;color:var(--mute)}
|
| 16 |
+
.row b{color:var(--bone)}
|
| 17 |
+
label{font-size:.85rem;color:var(--mute)}
|
| 18 |
+
input{width:100%;margin:6px 0 16px;padding:11px;background:var(--ink);border:1px solid var(--line);border-radius:4px;color:var(--bone);font-size:1rem}
|
| 19 |
+
input:focus,button:focus-visible{outline:2px solid var(--wraith);outline-offset:2px}
|
| 20 |
+
button{background:var(--ember);color:#1a0d08;border:0;border-radius:4px;padding:12px 18px;font-size:1rem;font-weight:700;cursor:pointer}
|
| 21 |
+
.full{width:100%}
|
| 22 |
+
#msg{margin:12px 0 0;color:var(--mute);font-size:.9rem;min-height:1.2em}
|
| 23 |
+
#arena{width:100%;max-width:400px;text-align:center}
|
| 24 |
+
#field{position:relative;width:360px;height:360px;margin:12px auto;background:#0b0914;border:1px solid var(--line);background-image:linear-gradient(var(--line) 1px,transparent 1px),linear-gradient(90deg,var(--line) 1px,transparent 1px);background-size:30px 30px}
|
| 25 |
+
.p{position:absolute;width:30px;height:30px;border-radius:50%;background:var(--ember);top:165px;left:165px;transition:top .1s linear,left .1s linear}
|
| 26 |
+
.p.me{background:var(--wraith);z-index:2}
|
| 27 |
+
.p span{position:absolute;bottom:32px;left:50%;transform:translateX(-50%);font-size:.68rem;white-space:nowrap}
|
| 28 |
+
.pad{display:grid;grid-template-columns:repeat(3,56px);gap:6px;justify-content:center;margin:10px 0}
|
| 29 |
+
.pad button{padding:0;height:52px;background:var(--slab);color:var(--bone);border:1px solid var(--line)}
|
| 30 |
+
.pad .u{grid-column:2}.pad .l{grid-column:1;grid-row:2}.pad .d{grid-column:2;grid-row:2}.pad .r{grid-column:3;grid-row:2}
|
| 31 |
+
#toast{position:fixed;top:16px;left:50%;transform:translateX(-50%);background:var(--bone);color:#1a0d08;padding:11px 18px;border-radius:4px;font-weight:700;z-index:9}
|
| 32 |
+
#adminLink{margin-top:26px;background:none;border:0;color:var(--mute);font-weight:400;font-size:.8rem;text-decoration:underline}
|
| 33 |
+
#admin{margin-top:16px;max-width:400px;width:100%}
|
| 34 |
+
table{width:100%;border-collapse:collapse;font-size:.85rem;margin:10px 0}
|
| 35 |
+
td{padding:7px 4px;border-bottom:1px solid var(--line)}
|
| 36 |
+
td button{padding:5px 10px;font-size:.8rem;background:#b3262d;color:#fff}
|
| 37 |
+
.tools{display:flex;gap:8px;margin-bottom:8px}.tools input{margin:0}
|
| 38 |
+
.tools button{white-space:nowrap;padding:10px 12px;font-size:.9rem}
|
| 39 |
+
</style>
|
| 40 |
</head>
|
| 41 |
<body>
|
| 42 |
+
<h1>DarkWard</h1>
|
| 43 |
+
<p class="tag">One open arena. Pick a name and walk in.</p>
|
| 44 |
|
| 45 |
+
<div id="join" class="card">
|
| 46 |
+
<div class="row"><span>Coins: <b id="coins">0</b></span></div>
|
| 47 |
+
<label for="name">Your name</label>
|
| 48 |
+
<input id="name" maxlength="14" autocomplete="off">
|
| 49 |
+
<button id="enter" class="full">Enter arena</button>
|
| 50 |
+
<p id="msg"></p>
|
| 51 |
+
</div>
|
| 52 |
|
| 53 |
+
<div id="arena" hidden>
|
| 54 |
+
<div class="row"><span>In arena: <b id="count">0</b></span><span>Coins: <b id="coins2">0</b></span></div>
|
| 55 |
+
<div id="field"></div>
|
| 56 |
+
<div class="pad">
|
| 57 |
+
<button class="u" data-d="u" aria-label="Up">▲</button>
|
| 58 |
+
<button class="l" data-d="l" aria-label="Left">◀</button>
|
| 59 |
+
<button class="d" data-d="d" aria-label="Down">▼</button>
|
| 60 |
+
<button class="r" data-d="r" aria-label="Right">▶</button>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
|
| 64 |
+
<button id="adminLink">Host panel</button>
|
| 65 |
+
<div id="admin" class="card" hidden>
|
| 66 |
+
<div id="login">
|
| 67 |
+
<label for="pass">Host password</label>
|
| 68 |
+
<input id="pass" type="password">
|
| 69 |
+
<button id="loginBtn" class="full">Sign in</button>
|
| 70 |
+
</div>
|
| 71 |
+
<div id="panel" hidden>
|
| 72 |
+
<div class="tools">
|
| 73 |
+
<input id="giftAmt" type="number" min="1" value="100" aria-label="Gift amount">
|
| 74 |
+
<button id="giftBtn">Gift all</button>
|
| 75 |
</div>
|
| 76 |
+
<div class="tools">
|
| 77 |
+
<input id="botAmt" type="number" min="1" max="26" value="5" aria-label="Fake players">
|
| 78 |
+
<button id="botBtn">Add fake players</button>
|
| 79 |
+
<button id="botClr" style="background:var(--line);color:var(--bone)">Clear</button>
|
| 80 |
+
</div>
|
| 81 |
+
<table id="plist"></table>
|
| 82 |
+
</div>
|
| 83 |
+
</div>
|
| 84 |
|
| 85 |
+
<script src="/socket.io/socket.io.js"></script>
|
| 86 |
+
<script>
|
| 87 |
+
const $ = (id) => document.getElementById(id);
|
| 88 |
+
const socket = io();
|
| 89 |
+
const els = new Map();
|
| 90 |
+
let joined = false, pos = { top: 165, left: 165 }, coins = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
function toast(msg) {
|
| 93 |
+
const t = document.createElement('div');
|
| 94 |
+
t.id = 'toast'; t.textContent = msg; document.body.appendChild(t);
|
| 95 |
+
setTimeout(() => t.remove(), 3000);
|
| 96 |
+
}
|
| 97 |
+
function setCoins(n) { coins = n; $('coins').textContent = n; $('coins2').textContent = n; }
|
| 98 |
|
| 99 |
+
socket.on('you', (d) => { $('name').value = d.name; setCoins(d.coins); });
|
| 100 |
+
$('enter').onclick = () => socket.emit('join', $('name').value);
|
| 101 |
+
socket.on('full', () => { $('msg').textContent = 'The arena is full. Try again in a minute.'; });
|
| 102 |
+
socket.on('joined', () => { joined = true; $('join').hidden = true; $('arena').hidden = false; });
|
| 103 |
|
| 104 |
+
socket.on('state', (list) => {
|
| 105 |
+
if (!joined) return;
|
| 106 |
+
const seen = new Set();
|
| 107 |
+
list.forEach((p) => {
|
| 108 |
+
seen.add(p.id);
|
| 109 |
+
let e = els.get(p.id);
|
| 110 |
+
if (!e) {
|
| 111 |
+
e = document.createElement('div'); e.className = 'p';
|
| 112 |
+
e.appendChild(document.createElement('span'));
|
| 113 |
+
$('field').appendChild(e); els.set(p.id, e);
|
| 114 |
+
if (p.id === socket.id) { e.classList.add('me'); pos = { top: p.top, left: p.left }; }
|
| 115 |
+
}
|
| 116 |
+
e.firstChild.textContent = p.name;
|
| 117 |
+
if (p.id !== socket.id) { e.style.top = p.top + 'px'; e.style.left = p.left + 'px'; }
|
| 118 |
+
});
|
| 119 |
+
els.forEach((e, id) => { if (!seen.has(id)) { e.remove(); els.delete(id); } });
|
| 120 |
+
$('count').textContent = list.length;
|
| 121 |
+
});
|
| 122 |
|
| 123 |
+
function move(dir) {
|
| 124 |
+
if (!joined) return;
|
| 125 |
+
if (dir === 'u') pos.top -= 10;
|
| 126 |
+
if (dir === 'd') pos.top += 10;
|
| 127 |
+
if (dir === 'l') pos.left -= 10;
|
| 128 |
+
if (dir === 'r') pos.left += 10;
|
| 129 |
+
pos.top = Math.max(0, Math.min(330, pos.top));
|
| 130 |
+
pos.left = Math.max(0, Math.min(330, pos.left));
|
| 131 |
+
const me = els.get(socket.id);
|
| 132 |
+
if (me) { me.style.top = pos.top + 'px'; me.style.left = pos.left + 'px'; }
|
| 133 |
+
socket.emit('move', pos);
|
| 134 |
+
}
|
| 135 |
+
const keys = { ArrowUp: 'u', ArrowDown: 'd', ArrowLeft: 'l', ArrowRight: 'r' };
|
| 136 |
+
addEventListener('keydown', (e) => { if (keys[e.key] && joined) { e.preventDefault(); move(keys[e.key]); } });
|
| 137 |
+
document.querySelectorAll('.pad button').forEach((b) => {
|
| 138 |
+
b.addEventListener('pointerdown', (e) => { e.preventDefault(); move(b.dataset.d); });
|
| 139 |
+
});
|
| 140 |
|
| 141 |
+
socket.on('gift', (d) => { setCoins(d.coins); toast('Gift received: +' + d.amount + ' coins'); });
|
| 142 |
+
socket.on('kicked', () => {
|
| 143 |
+
document.body.innerHTML = '<h1>DarkWard</h1><p class="tag">The host removed you from the arena. Reload the page to join again.</p>';
|
| 144 |
+
});
|
|
|
|
|
|
|
| 145 |
|
| 146 |
+
// ---- Host panel ----
|
| 147 |
+
$('adminLink').onclick = () => { $('admin').hidden = !$('admin').hidden; };
|
| 148 |
+
$('loginBtn').onclick = () => socket.emit('adminLogin', $('pass').value);
|
| 149 |
+
socket.on('adminFail', () => toast('Wrong host password.'));
|
| 150 |
+
socket.on('adminOk', () => { $('login').hidden = true; $('panel').hidden = false; });
|
| 151 |
+
$('giftBtn').onclick = () => socket.emit('giftAll', $('giftAmt').value);
|
| 152 |
+
$('botBtn').onclick = () => socket.emit('addBots', $('botAmt').value);
|
| 153 |
+
$('botClr').onclick = () => socket.emit('clearBots');
|
| 154 |
+
socket.on('players', (list) => {
|
| 155 |
+
const t = $('plist'); t.textContent = '';
|
| 156 |
+
list.filter((p) => p.joined).forEach((p) => {
|
| 157 |
+
const tr = t.insertRow();
|
| 158 |
+
tr.insertCell().textContent = p.name;
|
| 159 |
+
tr.insertCell().textContent = p.bot ? 'fake' : p.coins + ' coins';
|
| 160 |
+
const c = tr.insertCell(), b = document.createElement('button');
|
| 161 |
+
b.textContent = 'Kick';
|
| 162 |
+
b.onclick = () => socket.emit('kick', p.id);
|
| 163 |
+
c.appendChild(b);
|
| 164 |
+
});
|
| 165 |
+
});
|
| 166 |
+
</script>
|
| 167 |
</body>
|
| 168 |
+
</html>
|
|
|