Código de JQuery - Juego de Memoria

1
estrellaestrellaestrellaestrellaestrella(1)

Publicado el 20 de Mayo del 2021gráfica de visualizaciones de la versión: 1
3.725 visualizaciones desde el 20 de Mayo del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella


Forma parte de Memory Game
 
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html>
<head>
 
<style>
* {
	 box-sizing: border-box;
}
 html, body {
	 height: 100%;
}
 body {
	 background: black;
	 min-height: 100%;
	 font-family: "Arial", sans-serif;
}
 .wrap {
	 position: relative;
	 height: 100%;
	 min-height: 500px;
	 padding-bottom: 20px;
}
 .game {
	 transform-style: preserve-3d;
	 perspective: 500px;
	 min-height: 100%;
	 height: 100%;
}
 @keyframes matchAnim {
	 0% {
		 background: #bcffcc;
	}
	 100% {
		 background: white;
	}
}
 .card {
	 float: left;
	 width: 16.66666%;
	 height: 25%;
	 padding: 5px;
	 text-align: center;
	 display: block;
	 perspective: 500px;
	 position: relative;
	 cursor: pointer;
	 z-index: 50;
	 -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
 @media (max-width: 800px) {
	 .card {
		 width: 25%;
		 height: 16.666%;
	}
}
 .card .inside {
	 width: 100%;
	 height: 100%;
	 display: block;
	 transform-style: preserve-3d;
	 transition: 0.4s ease-in-out;
	 background: white;
}
 .card .inside.picked, .card .inside.matched {
	 transform: rotateY(180deg);
}
 .card .inside.matched {
	 animation: 1s matchAnim ease-in-out;
	 animation-delay: 0.4s;
}
 .card .front, .card .back {
	 border: 1px solid black;
	 backface-visibility: hidden;
	 position: absolute;
	 top: 0;
	 left: 0;
	 width: 100%;
	 height: 100%;
	 padding: 20px;
}
 .card .front img, .card .back img {
	 max-width: 100%;
	 display: block;
	 margin: 0 auto;
	 max-height: 100%;
}
 .card .front {
	 transform: rotateY(-180deg);
}
 @media (max-width: 800px) {
	 .card .front {
		 padding: 5px;
	}
}
 .card .back {
	 transform: rotateX(0);
}
 @media (max-width: 800px) {
	 .card .back {
		 padding: 10px;
	}
}
 .modal-overlay {
	 display: none;
	 background: rgba(0, 0, 0, .8);
	 position: fixed;
	 top: 0;
	 left: 0;
	 width: 100%;
	 height: 100%;
}
 .modal {
	 display: none;
	 position: relative;
	 width: 500px;
	 height: 400px;
	 max-height: 90%;
	 max-width: 90%;
	 min-height: 380px;
	 margin: 0 auto;
	 background: white;
	 top: 50%;
	 transform: translateY(-50%);
	 padding: 30px 10px;
}
 .modal .winner {
	 font-size: 80px;
	 text-align: center;
	 font-family: "Anton", sans-serif;
	 color: #4d4d4d;
	 text-shadow: 0px 3px 0 black;
}
 @media (max-width: 480px) {
	 .modal .winner {
		 font-size: 60px;
	}
}
 .modal .restart {
	 font-family: "Anton", sans-serif;
	 margin: 30px auto;
	 padding: 20px 30px;
	 display: block;
	 font-size: 30px;
	 border: none;
	 background: #4d4d4d;
	 background: linear-gradient(#4d4d4d, #222);
	 border: 1px solid #222;
	 border-radius: 5px;
	 color: white;
	 text-shadow: 0px 1px 0 black;
	 cursor: pointer;
}
 .modal .restart:hover {
	 background: linear-gradient(#222, black);
}
 .modal .message {
	 text-align: center;
}
 .modal .message a {
	 text-decoration: none;
	 color: #28afe6;
	 font-weight: bold;
}
 .modal .message a:hover {
	 color: #56c0eb;
	 border-bottom: 1px dotted #56c0eb;
}
 .modal .share-text {
	 text-align: center;
	 margin: 10px auto;
}
 .modal .social {
	 margin: 20px auto;
	 text-align: center;
}
 .modal .social li {
	 display: inline-block;
	 height: 50px;
	 width: 50px;
	 margin-right: 10px;
}
 .modal .social li:last-child {
	 margin-right: 0;
}
 .modal .social li a {
	 display: block;
	 line-height: 50px;
	 font-size: 20px;
	 color: white;
	 text-decoration: none;
	 border-radius: 5px;
}
 .modal .social li a.facebook {
	 background: #3b5998;
}
 .modal .social li a.facebook:hover {
	 background: #4c70ba;
}
 .modal .social li a.google {
	 background: #d34836;
}
 .modal .social li a.google:hover {
	 background: #dc6e60;
}
 .modal .social li a.twitter {
	 background: #4099ff;
}
 .modal .social li a.twitter:hover {
	 background: #73b4ff;
}
 @media (max-width: 767px) {
	 footer .disclaimer {
		 font-size: 8px;
	}
}
</style>
 
</head>
 
<body>
    <div class="wrap">
        <div class="game"></div>
 
          <div class="modal-overlay">
            <div class="modal">
              <h2 class="winner">You Rock!</h2>
              <button class="restart">Play Again?</button>
            </div>
          </div>
    </div>
</body>
</html>
 
<script src="//code.jquery.com/jquery-latest.js"></script>
<script>
// Memory Game
// © 2014 Nate Wiley
// License -- MIT
// best in full screen, works on phones/tablets (min height for game is 500px..) enjoy ;)
// Follow me on Codepen
 
(function(){
 
  var Memory = {
 
    init: function(cards){
      this.$game = $(".game");
      this.$modal = $(".modal");
      this.$overlay = $(".modal-overlay");
      this.$restartButton = $("button.restart");
      this.cardsArray = $.merge(cards, cards);
      this.shuffleCards(this.cardsArray);
      this.setup();
    },
 
    shuffleCards: function(cardsArray){
      this.$cards = $(this.shuffle(this.cardsArray));
    },
 
    setup: function(){
      this.html = this.buildHTML();
      this.$game.html(this.html);
      this.$memoryCards = $(".card");
      this.paused = false;
      this.guess = null;
      this.binding();
    },
 
    binding: function(){
      this.$memoryCards.on("click", this.cardClicked);
      this.$restartButton.on("click", $.proxy(this.reset, this));
    },
    // kinda messy but hey
    cardClicked: function(){
      var _ = Memory;
      var $card = $(this);
      if(!_.paused && !$card.find(".inside").hasClass("matched") && !$card.find(".inside").hasClass("picked")){
        $card.find(".inside").addClass("picked");
        if(!_.guess){
          _.guess = $(this).attr("data-id");
        } else if(_.guess == $(this).attr("data-id") && !$(this).hasClass("picked")){
          $(".picked").addClass("matched");
          _.guess = null;
        } else {
          _.guess = null;
          _.paused = true;
          setTimeout(function(){
            $(".picked").removeClass("picked");
            Memory.paused = false;
          }, 600);
        }
        if($(".matched").length == $(".card").length){
          _.win();
        }
      }
    },
 
    win: function(){
      this.paused = true;
      setTimeout(function(){
        Memory.showModal();
        Memory.$game.fadeOut();
      }, 1000);
    },
 
    showModal: function(){
      this.$overlay.show();
      this.$modal.fadeIn("slow");
    },
 
    hideModal: function(){
      this.$overlay.hide();
      this.$modal.hide();
    },
 
    reset: function(){
      this.hideModal();
      this.shuffleCards(this.cardsArray);
      this.setup();
      this.$game.show("slow");
    },
 
    // Fisher--Yates Algorithm -- https://bost.ocks.org/mike/shuffle/
    shuffle: function(array){
      var counter = array.length, temp, index;
      // While there are elements in the array
      while (counter > 0) {
          // Pick a random index
          index = Math.floor(Math.random() * counter);
          // Decrease counter by 1
          counter--;
          // And swap the last element with it
          temp = array[counter];
          array[counter] = array[index];
          array[index] = temp;
        }
        return array;
    },
 
    buildHTML: function(){
      var frag = '';
      this.$cards.each(function(k, v){
        frag += '<div class="card" data-id="'+ v.id +'"><div class="inside">\
        <div class="front"><img src="'+ v.img +'"\
        alt="'+ v.name +'" /></div>\
        <div class="back"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/codepen-logo.png"\
        alt="Codepen" /></div></div>\
        </div>';
      });
      return frag;
    }
  };
 
  var cards = [
    {
      name: "php",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/php-logo_1.png",
      id: 1,
    },
    {
      name: "css3",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/css3-logo.png",
      id: 2
    },
    {
      name: "html5",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/html5-logo.png",
      id: 3
    },
    {
      name: "jquery",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/jquery-logo.png",
      id: 4
    },
    {
      name: "javascript",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/js-logo.png",
      id: 5
    },
    {
      name: "node",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/nodejs-logo.png",
      id: 6
    },
    {
      name: "photoshop",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/photoshop-logo.png",
      id: 7
    },
    {
      name: "python",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/python-logo.png",
      id: 8
    },
    {
      name: "rails",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/rails-logo.png",
      id: 9
    },
    {
      name: "sass",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/sass-logo.png",
      id: 10
    },
    {
      name: "sublime",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/sublime-logo.png",
      id: 11
    },
    {
      name: "wordpress",
      img: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/74196/wordpress-logo.png",
      id: 12
    },
  ];
 
  Memory.init(cards);
 
})();
</script>



Comentarios sobre la versión: 1 (1)

26 de Mayo del 2021
estrellaestrellaestrellaestrellaestrella
me sale solo la pantalla en negro solamente
Responder

Comentar la versión: 1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7065