var mymap = L.map('mymap').setView([38.898913, 139.818540], 16);
var gsiLayer = L.tileLayer('https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
attribution: '国土地理院 (<a href="https://maps.gsi.go.jp/development/ichiran.html">地理院タイル</a>)'
});
var osmLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
gsiLayer.addTo(mymap);
var baseMaps = {
"国土地理院": gsiLayer,
"OpenStreetMap": osmLayer
};
L.control.layers(baseMaps).addTo(mymap);
var markers = [
L.marker([38.899003, 139.818406]),
L.marker([38.903117, 139.816343]),
L.marker([38.902537, 139.820163]),
L.marker([38.894325, 139.819551]),
L.marker([38.904011, 139.818709])
];
var currentDestination = null;
var visitedDestinations = new Set();
var totalDestinations = markers.length;
function setRandomDestination() {
if (currentDestination) {
mymap.removeLayer(currentDestination);
}
let availableMarkers = markers.filter(marker => !visitedDestinations.has(marker));
if (availableMarkers.length === 0) {
alert('おめでとうございます!全ての目的地を制覇しました!ゲームクリアです!');
resetGame();
return;
}
currentDestination = availableMarkers[Math.floor(Math.random() * availableMarkers.length)];
currentDestination.addTo(mymap);
document.getElementById('game-info').textContent = `新しい目的地が設定されました!目的地を探してクリックしてください。(${visitedDestinations.size + 1}/${totalDestinations})`;
}
markers.forEach(marker => {
marker.on('click', function(e) {
var clickedLat = e.latlng.lat.toFixed(6);
var clickedLng = e.latlng.lng.toFixed(6);
document.getElementById('game-info').textContent = `クリックした位置: (${clickedLat}, ${clickedLng})`;
if (marker === currentDestination) {
document.getElementById('janken-game').style.display = 'block';
enableJankenButtons(true);
document.getElementById('result').textContent = '';
document.getElementById('reset-button').style.display = 'none';
} else {
document.getElementById('game-info').textContent += ' - この場所は目的地ではありません。';
}
L.DomEvent.stopPropagation(e);
});
});
mymap.on('click', function(e) {
if (e.originalEvent.target.nodeName !== 'IMG') {
var clickedLat = e.latlng.lat.toFixed(6);
var clickedLng = e.latlng.lng.toFixed(6);
document.getElementById('game-info').textContent = `クリックした位置: (${clickedLat}, ${clickedLng})`;
document.getElementById('janken-game').style.display = 'none';
enableJankenButtons(false);
}
});
function enableJankenButtons(enable) {
const buttons = document.querySelectorAll('#janken-game button:not(#reset-button)');
buttons.forEach(button => {
button.disabled = !enable;
});
}
const choices = ['rock', 'paper', 'scissors'];
choices.forEach(choice => {
document.getElementById(choice).addEventListener('click', () => {
playJanken(choice);
enableJankenButtons(false);
});
});
function playJanken(playerChoice) {
const computerChoice = choices[Math.floor(Math.random() * 3)];
const outcome = getOutcome(playerChoice, computerChoice);
document.getElementById('result').textContent = `あなた: ${translateChoice(playerChoice)}, コンピュータ: ${translateChoice(computerChoice)}. ${outcome}`;
if (outcome.includes('あなたの勝ち')) {
visitedDestinations.add(currentDestination);
if (visitedDestinations.size === totalDestinations) {
setTimeout(() => {
alert('おめでとうございます!全ての目的地を制覇しました!ゲームクリアです!');
resetGame();
}, 2000);
} else {
setTimeout(() => {
setRandomDestination();
document.getElementById('janken-game').style.display = 'none';
}, 2000);
}
} else {
document.getElementById('reset-button').style.display = 'inline-block';
}
}
function getOutcome(player, computer) {
if (player === computer) return '引き分け!もう一度チャレンジしてください。';
if (
(player === 'rock' && computer === 'scissors') ||
(player === 'paper' && computer === 'rock') ||
(player === 'scissors' && computer === 'paper')
) {
return 'あなたの勝ち!おめでとう!🎉 2秒後に新しい目的地が設定されます。';
}
return 'コンピュータの勝ち!もう一度チャレンジしてください。';
}
function translateChoice(choice) {
const translations = { rock: 'グー', paper: 'パー', scissors: 'チョキ' };
return translations[choice];
}
document.getElementById('reset-button').addEventListener('click', resetJankenGame);
function resetJankenGame() {
document.getElementById('result').textContent = '';
enableJankenButtons(true);
document.getElementById('reset-button').style.display = 'none';
}
function resetGame() {
visitedDestinations.clear();
setRandomDestination();
document.getElementById('janken-game').style.display = 'none';
document.getElementById('result').textContent = '';
document.getElementById('reset-button').style.display = 'none';
}
// 初期化
resetGame();