Añadidos juegos

This commit is contained in:
2025-08-21 23:42:55 +02:00
parent ec9c7d8d63
commit 90b2643d8d
46 changed files with 3936 additions and 0 deletions

16
memoria/index.html Normal file
View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Juego de Memoria</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Juego de Memoria</h1>
<p>Haz clic en las cartas para darles la vuelta y encuentra las parejas.</p>
<div id="game-board"></div>
<div id="info"></div>
<button id="reset-btn">Reiniciar</button>
<script src="script.js"></script>
</body>
</html>

85
memoria/script.js Normal file
View File

@@ -0,0 +1,85 @@
const symbols = ['🍎','🍌','🍒','🍇','🍉','🍑','🍊','🍓'];
let cards = [];
let firstCard = null;
let secondCard = null;
let lockBoard = false;
let matches = 0;
const gameBoard = document.getElementById('game-board');
const infoDiv = document.getElementById('info');
const resetBtn = document.getElementById('reset-btn');
function shuffle(array) {
// Fisher-Yates shuffle
for(let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i+1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function setupBoard() {
matches = 0;
firstCard = null;
secondCard = null;
lockBoard = false;
infoDiv.textContent = '';
// Duplica los símbolos y los mezcla
cards = [...symbols, ...symbols];
shuffle(cards);
gameBoard.innerHTML = '';
cards.forEach((symbol, idx) => {
const cardEl = document.createElement('div');
cardEl.className = 'card';
cardEl.dataset.index = idx;
cardEl.dataset.symbol = symbol;
cardEl.textContent = '';
cardEl.onclick = () => flipCard(cardEl);
gameBoard.appendChild(cardEl);
});
}
function flipCard(cardEl) {
if (lockBoard) return;
if (cardEl.classList.contains('flipped') || cardEl.classList.contains('matched')) return;
cardEl.classList.add('flipped');
cardEl.textContent = cardEl.dataset.symbol;
if (!firstCard) {
firstCard = cardEl;
} else if(!secondCard && cardEl !== firstCard) {
secondCard = cardEl;
lockBoard = true;
if (firstCard.dataset.symbol === secondCard.dataset.symbol) {
// ¡Es pareja!
firstCard.classList.add('matched');
secondCard.classList.add('matched');
matches++;
resetFlipped(700);
if (matches === symbols.length) {
infoDiv.textContent = '¡Felicidades! Has encontrado todas las parejas 🎉';
}
} else {
// No es pareja, voltea las cartas después de un momento
setTimeout(() => {
firstCard.classList.remove('flipped');
secondCard.classList.remove('flipped');
firstCard.textContent = '';
secondCard.textContent = '';
resetFlipped(0);
}, 900);
}
}
}
function resetFlipped(delay) {
setTimeout(() => {
firstCard = null;
secondCard = null;
lockBoard = false;
}, delay);
}
resetBtn.onclick = setupBoard;
setupBoard();

146
memoria/styles.css Normal file
View File

@@ -0,0 +1,146 @@
/* ==== Reset y base ==== */
html {
box-sizing: border-box;
font-size: 16px;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
background: #eef2f3;
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
min-height: 100vh;
color: #364f6b;
}
/* ==== Encabezado ===== */
h1 {
margin-top: 2rem;
color: #364f6b;
font-size: clamp(1.8rem, 4vw, 2.7rem);
}
/* ==== Info & botón ==== */
#info {
font-size: clamp(1rem, 2.2vw, 1.35em);
min-height: 2em;
margin-bottom: 1.2em;
}
#reset-btn {
background: #fc5185;
color: #fff;
font-size: clamp(1em, 2vw, 1.2em);
border: none;
border-radius: 0.7rem;
padding: 0.5em 2em;
cursor: pointer;
transition: background 0.2s;
margin-bottom: 1.5em;
}
#reset-btn:hover { background: #f31349; }
/* ==== Tablero ==== */
#game-board {
margin: 2.2rem auto 1.2rem auto;
display: grid;
grid-template-columns: repeat(4, minmax(60px,1fr));
gap: 1rem;
justify-content: center;
max-width: 98vw;
}
/* ==== Tarjetas ==== */
.card {
aspect-ratio: 1 / 1;
width: 100%; /* para que rellenen su columna */
background: #3fc1c9;
color: #364f6b;
display: flex;
align-items: center;
justify-content: center;
border-radius: 0.8rem;
box-shadow: 0 2px 8px #bbb;
font-size: clamp(1.5rem, 4vw, 2.5rem);
cursor: pointer;
user-select: none;
transition: background 0.2s, color 0.2s, opacity 0.2s;
}
.card.flipped {
background: #fc5185;
color: #fff;
cursor: default;
}
.card.matched {
background: #364f6b;
color: #fff;
cursor: default;
opacity: 0.7;
}
/* ==== MÓVILES: ancho máximo y menos columnas ==== */
@media (max-width: 600px) {
h1 {
margin-top: 3vw;
font-size: clamp(1.3rem, 7vw, 2.2rem);
}
#game-board {
grid-template-columns: repeat(2, 1fr);
gap: 4vw;
margin-top: 4vw;
margin-bottom: 6vw;
padding: 2vw;
max-width: 98vw;
}
.card {
border-radius: 5vw;
font-size: clamp(1.2rem, 12vw, 2.7rem);
}
#reset-btn {
font-size: clamp(1rem, 7vw, 1.7em);
border-radius: 5vw;
padding: 3vw 12vw;
margin-bottom: 4vw;
}
#info {
font-size: clamp(1rem, 6vw, 1.4em);
}
}
/* ==== Phablets/tablets: más columnas ==== */
@media (min-width: 601px) and (max-width: 900px) {
#game-board {
grid-template-columns: repeat(3, 1fr);
gap: 2vw;
}
.card {
font-size: clamp(1.3rem, 5vw, 2.2rem);
}
}
/* ==== Pantallas grandes (>1200px): tablero más ancho ==== */
@media (min-width: 1200px) {
#game-board {
max-width: 500px;
grid-template-columns: repeat(4, 1fr);
gap: 1.5rem;
}
.card {
font-size: clamp(2rem, 2vw, 3rem);
}
}
/* ==== Extra pequeñas (<350px): modo apilado ==== */
@media (max-width: 350px) {
#game-board {
grid-template-columns: repeat(1, 1fr);
gap: 2vw;
padding: 1vw;
}
.card { font-size: clamp(1rem, 20vw, 2rem); }
}
/* ::::::::::::::::::::::::::: */