-
Notifications
You must be signed in to change notification settings - Fork 0
/
Control.js
128 lines (128 loc) · 3.45 KB
/
Control.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
var ovrKpr = 0.0;
var ttlrn = 0;
var strk = new Array(1, 0);
var nStrk = new Array(2, 0);
var hold = 0;
var wktKpr = 0;
var firstInning = 0;
function ovrs() {
if(((ovrKpr * 10) % 10) >= 5) {
ovrKpr += 0.5;
strkSwap();
}
else {
ovrKpr += 0.1;
}
ovrKpr = parseInt(Math.round(ovrKpr * 10)) / 10;
$("#overs").text(ovrKpr);
}
function ttl(run) {
ttlrn += run;
$("#tot").text(ttlrn);
}
function runStrk(run) {
strk[1] += run;
$("#bSScore").text(strk[1]);
}
function strkSwap() {
var temp1 = strk;
strk = nStrk;
nStrk = temp1;
$("#bS").text(strk[0]);
$("#bNS").text(nStrk[0]);
$("#bSScore").text(strk[1]);
$("#bNSScore").text(nStrk[1]);
}
function tableEvents() {
$(".points").on("click", function() {
var pnt = parseInt($(this).text());
ttl(pnt);
if(hold == 0) {
runStrk(pnt);
ovrs();
}
else {
hold = 0;
$("#ctHead").text("Runs");
$("#ctHead").css("background-color", "#63ff8f");
$(".btns").css("display", "table-row");
}
switch(pnt) {
case 1:
case 3:
strkSwap();
break;
}
});
$(".extras").on("click", function() {
var elmId = $(this).attr("id");
var message = "Extra Runs";
switch(elmId) {
case "wkt":
wktKpr += 1;
$("#wkts").text(wktKpr);
$(".pts").css("display", "none");
$("#wktType").css("display", "table-row");
message = "Bowled Player";
ovrs();
break;
case "nb":
case "wd":
ttl(1);
break;
case "bye":
case "lby":
ovrs();
break;
}
hold = 1;
$("#ctHead").text(message);
$("#ctHead").css("background-color", "#ff571e");
$(".btns").css("display", "none");
});
$("#wS, #wNS").on("click", function() {
var elemId = $(this).attr("id");
var part = elemId.substr(1);
if(part == "S") {
strk = [(wktKpr + 2), 0];
}
else if(part == "NS"){
nStrk = [(wktKpr + 2), 0];
}
$("#b" + part).text(wktKpr + 2);
$("#b" + part + "Score").text("0");
$(".pts").css("display", "table-row");
$("#wktType").css("display", "none");
$("#ctHead").text("Extra Runs");
if(wktKpr == 10) {
if(firstInning == 0) {
$("#bS").text("1");
$("#bNS").text("2");
$("#bSScore").text("0");
$("#bNSScore").text("0");
$("#tot").text("0");
$("#inngs").text(ttlrn);
$("#wkts").text("0");
$("#overs").text("0");
firstInning = ttlrn;
ttlrn = 0;
ovrKpr = 0.0;
strk = [1, 0];
nStrk = [2, 0];
hold = 0;
wktKpr = 0;
}
else {
if(firstInning > ttlrn) {
alert("First Batting Team is Winner!");
}
else if(firstInning < ttlrn) {
alert("Second Batting Team is Winner!");
}
else {
alert("It is a Tie!");
}
}
}
});
}