-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.txt
127 lines (89 loc) · 2.15 KB
/
demo.txt
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
var wordsBox=[];
wordsBox=[{word:"Raheem", posX:0, posY:5},{word:"Amazing", posX:50,posY:20},{word:"queue", posX:90,posY:2},{word:"Melbourne", posX:120,posY:40}];
var keyNum=0;
var str=null;
var totalLetter=0;
var index=0;
var j;
var l=0;
var r=20
$(document).ready(function(){
var y=10;
var speed=0.4;
for(var i=0;i<wordsBox.length;i++)
{
//$("#words").append("<span>"+wordsBox[i].word+"</span><br>");
$('<span></span>').css({"left":wordsBox[i].posX+"px","top":wordsBox[i].posY+"px"}).html(wordsBox[i].word).appendTo('#words');
totalLetter+=wordsBox[i].word.length;
}
$(document).keyup(function(key){
var letterValue=key.keyCode;
var letter = String.fromCharCode(letterValue);
if(l==0)
{
for(var i=0;i<wordsBox.length;i++)
{
if(wordsBox[i].word[0].toUpperCase()===letter)
{
str=wordsBox[i].word;
l=str.length;
j=i;
}
}
}
if(l!=0)
{
if(letter===str[0].toUpperCase())
{
var len = str.length;
str=str.substring(1,len);
l--;
wordsBox[j].word = (wordsBox[j].word).substring(1,len);
if(l==0)
wordsBox.splice(j,1);
$("#words").empty();
$("#words").html(myFunction());
keyNum++;
$("#score").html(keyNum);
}
}
});
function myFunction()
{
for(var i=0;i<wordsBox.length;i++){
$('<span></span>').css({"left":wordsBox[i].posX+"px","top":wordsBox[i].posY+"px"}).html(wordsBox[i].word).appendTo('#words');
//$("#words").append("<span id='a'>"+wordsBox[i].word+"</span><br>");
//alert(wordsBox[i].posX);
//$("span").css({"left":wordsBox[i].posX+"px"});
}
}
function render()
{
$("#words").css({"top":y+"px"});
y+=speed;
if(y<=600 && keyNum==totalLetter)
gameWon();
else
if(keyNum<totalLetter && y>590)
gameOver();
setTimeout(render,10);
}
function gameWon()
{
{
$("#end").html("You Won");
$("#words").remove();
$("#word").remove();
}
}
function gameOver()
{
$("#end").html("Game Over");
$("#words").remove();
$("#word").remove();
return;
}
window.addEventListener("load", function(){
render();
});
});