-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
802 lines (613 loc) · 19.7 KB
/
index.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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<title>Click the Magic Ball </title>
</head>
<style>
body {
/* background-color: rgb(43, 35, 35); */
background-image: url('game_bg.jpg');
background-size: cover;
height: 100vh;
background-repeat: no-repeat;
color: white;
font-size: 30px;
margin: 0px;
padding: 0px;
display: block;
overflow: hidden;
/* overflow:hidden; */
/* padding-left:300px; */
}
#header {
/* height: 50vh; */
background-color: rgba(0, 0, 248, 0.4);
display: none;
}
#ball {
background-color: rgb(84, 38, 170);
background-image: url("new_magic_ball1.jpg");
background-size: cover;
/* display: inline-block; */
height: 20vw;
width: 20vw;
/* transition: 0.1s; */
/* transition-duration: 1s; */
border-radius: 50%;
box-shadow: 0px 0px 30px 4px rgb(53, 5, 143), 0px 0px 40px 8px rgb(127, 92, 190), 0px 0px 10px 5px rgb(255, 255, 255);
position: relative;
left: 0vh;
right: 0vh;
z-index: 10;
}
#start_menu {
position: relative;
/* background-color: rgba(105, 62, 62,0.8); */
border: solid rgb(7, 226, 226);
text-align: center;
top: 10vh;
/* border-radius:5px; */
}
#start_message {
padding: 0px;
margin: 10px;
}
#score_message {
padding: 0px;
margin: 10px;
/* color:white ;!important; */
display: none;
}
#hint_button,
#start_button,
#replay_button,
#score_button,
#submit_button {
padding: 4px;
margin-bottom: 5px;
background-color: rgba(76, 76, 129, 0.4);
border-color: rgb(78, 78, 194);
color:white;
}
#hint_button:hover,
#start_button:hover,
#replay_button:hover,
#score_button:hover,
#submit_button:hover,
#close_button:hover,
#hint_box_close_button:hover {
background-color: rgb(39, 39, 179);
}
#detail_box {
position: fixed;
background-color: brown;
border: solid rgb(7, 226, 226);
background-color: rgba(89, 18, 95, 0.5);
right: 0px;
top: 0px;
padding: 5px;
margin: 10px;
color: cornsilk;
display: none;
}
#time_taken,
#time_limit,
#score {
margin: 0px;
font-size: small;
color: rgb(192, 255, 65);
}
#score_box {
/* background-color:rgba(89, 18, 95,0.5); */
display: none;
/* background-color: brown; */
border: solid rgb(185, 174, 174);
position: relative;
padding: 0px;
width: 60%;
margin: auto;
top: -120px;
font-size: 20px;
font-size: 20px;
/* border-radius:5px; */
}
#hint_box {
display: none;
background-color: brown;
border: solid rgb(185, 174, 174);
position: relative;
padding: 0px;
width: 60%;
margin: auto;
top: -120px;
font-size: 20px;
font-size: 20px;
}
.right {
position: absolute;
right: 10px;
;
}
.left {
position: relative;
left: 10px;
padding-left: 10px;
}
#last {
display: flexbox;
justify-content: center;
align-self: center;
/* display: contents; */
background-color: pink;
}
#score_list {
background-color: rgb(10, 10, 66);
/* height: 100px; */
}
#hint_box_message {
background-color: rgb(10, 10, 66);
padding: 10px;
}
#close_button {
position: absolute;
right: 0px;
margin: 5px;
color:white;
padding: 5px 8px 5px;
border: solid rgb(221, 205, 221);
border-width: 0.1px;
}
#hint_box_close_button {
position: absolute;
right: 0px;
/* top:-1px; */
color:black;
margin-right: 5px;
padding: 5px 8px 5px;
border: solid rgb(221, 205, 221);
border-width: 0.1px;
}
#score_box_header,
#hint_box_header {
background-color: rgb(19, 6, 6);
/* margin:53px; */
padding: 5px;
}
#middle {
border-top: solid rgb(221, 205, 221);
border-bottom: solid rgb(221, 205, 221);
background-color: rgb(39, 83, 83);
}
#user_name {
background-color: blue;
}
#difficulty_range {
margin: 0px;
/* background-color:black; */
/* display: none; */
}
#difficulty_range:hover {
background-color: rgba(89, 18, 95, 0.5);
}
#input_range {
border-style: solid;
background-color: blanchedalmond;
}
#input_name {
width: 30%;
}
@media screen and (orientation: landscape){
#ball{
height: 20vh;
width: 20vh;
}
}
@media screen and (max-width:500px){
#hint_box{
width:98%;
}
}
</style>
<!-- html -->
<body>
<div id="header"> </div>
<span id="ball">
</span>
<!-- <audio src="bgmusic.mp3" loop id=audio_button > </audio> -->
<audio src="bg_music1.mp3" loop id=audio_button> </audio>
<audio src="bounce.mp3" id=aud_button> </audio>
<div align="center">
<div id="start_menu">
<p id="start_message">Click the Circle</p>
<p id="difficulty_range">
<input id="input_range" min=1 max=3 type="range" value=3>
</p>
<p id="score_message"> 1 out of 5</p>
<button id="start_button">Start</button>
<button id="hint_button">Hint</button>
<button id="replay_button">Replay</button>
<button id="score_button">Show Score</button>
</div>
</div>
<div id="detail_box">
<p id="time_limit">Time Limit :33434</p>
<p id="time_taken">Time Taken: 342343</p>
<p id="score">Score is:100000</p>
</div>
<div id="score_box">
<div id="score_box_header">
<input id="input_name" value="player">
<button id="submit_button">submit</button>
<button id="close_button" style=" color:black;">X</button>
</div>
<div id="middle">
<span class="left">Player Name </span>
<span class="right">Score </span>
</div>
<div id="score_list">
</div>
</div>
<div id="hint_box">
<div id="hint_box_header">
<button id="hint_box_close_button">X</button>
</div>
<div id="hint_box_message">
In this game, you have to <i><b>click the yellow circle </b> </i> circle which appear when you click the start
button.
<br>If you <i><b>click the circle within the given time limit </b> </i>you will be update to next level.
<br> After clicking the circle one detail box will appear in top-right corner which displays your game details.
<ul>
<li><u>Time Limit</u> - time given for the current level </li>
<li><u>Time Taken</u> - time taken between the ball appear and the ball hit</li>
<li><u>Score</u> - score till current level</li>
</ul>
If the time taken is greater then the time limit<i><b> you will lose!</b></i> .
<br>click next to go to next level.
<br> You can change the difficulty level of game with the help of sliding button, moving toward
right will increase the difficulty level and vise-versa.
<br> You will have to click the ball as far as possible.
<br><b><i>Click start to play the game.</i></b>
</div>
</div>
<script>
var header = document.getElementById("header");
var ball = document.getElementById("ball");
var start_button = document.getElementById("start_button");
var replay_button = document.getElementById("replay_button");
var score_button = document.getElementById("score_button");
var close_button = document.getElementById("close_button");
var hint_button = document.getElementById("hint_button");
var hint_box_close_button = document.getElementById("hint_box_close_button");
var hint_box = document.getElementById("hint_box");
var audio_button = document.getElementById("audio_button");
var aud_button = document.getElementById("aud_button");
var score_list = document.getElementById("score_list");
var submit_button = document.getElementById("submit_button");
var input_name = document.getElementById("input_name");
var score_box = document.getElementById("score_box");
var input_range = document.getElementById("input_range");
var input_range = document.getElementById("input_range");
var difficulty_level = 10;
var score_message = document.getElementById("score_message");
var detail_box = document.getElementById("detail_box");
var start_menu = document.getElementById("start_menu");
var detail_box_children = detail_box.children;
var start_menu_children = start_menu.children;
var time_limit = 2000;
var score = 0;
var level_no = 1;
var time_taken;
var current_time
var brightness = 1;
let array = [
{ "batman": 57300 },
{ "bheem": 1493227000 },
{ "raju": 28700 },
{ "abraham": 8600 },
{ "joker": 4595000 },
{ "doremon": 65791000 }
];
// document.addEventListener("mousedown",function(){
// console.log("w = ",innerWidth,"h = ",innerHeight);
// })
// document.addEventListener("click" , ()=> {
// console.log( event.clientX);
// })
hint_button.addEventListener("click", function () {
hint_box.style.display = "block";
// console.log("hiteed hit");
});
hint_box_close_button.addEventListener("click", () => {
hint_box.style.display = "none";
})
function display_game() {
let h = innerHeight;
let w = innerWidth;
// w=h= Math.min(h,w);
let r = Math.min(h, w) * 0.1;
Math.srand
ball.style.width = ball.style.height = 2 * r;
ball.style.top = String(-r) + "px";
header.style.height = String(r + (Math.random() * (h - 2 * r))) + "px";
ball.style.left = String(Math.random() * (w - 2 * r)) + "px";
}
function manage_input_range() {
difficulty_level = Number(input_range.value) * 5;
// console.log("input is executed ");
if (input_range.value == 3) {
// console.log("input range fixed to 2300")
time_limit = 2300;
}
else {
time_limit = 2000;
}
}
input_range.addEventListener("change", manage_input_range);
function display_ball() {
ball.style.display = "inline-block";
header.style.display = "block";
display_game();
current_time = Date.now();
}
function show_detail_box() {
detail_box.style.display = "inline-block";
detail_box_children[0].textContent = "Time Limit: " + (time_limit);
detail_box_children[1].textContent = "Time Taken: " + (time_taken);
detail_box_children[2].textContent = "Score: " + score;
}
function show_time_out_message() {
start_message.style.color = "rgb(255,5, 5)";
start_message.textContent = "Ops.. time up You Lose! ";
}
replay_button.addEventListener("click", function () {
input_range.style.display = "inline-block";
// console.log("repaly button ");
hint_button.style.display = "inline";
brightness = 1;
start_menu.style.display = "inline-block";
replay_button.style.display = "none";
score_button.style.display = "none";
score_box.style.display = "none";
// start_button.style.display="inline-block";
reset_all_value();
start_button.style.display = "inline-block";
// detail_box.style.display ="none";
detail_box.style.display = "none"
start_message.style.color = "white";
start_menu_children[2].textContent = "";
start_message.textContent = "Click the Circle";
});
function reset_all_value() {
level_no = 1;
brightness = 1;
ball.style.backgroundImage="url(new_magic_ball1.jpg)";
// brighness = 1;
start_button.textContent = "Start";
score = 0;
time_limit = 2000;
manage_input_range();
// start_menu.style.display ="inline-block";
// replay_button.style.display ="none";
// score_button.style.display = "none";
// score_box.style.display ="none";
}
ball.addEventListener("mousedown", function () {
time_taken = Date.now() - current_time;
ball.style.display = "none";
header.style.display = "none";
score_message.style.display = "block";
score_message.textContent = `${level_no} out of ${difficulty_level}`;
// if (level_no == 1) {
// score = 0;
// time_limit = 2000;
// start_button.textContent = "Next Level";
// replay_button.style.display = "inline-block";
//}
if (time_taken <= time_limit) {
score += level_no * 1000 * (time_limit - time_taken);
}
show_detail_box();
start_button.textContent = "Next Level";
replay_button.style.display = "inline-block";
// console.log()
// console.log("difference is " , (time_limit - time_taken));
// console.log((time_limit - time_taken)< 0);
if ((time_limit < time_taken) || level_no == difficulty_level) {
ball.style.backgroundImage="url(new_magic_ball1.jpg)";
brighness = 1;
replay_button.style.display = "inline-block";
start_menu.style.display = "inline-block";
start_message.style.color = "rgb(2, 255, 5)";
start_message.style.display = "inline-block";
start_button.style.display = "none";
score_button.style.display = "inline-block";
if ((time_limit < time_taken)) {
brightness=1;
ball.style.backgroundImage="url(new_magic_ball1.jpg)";
// brighness = 1;
show_time_out_message();
}
else {
start_message.textContent = "Horreaaa... You Win!";
brightness=1 ;
ball.style.backgroundImage="url(new_magic_ball1.jpg)";
// brighness = 1;
}
}
else {
level_no += 1;
time_limit = time_limit - 150;
display_start_menu();
}
if(level_no>10){
ball.style.backgroundImage="url(new_magic_ball3.jpg)";
}
else if(level_no>5){
ball.style.backgroundImage="url(new_magic_ball2.jpg)";
}
brightness += 1;
ball.style.boxShadow = " 0px 0px " + brightness + "0px 4px rgb(53, 5, 143),0px 0px 40px 8px rgb(127, 92, 190),0px 0px " + (brightness * 2) + "0px " + brightness + "0px rgb(255, 255, 255)"
});
function display_start_menu() {
start_menu.style.display = "inline-block";
}
start_button.addEventListener("click", function () {
start_menu.style.display = "none";
input_range.style.display = "none";
hint_button.style.display = "none";
setTimeout(display_ball, (Math.random() * 3000) + 500);
})
function remove_from_score_list() {
let temp = score_list.children;
// if()
let len = temp.length;
if (len == 0) {
return;
}
while (len) {
temp[--len].remove();
}
// console.log("after remving score list is: ");
// console.log(score_list);
}
function add_to_score_list(index, signal = 0) {
let key;
let user_name = input_name.value;
let x = document.createElement("div");
let temp = document.createElement("span");
temp.className = "left"
for (i in array[index]) {
key = i;
}
if (user_name == i) {
x.id = "user_name";
}
temp.textContent = i;
x.appendChild(temp);
temp = document.createElement("span");
temp.className = "right";
temp.textContent = array[index][i];
x.appendChild(temp);
score_list.appendChild(x);
}
function set_score_list() {
let key1, value1, key2, value2;
let score_list_index = localStorage.getItem("score_list_index");
if (score_list_index != null) {
score_list_index = JSON.parse(score_list_index);
// console.log(score_list_index);
}
else {
localStorage.setItem("score_list_index", JSON.stringify({}))
score_list_index = {};
}
if (remove_space_from_both_side(input_name.value).length == 0) {
input_name.value = "player";
}
let temp_name = input_name.value;
let count = 1;
// console.log("score_list is");
// console.log(score_list_index);
if (score_list_index[temp_name] != null) {
while (score_list_index[temp_name + "(" + count + ")"] != null) {
count++;
}
input_name.value = temp_name + "(" + count + ")";
}
score_list_index[input_name.value] = score;
let dict = {};
for (key in score_list_index) {
dict = {};
dict[key] = score_list_index[key];
array.push(dict);
}
function sort_by_score(a, b) {
for (let i in a) {
key1 = i;
value1 = a[i];
}
for (let i in b) {
key2 = i;
value2 = b[i];
}
// console.log(key1 ,":",value1,",",key2,":",value2);
if (value1 > value2) return 1;
else if (value1 == value2) return 0;
else return -1;
}
array.sort(sort_by_score);
let len = array.length;
remove_from_score_list();
for (let i = len - 1; i >= 0; i--) {
add_to_score_list(i);
}
localStorage.setItem("score_list_index", JSON.stringify(score_list_index));
input_name.value = "";
array = [
{ "batman": 57300 },
{ "bheem": 1493227000 },
{ "raju": 28700 },
{ "abraham": 8600 },
{ "joker": 4595000 },
{ "doremon": 65791000 }
];
// console.log("key ", (array[3]).key(0)," value",array[3][ (array[3]).key(0)]);
}
submit_button.addEventListener("click", function () {
remove_from_score_list();
set_score_list();
score_box.style.display = "block";
});
close_button.addEventListener("click", function () {
// window.location.reload();
score_box.style.display = "none";
});
function remove_space_from_both_side(string) {
let len = string.length;
if (len == 0)
return "";
let i = 0;
while (string[i] == " ") {
i++
}
if (i == len)
return "";
len = len - 1;
while (string[len] == " ") {
len--;
}
return string.substring(i, len + 1);;
}
score_button.addEventListener("click", function () {
remove_from_score_list();
if (remove_space_from_both_side(input_name.value).length == 0) {
input_name.value = "player";
}
set_score_list();
score_box.style.display = "block";
})
display_start_menu();
replay_button.style.display = "none";
score_button.style.display = "none";
detail_box.style.display = "none";
start_menu.addEventListener("click", function () {
// console.log(audio_button);
audio_button.play();
});
document.addEventListener("click", function () {
// console.log("clice");
aud_button.play();
})
ball.style.backgroundImage="url(new_magic_ball3.jpg)";
ball.style.backgroundImage="url(new_magic_ball2.jpg)";
ball.style.backgroundImage="url(new_magic_ball1.jpg)";
manage_input_range();
</script>
</body>
</html>
<!-- x.insertAdjacentHTML("afterend",
// '<img src="'+ image_array[3] + '" alt="no_image">'); -->