-
Notifications
You must be signed in to change notification settings - Fork 1
/
typing.js
140 lines (124 loc) · 4 KB
/
typing.js
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
$(document).ready( function()
{
var width = screen.width - 100,
height = screen.height - 200,
code = 0,
gameSpeed = 550;
var $start = $('#start'),
$timeUp = $('#timeUp'),
$body = $('body'),
$background = $('#Backgound'),
$time = $('#time'),
$score = $('#score'),
$speed = $('#speed'),
$gameSpeed = $('#gameSpeed');
// the button site of start
$start.css({
"top" : (height/2) + 'px',
"left" : (width/2) + 'px'
});
// Begin the game after click the start
$('#start').click(function() {
$(this).fadeOut('slow');
$score.show();
$time.show();
$speed.show();
getTimeChange();
getLetter();
});
//restart the game
$timeUp.click( function() {
location.reload();
});
//Dealing the keyEvents and fadeout the bubble
$(document).keydown(function (event) {
var keyCode = event.keyCode;
if ($time.html() > 0) {
if($('.bubb'+keyCode).length == 0) {
$time.html($time.html() - 1);
} else {
$('.bubb'+keyCode).animate({
"top": height+"px","opacity" : 0
}, 200 );
$('.bubb'+keyCode).fadeOut('slow').hide( 'slow', function() {
code += 20;
$('#score').html(code);
$(this).remove();
// speed Up the game speed
if ($score.html() % 400 == 0 ) {
if (gameSpeed >= 300) {
gameSpeed -= 50;
number = parseInt($gameSpeed.html()) + 1;
$gameSpeed.html(number);
}
}
});
// add time
if ($score.html() % 60 == 0 && $score.html != 0) {
timeAdd = parseInt($time.html()) + 1;
$time.html( timeAdd );
}
}
}
});
// Generating a random alphabet between A-Z
function getLetter()
{
var color = randomColor();
// Generating a random number between 65-90 A-Z
var k = Math.floor(Math.random() * ( 90 - 65 + 1 )) + 65;
// charge the int to char
var ch = String.fromCharCode(k);
// get the random site at the screen
var top = Math.floor(Math.random() * height/6 ),
left = Math.floor(Math.random() * width/2 ) + width/4,
html = '<span class="bubb bubb'+ k +' " style="left:'+ left +'; top: '+ top +'; background-color: '+ color + '">'+ ch +'</span>' ;
$body.append(html);
slowdown(k);
if($time.html() <= 0) {
return;
}
setTimeout(getLetter,gameSpeed);
}
// make the bubble slowdown when it generated
function slowdown(k) {
$('.bubb' + k).animate({
"top": height + "px","opacity" : 1
},{
duration:4000,
queue:false,
complete: function() {
$('.bubb'+k).fadeOut('slow').hide('slow',function(){
$(this).remove();
});
}
});
}
// Count time
function getTimeChange() {
if ($time.html() <= 0) {
$background.fadeIn('slow');
$timeUp.fadeIn('slow');
$timeUp.css({
"top": (height/2)+'px',
"left" : (width/2) - 50 +'px',
"z-index": 100
});
return;
}
$time.html() - 1;
$time.html($time.html() - 1);
setTimeout(getTimeChange, 1000);
}
// Generating a random color
function randomColor() {
var color = '';
var value = ['a', 'b', 'c', 'd', 'e', 'f', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '0'];
for (c = 0; c < 6; c++) {
no = Math.floor( Math.random() * 15 );
color += value[no];
}
return color;
}
});