-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjuego_memoria.html
More file actions
176 lines (153 loc) · 6.65 KB
/
Copy pathjuego_memoria.html
File metadata and controls
176 lines (153 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Juego de Memoria</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#1a1a2e;display:flex;flex-direction:column;align-items:center;
justify-content:flex-start;min-height:100vh;font-family:sans-serif;color:#fff;
padding:14px;gap:10px}
h2{color:#ffd700;font-size:1.3rem;letter-spacing:1px;margin-top:4px}
/* CONTROLES */
.controles{display:flex;gap:8px;flex-wrap:wrap;justify-content:center}
.ctrl-group{display:flex;gap:4px}
.ctrl-btn{padding:5px 12px;background:#16213e;border:2px solid #0f3460;border-radius:8px;
color:#aaa;cursor:pointer;font-size:.8rem;transition:all .2s}
.ctrl-btn.active{border-color:#ffd700;color:#ffd700;background:#1e2d50}
.ctrl-btn:hover:not(.active){border-color:#4a7fc1;color:#fff}
/* INFO */
#info{font-size:.9rem;color:#aaa;text-align:center}
/* GRID */
.grid{display:grid;gap:6px;max-width:440px;width:100%}
.grid.g4{grid-template-columns:repeat(4,1fr)}
.grid.g5{grid-template-columns:repeat(5,1fr)}
.grid.g6{grid-template-columns:repeat(6,1fr)}
/* CARTA */
.carta{aspect-ratio:1;background:#16213e;border:2px solid #0f3460;border-radius:10px;
display:flex;align-items:center;justify-content:center;
font-size:1.8rem;cursor:pointer;
transition:transform .15s,background .2s;user-select:none;
-webkit-tap-highlight-color:transparent}
.carta:hover:not(.matched):not(.flipped){transform:scale(1.06);background:#1e2d50}
.carta.flipped{background:#0f3460;border-color:#4a7fc1}
.carta.matched{background:#1a3a1a;border-color:#ffd700;opacity:.75;cursor:default}
.grid.g5 .carta,.grid.g6 .carta{font-size:1.4rem;border-radius:8px}
/* BOTÓN */
#btn{padding:7px 22px;background:#ffd700;color:#1a1a2e;border:none;border-radius:8px;
font-size:.95rem;font-weight:bold;cursor:pointer;flex-shrink:0}
#btn:hover{background:#ffe94d}
/* WIN */
#win{display:none;position:fixed;inset:0;background:rgba(0,0,0,.75);
align-items:center;justify-content:center;z-index:99}
#win.show{display:flex}
#win-box{background:#16213e;border:2px solid #ffd700;border-radius:16px;
padding:2rem 2.5rem;text-align:center;max-width:320px;width:90%}
#win-box h3{color:#ffd700;font-size:1.5rem;margin-bottom:.4rem}
#win-box p{color:#aaa;margin-bottom:1rem;font-size:.9rem}
#win-box button{padding:8px 22px;background:#ffd700;color:#1a1a2e;border:none;
border-radius:8px;font-size:.95rem;font-weight:bold;cursor:pointer}
</style>
</head>
<body>
<h2>🃏 JUEGO DE MEMORIA</h2>
<div class="controles">
<div class="ctrl-group">
<button class="ctrl-btn active" id="d-facil" onclick="setDif('facil')">Fácil 4×4</button>
<button class="ctrl-btn" id="d-medio" onclick="setDif('medio')">Medio 4×5</button>
<button class="ctrl-btn" id="d-dificil" onclick="setDif('dificil')">Difícil 5×6</button>
</div>
<div class="ctrl-group">
<button class="ctrl-btn active" id="t-espacio" onclick="setTema('espacio')">🚀 Espacio</button>
<button class="ctrl-btn" id="t-animales" onclick="setTema('animales')">🐾 Animales</button>
<button class="ctrl-btn" id="t-ciencia" onclick="setTema('ciencia')">🔬 Ciencia</button>
<button class="ctrl-btn" id="t-frutas" onclick="setTema('frutas')">🍎 Frutas</button>
</div>
</div>
<div id="info">Intentos: 0 | Pares: 0 / –</div>
<div class="grid g4" id="grid"></div>
<button id="btn" onclick="init()">🔄 Reiniciar</button>
<div id="win">
<div id="win-box">
<h3>🎉 ¡Ganaste!</h3>
<p id="win-msg"></p>
<button onclick="document.getElementById('win').classList.remove('show');init()">Jugar de nuevo</button>
</div>
</div>
<script>
const TEMAS = {
espacio: ['🚀','⭐','🌙','🪐','☄️','🔭','👽','🛸','🌌','🌠','🌍','☀️','🌊','🌋','💫'],
animales: ['🐶','🐱','🐸','🦁','🐧','🦊','🐨','🦋','🐬','🦜','🐙','🦒','🐺','🦅','🐝'],
ciencia: ['🔬','⚗️','🧲','💡','🔋','⚡','🧪','🌡️','🔭','🧬','💊','🔩','🧮','📡','🛰️'],
frutas: ['🍎','🍊','🍋','🍇','🍓','🍑','🍍','🥭','🍒','🫐','🍌','🥝','🍈','🍏','🫒']
};
const DIFS = {
facil: { pares:8, cols:'g4' },
medio: { pares:10, cols:'g5' },
dificil: { pares:15, cols:'g6' }
};
let dif='facil', tema='espacio';
let flipped=[], matched=0, moves=0, total=0, lock=false;
function setDif(d){
dif=d;
document.querySelectorAll('[id^="d-"]').forEach(b=>b.classList.remove('active'));
document.getElementById('d-'+d).classList.add('active');
init();
}
function setTema(t){
tema=t;
document.querySelectorAll('[id^="t-"]').forEach(b=>b.classList.remove('active'));
document.getElementById('t-'+t).classList.add('active');
init();
}
function shuffle(arr){ return [...arr].sort(()=>Math.random()-.5); }
function init(){
const cfg = DIFS[dif];
const emojis = shuffle(TEMAS[tema]).slice(0, cfg.pares);
total = cfg.pares;
matched=0; moves=0; flipped=[]; lock=false;
updInfo();
const grid = document.getElementById('grid');
grid.className = `grid ${cfg.cols}`;
grid.innerHTML = '';
shuffle([...emojis,...emojis]).forEach(emoji=>{
const d = document.createElement('div');
d.className='carta';
d.dataset.val=emoji;
d.textContent='❓';
d.addEventListener('click',()=>flip(d));
grid.appendChild(d);
});
}
function updInfo(){
document.getElementById('info').textContent =
`Intentos: ${moves} | Pares: ${matched} / ${total}`;
}
function flip(card){
if(lock||flipped.length===2||card.classList.contains('matched')||card.classList.contains('flipped'))return;
card.classList.add('flipped'); card.textContent=card.dataset.val;
flipped.push(card);
if(flipped.length===2){
moves++; lock=true; updInfo();
if(flipped[0].dataset.val===flipped[1].dataset.val){
flipped.forEach(c=>c.classList.add('matched'));
matched++; updInfo(); flipped=[]; lock=false;
if(matched===total){
const stars = moves<=total+2?'⭐⭐⭐':moves<=total*1.5?'⭐⭐':'⭐';
document.getElementById('win-msg').textContent=
`${stars} Completaste ${total} pares en ${moves} intentos.`;
setTimeout(()=>document.getElementById('win').classList.add('show'),400);
}
}else{
setTimeout(()=>{
flipped.forEach(c=>{c.classList.remove('flipped');c.textContent='❓';});
flipped=[]; lock=false;
},900);
}
}
}
init();
</script>
</body>
</html>