この文章より下をメモ帳アプリにコピペしてください。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>情報探索パート</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-image: url('./image/background.jpg');
background-size: cover;
background-position: center;
background-attachment: fixed;
background-color: #f4f4f4;
text-align: center;
}
h1 {
font-size: 24px;
margin: 20px 0;
}
#status {
font-size: 18px;
margin: 10px;
color: white;
}
.container {
display: flex;
flex-wrap: wrap; /* カードを折り返す */
justify-content: center; /* カードを中央揃え */
gap: 10px;
padding: 20px;
max-width: 90%;
}
.card {
flex: 0 0 auto;
width: 150px;
height: 200px;
background-image: url('./image/card.jpg');
background-size: cover;
background-position: center;
border-radius: 12px;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
color: rgb(0, 0, 0);
text-align: center;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: transform 0.3s;
}
.card:active {
transform: scale(0.95);
}
.card.flipped {
background-image: url('./image/card-2.jpg');
background-color: white;
color: rgb(255, 255, 255);
font-size: 18px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
button {
display: block;
width: 80%;
margin: 20px auto;
padding: 15px;
font-size: 18px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
text-align: center;
}
button:hover {
background-color: #0056b3;
}
button:active {
background-color: #004494;
}
#ruleOverlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
#ruleButton {
background-color: #ffffff;
color: #333;
font-size: 18px;
padding: 20px 30px;
border-radius: 8px;
cursor: pointer;
text-align: center;
}
#ruleButton:hover {
background-color: #f4f4f4;
}
</style>
</head>
<body>
<div id="ruleOverlay">
<button id="ruleButton">
【情報探索のルール】<br>
- 最大3枚までカードを引けます<br>
- カードをクリックして秘密を確認<br><br>
クリックしてゲームを開始
</button>
</div>
<h1>情報探索パート</h1>
<div id="status">証拠カードを選んでください(最大3枚)。</div>
<div class="container" id="cards"></div>
<button id="resetGame">ゲームをリセット</button>
<script>
const cardsContainer = document.getElementById('cards');
const statusDiv = document.getElementById('status');
let drawnCardsCount = 0;
// 初期カードデータ
const initialCards = [
{ id: 1, info: "カード1のヒントです。" },
{ id: 2, info: "カード2のヒントです。" },
{ id: 3, info: "カード3のヒントです。" },
{ id: 4, info: "カード4のヒントです。" },
{ id: 5, info: "カード5のヒントです。" },
{ id: 6, info: "カード6のヒントです。" }
];
// ルール画面を閉じる
const ruleOverlay = document.getElementById('ruleOverlay');
document.getElementById('ruleButton').addEventListener('click', () => {
ruleOverlay.style.display = 'none';
resetGame(); // ルール画面閉じたらゲームをリセット
});
// カードを描画
function renderCards(cards) {
cardsContainer.innerHTML = '';
cards.forEach((card, index) => {
if (card !== null) {
const cardElement = document.createElement('div');
cardElement.className = 'card';
cardElement.dataset.index = index;
cardElement.textContent = '証拠カード';
cardElement.addEventListener('click', () => handleCardClick(index));
cardsContainer.appendChild(cardElement);
}
});
}
// カードをクリック
function handleCardClick(index) {
let savedCards = JSON.parse(localStorage.getItem('cards')) || initialCards;
if (drawnCardsCount < 3 && savedCards[index]) {
const cardElement = cardsContainer.children[index];
cardElement.classList.add('flipped');
cardElement.textContent = savedCards[index].info;
savedCards[index] = null; // カードを削除(取得済み)
drawnCardsCount++;
localStorage.setItem('cards', JSON.stringify(savedCards));
} else {
statusDiv.textContent = 'すでに3枚引いています。';
}
}
// ゲームをリセット
function resetGame() {
localStorage.setItem('cards', JSON.stringify(initialCards));
drawnCardsCount = 0;
renderCards(initialCards);
statusDiv.textContent = '証拠カードを選んでください(最大3枚)。';
}
// 初期化
document.getElementById('resetGame').addEventListener('click', resetGame);
if (!localStorage.getItem('cards')) {
localStorage.setItem('cards', JSON.stringify(initialCards));
}
renderCards(JSON.parse(localStorage.getItem('cards')));
</script>
</body>
</html>