-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-rosco.js
110 lines (104 loc) · 2.72 KB
/
script-rosco.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
var currentTimeout;
var lletres = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "V", "X", "Y", "Z" ];
var current = 0;
var encerts = 0;
var temps = 1200;
var continuo = false;
function toCercle( array, diametre )
{
// Nomes funciona per nombres parells
r = diametre/2;
for( i = 0; i < array.length / 2; i++)
{
xFirst = diametre*i*2/array.length;
xLast = xFirst + diametre*2/array.length;
$("#" + array[i]).css({position: "absolute", top: xFirst, left: Math.sqrt(Math.pow(r,2) - Math.pow(xFirst-r,2)) + r});
$("#" + array[array.length - i - 1]).css({position: "absolute", top: xLast, left: r - Math.sqrt(Math.pow(r,2) - Math.pow(xLast-r,2))});
}
}
function timerRun()
{
temps = temps - 1;
if( temps > 0 )
{
$("#reloj").html( temps%10 == 0 ? temps/10 + ".0" : temps/10);
currentTimeout = setTimeout("timerRun()",100);
$("#" + lletres[current]).css({ backgroundImage: "url(./current.gif)" });
}
else
{
$("#" + lletres[current]).css({ backgroundImage: "url(./default.jpg)" });
}
}
function timerStop()
{
clearTimeout( currentTimeout );
}
function checkEnd()
{
if ( Number($("#encerts").html()) + Number($("#errors").html()) == lletres.length )
{
timerStop();
alert( "Rosco acabat amb " + Number($("#encerts").html()) + " encerts i " + Number($("#errors").html()) + " errors. Quedaven " + temps + " segons.");
}
}
function encertat()
{
encerts++;
var lletra = lletres.splice(current,1);
if (current >= lletres.length)
{
current = 0;
}
$("#" + lletra).css({ backgroundImage: "url(./correct.jpg)" });
$("#" + lletres[current]).css({ backgroundImage: "url(./current.gif)" });
$("#encerts").html( Number($("#encerts").html()) + 1 );
}
function error()
{
if(!continuo)
{
timerStop();
}
var lletra = lletres.splice(current,1);
if (current >= lletres.length)
{
current = 0;
}
$("#" + lletra).css({ backgroundImage: "url(./wrong.jpg)" });
$("#" + lletres[current]).css({ backgroundImage: "url(./default.jpg)" });
$("#errors").html( Number($("#errors").html()) + 1 );
}
function pasapalabra()
{
if(!continuo)
{
timerStop();
}
var lletra = lletres[current];
current = current + 1;
if (current >= lletres.length)
{
current = 0;
}
$("#" + lletra).css({ backgroundImage: "url(./default.jpg)" });
$("#" + lletres[current]).css({ backgroundImage: "url(./default.jpg)" });
}
function acontinuo()
{
continuo = true;
}
$(function()
{
$("#start").click(timerRun);
$("#encertat").click(encertat);
$("#fallat").click(error);
$("#pasapalabra").click(pasapalabra);
$("#acontinuo").click(acontinuo);
var i;
for(i = 0; i < lletres.length; i++)
{
$("#content").append("<span id=\"" + lletres[i] + "\"><span>" + lletres[i] + "</span></span>");
}
toCercle(lletres,300);
});