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

20
simon-dice/index.html Normal file
View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Simon Dice</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Simon Dice</h1>
<div id="game-container">
<div class="color-btn" id="green"></div>
<div class="color-btn" id="red"></div>
<div class="color-btn" id="yellow"></div>
<div class="color-btn" id="blue"></div>
</div>
<div id="status"></div>
<button id="start-btn">Empezar</button>
<script src="script.js"></script>
</body>
</html>

66
simon-dice/script.js Normal file
View File

@@ -0,0 +1,66 @@
const colors = ['green', 'red', 'yellow', 'blue'];
let sequence = [];
let playerSequence = [];
let level = 0;
let waitingInput = false;
const statusDiv = document.getElementById('status');
const startBtn = document.getElementById('start-btn');
colors.forEach(color => {
document.getElementById(color).onclick = () => handleColorClick(color);
});
startBtn.onclick = startGame;
function startGame() {
sequence = [];
playerSequence = [];
level = 0;
statusDiv.textContent = '';
nextLevel();
}
function nextLevel() {
level++;
statusDiv.textContent = `Nivel ${level}`;
playerSequence = [];
sequence.push(colors[Math.floor(Math.random() * 4)]);
showSequence(0);
}
function showSequence(idx) {
waitingInput = false;
if (idx < sequence.length) {
const color = sequence[idx];
flashColor(color);
setTimeout(() => showSequence(idx + 1), 700);
} else {
setTimeout(() => {
waitingInput = true;
statusDiv.textContent = `Tu turno (Nivel ${level})`;
}, 400);
}
}
function flashColor(color) {
const el = document.getElementById(color);
el.classList.add('active');
setTimeout(() => el.classList.remove('active'), 400);
}
function handleColorClick(color) {
if (!waitingInput) return;
playerSequence.push(color);
flashColor(color);
const idx = playerSequence.length - 1;
if (color !== sequence[idx]) {
statusDiv.textContent = `¡Fallaste! Llegaste al nivel ${level}.`;
waitingInput = false;
return;
}
if (playerSequence.length === sequence.length) {
waitingInput = false;
setTimeout(nextLevel, 900);
}
}

136
simon-dice/styles.css Normal file
View File

@@ -0,0 +1,136 @@
html {
box-sizing: border-box;
font-size: 16px;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
background: #e1f5fe;
font-family: Arial, sans-serif;
text-align: center;
color: #222;
margin: 0;
min-height: 100vh;
}
/* Encabezado */
h1 {
margin-top: 2rem;
color: #01579b;
font-size: clamp(1.3rem, 5vw, 2.5rem);
}
/* Panel de botones Simon */
#game-container {
margin: 2.2rem auto 1rem auto;
width: 100%;
max-width: 340px;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 1.2em;
justify-content: center;
align-items: center;
padding: 0.8em;
border-radius: 1.2em;
background: #ffffffdd;
box-shadow: 0 2px 14px #bbbe;
aspect-ratio: 1 / 1; /* el panel siempre es cuadrado */
}
/* Botón Simon */
.color-btn {
width: 100%;
height: 100%;
border-radius: 1.1em;
box-shadow: 0 2px 8px #bbb;
cursor: pointer;
transition: filter 0.2s, border 0.2s;
filter: brightness(0.85);
border: 3px solid #fafafa;
min-width: 0;
min-height: 0;
aspect-ratio: 1 / 1;
/* background colors asignados por id */
}
#green { background: #43a047;}
#red { background: #e53935;}
#yellow { background: #fbc02d;}
#blue { background: #1e88e5;}
.color-btn.active {
filter: brightness(1.1);
border: 3px solid #333;
}
/* Estado y botón inicio */
#status {
font-size: clamp(1em, 2vw, 1.15em);
min-height: 2em;
margin-bottom: 1em;
color: #01579b;
}
#start-btn {
background: #01579b;
color: #fff;
font-size: clamp(1em, 2vw, 1.13em);
border: none;
border-radius: 0.6em;
padding: 0.5em 2em;
cursor: pointer;
transition: background 0.2s;
box-shadow: 0 2px 8px #01579b33;
margin-bottom: 1.4em;
}
#start-btn:hover,
#start-btn:active {
background: #263238;
}
/* ==== Pantallas pequeñas/móviles ==== */
@media (max-width: 600px) {
h1 {
margin-top: 6vw;
font-size: clamp(1.1em, 7vw, 2em);
}
#game-container {
max-width: 96vw;
gap: 6vw;
border-radius: 6vw;
padding: 2vw;
}
.color-btn {
border-radius: 5vw;
box-shadow: 0 2px 6px #bbb;
}
#start-btn {
font-size: clamp(1em, 8vw, 1.4em);
padding: 1em 13vw;
border-radius: 5vw;
margin-bottom: 6vw;
}
#status {
font-size: clamp(1em, 7vw, 1.3em);
margin-bottom: 5vw;
}
}
/* ==== Pantallas muy pequeñas ==== */
@media (max-width: 350px) {
#game-container {
max-width: 93vw;
gap: 3vw;
padding: 1vw;
border-radius: 10vw;
}
.color-btn {
border-radius: 8vw;
}
#start-btn {
padding: 0.8em 3vw;
border-radius: 8vw;
font-size: clamp(0.9em, 13vw, 1.1em);
}
}