-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·435 lines (426 loc) · 19 KB
/
Copy pathscript.js
File metadata and controls
executable file
·435 lines (426 loc) · 19 KB
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
/* using indexs for batsmen and names for bowler */
var app = angular.module("app",['ngSanitize']);
app.controller("cricket",function($scope,$http,$window,$filter){
$scope.page = "p1"; //to navigate from one page to another page
$scope.overs = 0.0 //to calculAte no of overs
//to set overs limit
$scope.thisover = 0.0 //to handle individual overs
$scope.count=0
$scope.overar ={0:-1,1:-1,2:-1,3:-1,4:-1,5:-1} //to collect balls result in an over
$scope.balcount=0; //for balls count
$scope.striker //to handle striker index
$scope.nonstriker //to handle nonstriker index
$scope.wickets=0 //for wicket count
$scope.Innigs=0 //for innings count
$scope.target=100000000 //for 2nd inning target
$scope.runs = 0
$scope.selection =2
$scope.display_swap = true
$scope.previous_bowler=""
$scope.toss = undefined
$scope.num_balls =0
$scope.num_overs = [2,5,10,15,20,15,20,25,30,35,40,45,50]
/* teamplayer is a dataset handle complete details of indiviual players
teama : carries team-A data
teamb : carries team-B data
name : for player name,
runs : for player runs,
wickets : to calculate bowler wickets count,
ball_runs : total no of runs given by bowler,
balls : no of balls by bowler,
catch : if he is catch out by opp name,
stump : if he is stump out by opp name,
throw : if he is throw out by opp name,
visited : if batsmen visited then it is true
*/
$scope.teamplayer = {
"teama":{
0:{"name":"saketh","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
1:{"name":"vinay","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
2:{"name":"vikram","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
3:{"name":"nanda","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
4:{"name":"sastri","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
5:{"name":"nagendra","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
6:{"name":"dhoni","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
7:{"name":"dravid","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},//
8:{"name":"ashwin","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
9:{"name":"kumble","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
10:{"name":"yuvaraj","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false}
},
"teamb":{
0:{"name":"kalyan","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
1:{"name":"ravi","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
2:{"name":"ganguly","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
3:{"name":"nagarjuna","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
4:{"name":"jadega","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
5:{"name":"kohili","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
6:{"name":"abd","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
7:{"name":"raina","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
8:{"name":"gavaskar","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
9:{"name":"bumrah","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false},
10:{"name":"pandey","runs":0,"wickets":0,"ball_runs":0,"balls":0,"bowling_balls":0,"catch":undefined,"stump":undefined,"throw":undefined,"wicket":undefined,"visited":false}
}
}
/*
teama : handle team-A brief data
teaab : handle team-B brief data
name : for team name
score : for team score
wickets : for team wickets
captian : for captian name
wiki : for wiki-keeper name
*/
$scope.team = {
"teama":{"name":"Chennai","score":0,"wickets":0,"captian":"saketh","wiki":"dhoni"},
"teamb":{"name":"Kolkatta","score":0,"wickets":0,"captian":"kalyan","wiki":"abd"},
"overs":2
};
/* score fuction to navigate to p2 */
$scope.navigate = function(a){
$scope.page = a
}
$scope.wide = function(a)
{
$scope.team[$scope.batting].score += a
$scope.page = 'p3'
}
$scope.swap = function()
{
var temp
temp = $scope.nonstriker
$scope.nonstriker = $scope.striker
$scope.striker = temp
$scope.display_swap = false
}
$scope.out = function(a,b,runs,outer)
{
if(a == "runout" && $scope.runs < 0)
return
if(a=="stump")
{
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.batting][$scope.striker].stump = $scope.team[$scope.bowling].wiki
$scope.teamplayer[$scope.batting][$scope.striker].runs += 0
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += 0
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
}
else if(a=="wicket")
{
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.batting][$scope.striker].wicket = $scope.teamplayer[$scope.bowling][$scope.bowler].name
$scope.teamplayer[$scope.batting][$scope.striker].runs += 0
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += 0
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
}
else if(a=="catch")
{
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.batting][$scope.striker].wicket = $scope.teamplayer[$scope.bowling][$scope.bowler].name
$scope.teamplayer[$scope.batting][$scope.striker].catch = $scope.teamplayer[$scope.bowling][b].name //who catched (b)
$scope.teamplayer[$scope.batting][$scope.striker].runs += runs
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += runs
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
}
else if(a=="runout")
{
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.batting][outer].wicket = $scope.teamplayer[$scope.bowling][$scope.bowler].name
$scope.teamplayer[$scope.batting][outer].throw = $scope.teamplayer[$scope.bowling][b].name //who throws ball (b)
$scope.teamplayer[$scope.batting][$scope.striker].runs += runs
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += runs
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
if($scope.nonstriker == outer)
{
var temp = $scope.striker
$scope.striker = outer
$scope.nonstriker = temp
}
}
$scope.teamplayer[$scope.bowling][$scope.bowler].wickets +=1
$scope.team[$scope.batting].wickets +=1
$scope.balcount += 1
$scope.team[$scope.batting].score += runs
$scope.thisover += 0.1
$scope.overar[$scope.balcount]=-2
$scope.overs = $scope.count+$scope.thisover
$scope.runs = 0
$scope.display_swap = true
$scope.wickets++
if($scope.wickets!=10 )
{
$scope.page = 'batsmen'
$scope.selection = 4
}
else
{
$scope.reset()
$scope.page = 'batsmen'
$scope.selection = 2
$scope.wickets=0
if($scope.Innigs ==2)
{
$scope.page="p4"
if($scope.team[$scope.batting].score > $scope.team[$scope.bowling].score)
{
$scope.winner = $scope.team[$scope.batting].name + " Won By "+($scope.team[$scope.batting].score-$scope.team[$scope.bowling].score)+ " Runs" /* 1st bat team wins */
}
else if($scope.team[$scope.batting].score == $scope.team[$scope.bowling].score)
{
$scope.winner = "Draw Match"
}
else
{
$scope.winner = $scope.team[$scope.bowling].name + " Won By "+(10-$scope.team[$scope.bowling].wickets)+ " Wickets"
}
}
}
if($scope.thisover == 0.5)
{
var temp = $scope.nonstriker
$scope.nonstriker = $scope.striker
$scope.striker = temp
}
$scope.num_balls++
}
$scope.reset = function ()
{
$scope.target = $scope.team[$scope.batting].score
$scope.Innigs++
$scope.overs=0.0
$scope.thisover = 0.0
$scope.count=0
$scope.num_balls = 0
$scope.overar ={0:-1,1:-1,2:-1,3:-1,4:-1,5:-1}
$scope.balcount=0;
var temp = $scope.batting
$scope.batting = $scope.bowling
$scope.bowling = temp
$scope.wickets = 0
}
$scope.set = function(a,b,c,type)
{
if((type=="opening") && (a != undefined && b!=undefined && c != undefined) && (a!=b)) // opening selection
{
$scope.striker = a
$scope.nonstriker = b
$scope.bowler = c
$scope.teamplayer[$scope.batting][$scope.striker].visited = true
$scope.teamplayer[$scope.batting][$scope.nonstriker].visited = true
$scope.page = "p3"
$scope.com = "<b>" + $scope.teamplayer[$scope.batting][$scope.striker].name + " and " + $scope.teamplayer[$scope.batting][$scope.nonstriker].name + " are the openers" + $scope.com
$scope.com = "<b>" + $scope.teamplayer[$scope.bowling][$scope.bowler].name + " has came to ATTACK!!!</b><br>"+$scope.com
}
else if(type=="bowler" && c !=undefined) //bowler
{
$scope.bowler = c
$scope.previous_bowler = $scope.teamplayer[$scope.bowling][c].name
$scope.page = "p3"
$scope.teamplayer[$scope.batting][$scope.striker].visited = true
$scope.teamplayer[$scope.batting][$scope.nonstriker].visited = true
$scope.thisover = 0.0
$scope.overs += 0.4
$scope.count++
$scope.overar ={0:-1,1:-1,2:-1,3:-1,4:-1,5:-1}
$scope.balcount =0;
$scope.com = "<b>"+ $scope.teamplayer[$scope.bowling][$scope.bowler].name + " has came to ATTACK!!!</b><br>"+$scope.com
}
else if(type=="bowbat" && a != undefined && c != undefined) //overup and wicket
{
$scope.striker = a
$scope.bowler = c
$scope.previous_bowler = $scope.teamplayer[$scope.bowling][c].name
$scope.page = "p3"
$scope.teamplayer[$scope.batting][$scope.striker].visited = true
$scope.teamplayer[$scope.batting][$scope.nonstriker].visited = true
$scope.thisover = 0.0
$scope.overs += 0.4
$scope.count++
$scope.overar ={0:-1,1:-1,2:-1,3:-1,4:-1,5:-1}
$scope.balcount =0;
var temp = $scope.nonstriker
$scope.nonstriker = $scope.striker
$scope.striker = temp
$scope.com = "<b>" + $scope.teamplayer[$scope.bowling][$scope.bowler].name + " has came to ATTACK!!!</b><br>"+$scope.com
$scope.com = "<b>" + $scope.teamplayer[$scope.batting][$scope.nonstriker].name + " has came to Feild </b><br>"+$scope.com
}
else if(type=="wicket" && a != undefined) // batsmen selection page
{
$scope.striker = a
$scope.page = "p3"
$scope.teamplayer[$scope.batting][$scope.striker].visited = true
$scope.com = "<b>" + $filter('number')($scope.overs, 1) + " " + $scope.teamplayer[$scope.batting][$scope.striker].name + " has came to Feild </b><br>"+$scope.com
}
if($scope.wickets==10 || $scope.num_balls == $scope.opt * 6) //executes if wkts = 10 or target is chased (reset every one)
{
//reset
$scope.reset()
$scope.page = "batsmen"
$scope.selection = 2
if($scope.Innigs ==2)
{
$scope.page="p4"
if($scope.team[$scope.batting].score > $scope.team[$scope.bowling].score)
{
$scope.winner = $scope.team[$scope.batting].name + " Won By "+($scope.team[$scope.batting].score-$scope.team[$scope.bowling].score)+ " Runs" /* 1st bat team wins */
}
else if($scope.team[$scope.batting].score == $scope.team[$scope.bowling].score)
{
$scope.winner = "Draw Match"
}
else
{
$scope.winner = $scope.team[$scope.bowling].name + " Won By "+(10-$scope.team[$scope.bowling].wickets)+ " Wickets"
}
}
}
}
$scope.indexOf = function (element,key)
{
for (var i = 0; i <= 10; i++)
{
if (element[i].name == key)
{
return i;
}
}
return -1;
}
let getmsg = function(a){
let msg = ""
if(a == 0){
msg = "its an Dot <b>[0]</b>"
}
else if(a == 4){
msg = "Hurray its a \"Four\" well play <b>" + $scope.teamplayer[$scope.batting][$scope.striker].name + "</b>"
}
else if(a == 6){
msg = "OMG!!! Maximum Shot its a \"Six\" Good Shot <b>" + $scope.teamplayer[$scope.batting][$scope.striker].name + "</b>"
}
else{
msg = "has <b>" + a + "</b> runs"
}
return msg
}
/* update is for ball */
$scope.update = function(a) //mainly focus on batting side
{
console.log($scope)
$scope.display_swap = false
$scope.num_balls++
if($scope.thisover == 0.5)
{
$scope.com = "<b>" +$filter('number')($scope.overs, 1) + "</b> <center>" + $scope.teamplayer[$scope.bowling][$scope.bowler].name + " to " + $scope.teamplayer[$scope.batting][$scope.striker].name + " : " + getmsg(a) + "</center><br>" + $scope.com
$scope.com = "Overup!!!<br>" + $scope.com
$scope.balcount += 1
$scope.team[$scope.batting].score += a
$scope.thisover += 0.1
$scope.overar[$scope.balcount]=a
$scope.overs = $scope.count+$scope.thisover
$scope.teamplayer[$scope.batting][$scope.striker].runs += a
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += a
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
$scope.selection = 3
$scope.page = 'batsmen'
var temp = $scope.nonstriker
$scope.nonstriker = $scope.striker
$scope.striker = temp
}
else if(a != -1) //update score and balls player individual score (batsmen)
{
$scope.balcount += 1
$scope.team[$scope.batting].score += a
$scope.thisover += 0.1
$scope.overar[$scope.balcount]=a
$scope.overs = $scope.count+$scope.thisover
$scope.teamplayer[$scope.batting][$scope.striker].runs += a
$scope.teamplayer[$scope.batting][$scope.striker].balls += 1
$scope.teamplayer[$scope.bowling][$scope.bowler].ball_runs += a
$scope.teamplayer[$scope.bowling][$scope.bowler].bowling_balls += 1
$scope.com = "<b>" +$filter('number')($scope.overs, 1) + "</b> <center>" + $scope.teamplayer[$scope.bowling][$scope.bowler].name + " to " + $scope.teamplayer[$scope.batting][$scope.striker].name + " : " + getmsg(a) + "</center><br>" + $scope.com
}
if(a%2==1) //executes if over up or odd runs by batting rteam
{
var temp;
temp = $scope.striker
$scope.striker = $scope.nonstriker
$scope.nonstriker = temp
}
if($scope.target < $scope.team[$scope.batting].score || $scope.opt * 6 < $scope.num_balls ) //executes if wkts = 10 or target is chased (reset every one)
{
$scope.reset()
$scope.page = 'batsmen'
$scope.selection = 2
if($scope.Innigs ==2)
{
$scope.page="p4"
if($scope.team[$scope.batting].score > $scope.team[$scope.bowling].score)
{
$scope.winner = $scope.team[$scope.batting].name + " Won By "+($scope.team[$scope.batting].score-$scope.team[$scope.bowling].score)+ " Runs" /* 1st bat team wins */
}
else if($scope.team[$scope.batting].score == $scope.team[$scope.bowling].score)
{
$scope.winner = "Draw Match"
}
else
{
$scope.winner = $scope.team[$scope.bowling].name + " Won By "+(10-$scope.team[$scope.bowling].wickets)+ " Wickets"
}
}
}
}
/* Random is to get random value */
$scope.random = function(){
var d = new Date();
var n = d.getMilliseconds();
n = d.getMilliseconds() + 111 * 221
if(n%2 == 1)
return "head"
else
return "tail"
}
/* function for toss */
$scope.tossfun = function(a){
$scope.opt = Number($scope.team.overs)
if($scope.b < 2)
return
if(a == $scope.random())
{
$scope.toss = $scope.team.teama['name']
$scope.nontoss = $scope.team.teamb['name']
}
else
{
$scope.toss = $scope.team.teamb['name']
$scope.nontoss = $scope.team.teama['name']
}
}
$scope.setteam = function (a)
{
$scope.com = (a=="batting" ? "Bat" : " Feild")
$scope.com = "<center><b>" + $scope.toss + "</b>" + " has won the toss and choose to " + $scope.com + " <b>first</b></center>"
if($scope.toss == $scope.team['teama'].name)
{
$scope.toss = 'teama'
$scope.nontoss = 'teamb'
}
else
{
$scope.toss = 'teamb'
$scope.nontoss = 'teama'
}
if(a=='batting')
{
$scope.batting = $scope.toss
$scope.bowling = $scope.nontoss
}
else
{
$scope.bowling = $scope.toss
$scope.batting = $scope.nontoss
}
$scope.navigate('batsmen')
$scope.selection = 2
}
})