-
Notifications
You must be signed in to change notification settings - Fork 0
/
game5.html
424 lines (351 loc) · 15.1 KB
/
game5.html
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
421
422
423
424
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Flip card memory | Adventure Club</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#2c3f51">
<link rel="shortcut icon" href="images/favicon.png">
<style>
body, html{margin:0;font:normal 0/0 Arial, Helvetica, sans-serif;background:#333;overflow:hidden;color:#fff;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
body, html, .flipper, .f, .b, #g {width:100%;height:100%;}
/* font-face */
@font-face{font-family: "GeneralFoundicons";font-weight:normal;font-style:normal;
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/60583/general_foundicons.eot");
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/60583/general_foundicons.eot?#iefix") format("embedded-opentype"),
url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/60583/general_foundicons.woff") format("woff"),
url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/60583/general_foundicons.ttf") format("truetype"),
url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/60583/general_foundicons.svg#GeneralFoundicons") format("svg");
}
a{text-decoration:none;color:#fff;display:block;font:bold 18px/75px 'Open Sans';text-transform:uppercase;text-align:center;padding:0;margin:0 1px;}
a:hover{color:#fff;background:rgba(255, 255, 255, .1)}
/* FRONT SCREEN */
.logo{width:450px;height:450px;position:absolute;top:50%;left:50%;margin:-225px 0 0 -225px}
.logo .card{width:50%;height:50%;cursor:default;position:relative}
.logo .card.left.active{z-index:2}
.logo .card.left.active + .card{opacity:0}
.logo .card.left.active .b{margin-left:-100%}
.logo .f{font:normal 130px/225px 'Open Sans';text-align:center;text-transform:uppercase;}
.logo .c2{transform:scale(-1, 1);-webkit-transform:scale(-1, 1);-moz-transform:scale(-1, 1);-ms-transform:scale(-1, 1)}
.logo .contentbox{width:200%;font:normal 12px/16px 'Open Sans';text-align:left}
.logo .contentbox.levels{width:100%}
.logo .contentbox .padded{padding:0 15px;}
.logo .contentbox h2{font-size:24px;padding:0;margin:28px 0;text-transform:uppercase}
.logo .contentbox p{line-height:14px;margin:14px 0}
#stats h2 i{margin-right:10px;vertical-align:top;font:italic normal 9px/8px 'Open Sans';color:rgba(255,255,255, .4)}
#stats ul{width:50%;display:inline-block;margin:0;padding:0;list-style-type:none;vertical-align:top;line-height:22px}
#stats li{display:block;margin:0;padding:0;}
#stats li b{display:inline-block;font-size:12px;width:95px}
#stats a {position:absolute;bottom:0;width:100%;margin-left:-15px;}
.logo .info{font-size:11px;line-height:16px;text-align:center;color: rgba(255,255,255, .3);padding:0 25px;}
/*GAME SCREEN*/
#g{margin-top:4px}
#g .timer{width:0%;height:5px;position:absolute;top:0;background:#C0392B;z-index:1}
@-webkit-keyframes timer {100% { width:100%; }}
@-moz-keyframes timer {100% { width:100%; }}
@-o-keyframes timer {100% { width:100%; }}
@keyframes timer {100% { width:100%; }}
.pause{position:absolute;width:100%;height:100%;left:0;top:0;z-index:100;background:rgba(51, 51, 51, 0.78)}
.pause::before{content:'PAUSED';width:100%;position:absolute;margin-top:-100px;top:50%;background:#C0392B;color:#fff;font:bold 80px/200px 'Open Sans';
display:block;text-align:center;}
/* card styles */
#g .found{display:inline-block}
.card{display:inline-block;-webkit-perspective:1000;-moz-perspective:1000;}
.card:not(.active):hover{opacity:.8}
.card .b::before{content:attr(data-f);display:block;font:normal 100px/100px "GeneralFoundicons";
position:absolute;top:50%;margin-top:-50px;width:100%;text-align:center}
/* flip cards */
.flipper {position:relative;-webkit-transform-style:preserve-3d;-moz-transform-style:preserve-3d}
.f, .b {position:absolute;top:0;left:0;box-shadow:inset 0 0 0 1px #333;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden}
.f {background:#16A085;z-index:1}
.b {background:#C0392B;opacity:0}
.card.active .b{z-index:2;opacity:1}
/*Grouped for easy prefixing*/
.card, .flipper, .logo .b{transition:400ms;-ms-transition:400ms;-webkit-transition:400ms;-moz-transition:400ms;-o-transition:400ms}
.card.active .flipper, .b {transform:rotateY(180deg);-webkit-transform:rotateY(180deg);-moz-transform:rotateY(180deg);-ms-transform:rotateY(180deg);-o-transform:rotateY(180deg)}
.logo .f, .card .b::before, .pause::before{-webkit-text-stroke: 1px #fff} /*webkit only*/
/*Responsive Stuff*/
@media all and (max-width: 1680px) and (min-width: 640px){
.card .b::before{font-size:90px}
#g.medium .card .b::before{font-size:70px}
#g.hard .card .b::before{font-size:50px}
}
@media all and (max-width: 640px) and (min-width: 470px){
.card .b::before{font-size:90px}
#g.medium .card .b::before{font-size:60px}
#g.hard .card .b::before{font-size:50px}
}
@media all and (max-width: 470px) and (min-width: 0px){
.card .b::before{font-size:60px}
#g.medium .card .b::before{font-size:35px;-webkit-text-stroke:0;}
#g.hard .card .b::before{font-size:32px;-webkit-text-stroke:0;}
}
@media all and (max-width: 640px) and (min-width: 0px){
a{line-height:50px;font-size:13px}
.logo{width:300px;height:300px;margin:-150px 0 0 -150px}
.logo .f{font:normal 80px/150px 'Open Sans'}
.logo .contentbox h2{font-size:16px;margin:24px 0;}
.logo .instructions h2{display:none}
.logo .instructions.contentbox p:nth-child(3){display:none}
#stats li b{width:auto}
}
</style>
<script>
window.console = window.console || function(t) {};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
</head>
<body translate="no" >
<!--
README!
GAME INSRUCTIONS:
p - pause
ESC - abandon game
Click the big P to choose one of three levels:
- Casual
- Medium
- Hard
The game will save your stats locally, via localStorage.
Click the F to see your stats.
Click I for these intructions.
Flip is a timed card memory game. When starting a level, there's a red bar on top of the screen that shows how much time you have left.
Click the green cards to see what symbol they uncover and try to find the matching symbol underneath the other cards.
Uncover two matching symbols in a row to eliminate them from the game.
Eliminate all cards as fast as you can to win the game. Have fun FLIPing!
-->
<div id="g"></div>
<div class="logo">
<p class="info">Click the P to get started.</p>
<div class="card left">
<div class="flipper">
<div class="f c1">F</div>
<div class="b contentbox" id="stats">
<div class="padded">
<h2>Figures</h2>
Looks like you haven't FLIPped yet.
<a href="javascript:;" class="playnow">Play now</a>
</div>
</div>
</div>
</div>
<div class="card active twist">
<div class="flipper">
<div class="b f">
<div class="c2">L</div>
</div>
</div>
</div>
<div class="card left">
<div class="flipper">
<div class="f c3">I</div>
<div class="b contentbox instructions">
<div class="padded">
<h2>Instructions</h2>
<p>Press [p] to pause, or [ESC] to abandon game.</p>
<p>Flip is a timed card memory game. Click the green cards to see what symbol they uncover and try to find the matching symbol underneath the other cards.</p>
<p>Uncover two matching symbols at once to eliminate them from the game.</p>
<p>Eliminate all cards as fast as you can to win the game. Have fun FLIPing!</p>
</div>
</div>
</div>
</div>
<div class="card">
<div class="flipper">
<div class="f c4">P</div>
<div class="b contentbox levels">
<a href="javascript:;" data-level="8" class="play">Casual</a>
<a href="javascript:;" data-level="18" class="play">Medium</a>
<a href="javascript:;" data-level="32" class="play">Hard</a>
</div>
</div>
</div>
<p class="info">Flip should work best in Google Chrome, decent in Firefox, IE10 and Opera;</p>
</div>
<script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-8216c69d01441f36c0ea791ae2d4469f0f8ff5326f00ae2d00e4bb7d20e24edb.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script id="rendered-js" >
$(function () {
function set(key, value) {localStorage.setItem(key, value);}
function get(key) {return localStorage.getItem(key);}
function increase(el) {set(el, parseInt(get(el)) + 1);}
function decrease(el) {set(el, parseInt(get(el)) - 1);}
var toTime = function (nr) {
if (nr == '-:-') return nr;else
{var n = ' ' + nr / 1000 + ' ';return n.substr(0, n.length - 1) + 's';}
};
function updateStats() {
$('#stats').html('<div class="padded"><h2>Figures: <span>' +
'<b>' + get('flip_won') + '</b><i>Won</i>' +
'<b>' + get('flip_lost') + '</b><i>Lost</i>' +
'<b>' + get('flip_abandoned') + '</b><i>Abandoned</i></span></h2>' +
'<ul><li><b>Best Casual:</b> <span>' + toTime(get('flip_casual')) + '</span></li>' +
'<li><b>Best Medium:</b> <span>' + toTime(get('flip_medium')) + '</span></li>' +
'<li><b>Best Hard:</b> <span>' + toTime(get('flip_hard')) + '</span></li></ul>' +
'<ul><li><b>Total Flips:</b> <span>' + parseInt((parseInt(get('flip_matched')) + parseInt(get('flip_wrong'))) * 2) + '</span></li>' +
'<li><b>Matched Flips:</b> <span>' + get('flip_matched') + '</span></li>' +
'<li><b>Wrong Flips:</b> <span>' + get('flip_wrong') + '</span></li></ul></div>');
};
function shuffle(array) {
var currentIndex = array.length,temporaryValue,randomIndex;
while (0 !== currentIndex) {if (window.CP.shouldStopExecution(0)) break;
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}window.CP.exitedLoop(0);
return array;
};
function startScreen(text) {
$('#g').removeAttr('class').empty();
$('.logo').fadeIn(250);
$('.c1').text(text.substring(0, 1));
$('.c2').text(text.substring(1, 2));
$('.c3').text(text.substring(2, 3));
$('.c4').text(text.substring(3, 4));
// If won game
if (text == 'nice') {
increase('flip_won');
decrease('flip_abandoned');
}
// If lost game
else if (text == 'fail') {
increase('flip_lost');
decrease('flip_abandoned');
}
// Update stats
updateStats();
};
/* LOAD GAME ACTIONS */
// Init localStorage
if (!get('flip_won') && !get('flip_lost') && !get('flip_abandoned')) {
//Overall Game stats
set('flip_won', 0);
set('flip_lost', 0);
set('flip_abandoned', 0);
//Best times
set('flip_casual', '-:-');
set('flip_medium', '-:-');
set('flip_hard', '-:-');
//Cards stats
set('flip_matched', 0);
set('flip_wrong', 0);
}
// Fill stats
if (get('flip_won') > 0 || get('flip_lost') > 0 || get('flip_abandoned') > 0) {updateStats();}
// Toggle start screen cards
$('.logo .card:not(".twist")').on('click', function (e) {
$(this).toggleClass('active').siblings().not('.twist').removeClass('active');
if ($(e.target).is('.playnow')) {$('.logo .card').last().addClass('active');}
});
// Start game
$('.play').on('click', function () {
increase('flip_abandoned');
$('.info').fadeOut();
var difficulty = '',
timer = 1000,
level = $(this).data('level');
// Set game timer and difficulty
if (level == 8) {difficulty = 'casual';timer *= level * 4;} else
if (level == 18) {difficulty = 'medium';timer *= level * 5;} else
if (level == 32) {difficulty = 'hard';timer *= level * 6;}
$('#g').addClass(difficulty);
$('.logo').fadeOut(250, function () {
var startGame = $.now(),
obj = [];
// Create and add shuffled cards to game
for (i = 0; i < level; i++) {if (window.CP.shouldStopExecution(1)) break;obj.push(i);}window.CP.exitedLoop(1);
var shu = shuffle($.merge(obj, obj)),
cardSize = 100 / Math.sqrt(shu.length);
for (i = 0; i < shu.length; i++) {if (window.CP.shouldStopExecution(2)) break;
var code = shu[i];
if (code < 10) code = "0" + code;
if (code == 30) code = 10;
if (code == 31) code = 21;
$('<div class="card" style="width:' + cardSize + '%;height:' + cardSize + '%;">' +
'<div class="flipper"><div class="f"></div><div class="b" data-f="ð' + code + ';"></div></div>' +
'</div>').appendTo('#g');
}
// Set card actions
window.CP.exitedLoop(2);$('#g .card').on({
'mousedown': function () {
if ($('#g').attr('data-paused') == 1) {return;}
var data = $(this).addClass('active').find('.b').attr('data-f');
if ($('#g').find('.card.active').length > 1) {
setTimeout(function () {
var thisCard = $('#g .active .b[data-f=' + data + ']');
if (thisCard.length > 1) {
thisCard.parents('.card').toggleClass('active card found').empty(); //yey
increase('flip_matched');
// Win game
if (!$('#g .card').length) {
var time = $.now() - startGame;
if (get('flip_' + difficulty) == '-:-' || get('flip_' + difficulty) > time) {
set('flip_' + difficulty, time); // increase best score
}
startScreen('nice');
}
} else
{
$('#g .card.active').removeClass('active'); // fail
increase('flip_wrong');
}
}, 401);
}
} });
// Add timer bar
$('<i class="timer"></i>').
prependTo('#g').
css({
'animation': 'timer ' + timer + 'ms linear' }).
one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
startScreen('fail'); // fail game
});
// Set keyboard (p)ause and [esc] actions
$(window).off().on('keyup', function (e) {
// Pause game. (p)
if (e.keyCode == 80) {
if ($('#g').attr('data-paused') == 1) {//was paused, now resume
$('#g').attr('data-paused', '0');
$('.timer').css('animation-play-state', 'running');
$('.pause').remove();
} else
{
$('#g').attr('data-paused', '1');
$('.timer').css('animation-play-state', 'paused');
$('<div class="pause"></div>').appendTo('body');
}
}
// Abandon game. (ESC)
if (e.keyCode == 27) {
startScreen('flip');
// If game was paused
if ($('#g').attr('data-paused') == 1) {
$('#g').attr('data-paused', '0');
$('.pause').remove();
}
$(window).off();
}
});
});
});
});
//# sourceURL=pen.js
</script>
</body>
</html>