diff --git a/hokaku.js b/hokaku.js index b67711c..34ef856 100644 --- a/hokaku.js +++ b/hokaku.js @@ -3,25 +3,16 @@ document.addEventListener("DOMContentLoaded", () => { - // ========================= - // 定数 - // ========================= const START_POS = [38.891, 139.824]; - const CAPTURE_DISTANCE = 30; // m - const NEAR_DISTANCE = 100; // m - const CAPTURE_RATE = 0.7; // 捕獲成功率 + const CAPTURE_DISTANCE = 30; + const NEAR_DISTANCE = 100; + const CAPTURE_RATE = 0.7; - // ========================= - // DOM - // ========================= const titleEl = document.getElementById("title"); const startBtn = document.getElementById("start"); const stopBtn = document.getElementById("stop"); const captureBtn = document.getElementById("capture"); - // ========================= - // 状態 - // ========================= let map; let playerMarker; let monsterMarker = null; @@ -31,9 +22,6 @@ let nTrial = 100; let canCapture = false; - // ========================= - // Map 初期化 - // ========================= function initMap() { map = L.map("locationmap", { tap: true }) .setView(START_POS, 16); @@ -46,15 +34,11 @@ playerMarker = L.marker(map.getCenter()).addTo(map); playerMarker.bindPopup("STARTを押して探索開始").openPopup(); - // ✅ ここで click を登録する map.on("click", (e) => { updateLocation(e.latlng); }); } - // ========================= - // モンスター生成 - // ========================= function spawnMonster(center) { const offsetLat = (Math.random() - 0.5) * 0.002; const offsetLng = (Math.random() - 0.5) * 0.002; @@ -73,9 +57,6 @@ }).addTo(map); } - // ========================= - // 位置更新 - // ========================= function updateLocation(latlng) { map.panTo(latlng); playerMarker.setLatLng(latlng); @@ -103,9 +84,6 @@ playerMarker.setPopupContent(message).openPopup(); } - // ========================= - // 捕獲処理 - // ========================= function captureMonster() { if (!canCapture || !monsterLatLng) return; @@ -125,9 +103,6 @@ captureBtn.disabled = true; } - // ========================= - // GPS - // ========================= function onSuccess(pos) { updateLocation( L.latLng(pos.coords.latitude, pos.coords.longitude) @@ -166,16 +141,11 @@ } } - // ========================= - // イベント - // ========================= startBtn.addEventListener("click", startWatch); stopBtn.addEventListener("click", stopWatch); captureBtn.addEventListener("click", captureMonster); - // ========================= - // 起動 - // ========================= + initMap(); });