diff --git a/3-en-raya-computer/index.html b/3-en-raya-computer/index.html new file mode 100644 index 0000000..a9f40b8 --- /dev/null +++ b/3-en-raya-computer/index.html @@ -0,0 +1,15 @@ + + +
+ +Estoy pensando en un número entre 1 y 100.
+¿Puedes adivinarlo en 7 intentos?
+ + + + +¡Prueba estos mini juegos creados por Fernando Méndez!
Elige, juega y supera tus récords.
Usa el ratón para mover el bloque. Rompe todos los ladrillos para ganar.
+ +Haz clic sobre las cartas para descubrir y encontrar las parejas.
+Haz clic en las cartas para darles la vuelta y encuentra las parejas.
+ + + + + + \ No newline at end of file diff --git a/memoria/script.js b/memoria/script.js new file mode 100644 index 0000000..8a9090e --- /dev/null +++ b/memoria/script.js @@ -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(); \ No newline at end of file diff --git a/memoria/styles.css b/memoria/styles.css new file mode 100644 index 0000000..e803b39 --- /dev/null +++ b/memoria/styles.css @@ -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); } +} + +/* ::::::::::::::::::::::::::: */ \ No newline at end of file diff --git a/piedra-papel-tijera/index.html b/piedra-papel-tijera/index.html new file mode 100644 index 0000000..56b96f5 --- /dev/null +++ b/piedra-papel-tijera/index.html @@ -0,0 +1,23 @@ + + + + +Usa las flechas arriba/abajo para mover tu pala. ¡No dejes que la bola pase!
+ + + + + + \ No newline at end of file diff --git a/pong/script.js b/pong/script.js new file mode 100644 index 0000000..95b57d0 --- /dev/null +++ b/pong/script.js @@ -0,0 +1,125 @@ +const canvas = document.getElementById('pong'); +const ctx = canvas.getContext('2d'); +const scoreDiv = document.getElementById('score'); +const restartBtn = document.getElementById('restart-btn'); + +const w = canvas.width, h = canvas.height; +const paddleHeight = 80, paddleWidth = 14; +let playerY = h/2 - paddleHeight/2, aiY = h/2 - paddleHeight/2; +let playerScore = 0, aiScore = 0; + +let ball = { + x: w/2, y: h/2, + size: 12, + speed: 5, + velX: 5, + velY: -4 +}; + +let up = false, down = false; +let running = true; + +// Dibujo de todo (juego, paletas, bola, marcador) +function draw() { + ctx.clearRect(0, 0, w, h); + ctx.fillStyle = "#f2e9e4"; + // Jugador (izq) + ctx.fillRect(16, playerY, paddleWidth, paddleHeight); + // AI (der) + ctx.fillRect(w-16-paddleWidth, aiY, paddleWidth, paddleHeight); + // Bola + ctx.beginPath(); + ctx.arc(ball.x, ball.y, ball.size, 0, 2 * Math.PI); + ctx.fillStyle = "#f6c90e"; + ctx.fill(); + // Red central + for(let i=15;iTu puntuación fue:
+ +Usa las flechas del teclado para mover la serpiente. ¡Come y crece!
+Haz clic en el topo cuando aparezca. ¡Consigue la mejor puntuación en 30 segundos!
+