-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScore.cs
149 lines (130 loc) · 4.28 KB
/
Score.cs
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
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using System.Timers;
namespace UmpireCounterMAUI
{
public static class Score
{
public static int Total { get; set; }
public static int Wickets { get; set; }
public static int ValidDeliveriesInOver { get; set; }
public static int OversCompleted { get; set; }
public static int BallsInOver { get; set; }
public static bool InningsInPlay { get; set; }
public static DateTime InningsStartTime { get; set; }
public static string InningsTime { get; set; }
public static TimeSpan TimeSinceTimerUpdate { get; set; }
public static DateTime TimeLastUpdated { get; set; }
public static bool AnyButtonPressed { get; set; }
public static bool TimeChanged { get; set; }
public static System.Timers.Timer inningsTimerCheckerTimer;
/*public static void CheckingTimer()
{
inningsTimerCheckerTimer = new System.Timers.Timer();
inningsTimerCheckerTimer.Interval = 30000;
inningsTimerCheckerTimer.Elapsed += Score.CheckUpdateTimer;
inningsTimerCheckerTimer.AutoReset = true;
inningsTimerCheckerTimer.Enabled = true;
}
*/
public static void IncreaseBalls()
{
Score.ValidDeliveriesInOver++;
if (Score.ValidDeliveriesInOver == Score.BallsInOver)
{
Score.OversCompleted++;
Score.ValidDeliveriesInOver = 0;
}
if (!Score.InningsInPlay)
{
Score.InningsStartTime = DateTime.Now;
Score.InningsInPlay = true;
}
TextFileStorage.WriteScore();
}
public static void DecreaseBalls()
{
if (Score.ValidDeliveriesInOver == 0)
{
Score.ValidDeliveriesInOver = (Score.BallsInOver - 1);
Score.OversCompleted--;
}
else
{
Score.ValidDeliveriesInOver--;
}
if (Score.OversCompleted < 0)
{
Score.OversCompleted = 0;
Score.ValidDeliveriesInOver = 0;
}
TextFileStorage.WriteScore();
}
public static void IncreaseTotal()
{
Score.Total++;
TextFileStorage.WriteScore();
if (!Score.InningsInPlay)
{
Score.InningsStartTime = DateTime.Now;
Score.InningsInPlay = true;
}
}
public static void DecreaseTotal()
{
Score.Total--;
if (Score.Total < 0)
{
Score.Total = 0;
}
TextFileStorage.WriteScore();
}
public static void IncreaseWickets()
{
Score.Wickets++;
TextFileStorage.WriteScore();
if (!Score.InningsInPlay)
{
Score.InningsStartTime = DateTime.Now;
Score.InningsInPlay = true;
}
}
public static void DecreaseWickets()
{
Score.Wickets--;
if (Score.Wickets < 0)
{
Score.Wickets = 0;
}
TextFileStorage.WriteScore();
}
public static void ResetScore()
{
Score.Total = 0;
Score.Wickets = 0;
Score.OversCompleted = 0;
Score.ValidDeliveriesInOver = 0;
Score.InningsTime = "Innings hasn't started";
Score.InningsInPlay = false;
}
public static void UpdateInningsTimer()
{
Score.InningsTime = DateTime.Now.Subtract(Score.InningsStartTime).Minutes.ToString() + " minute(s)";
Score.TimeLastUpdated = DateTime.Now;
}
public static void CheckUpdateTimer()
{
if (Score.InningsTime != "Innings hasn't started")
{
int minutesSinceUpdate = DateTime.Now.Subtract(Score.TimeLastUpdated).Minutes;
if (minutesSinceUpdate >= 1)
{
Score.TimeChanged = true;
Score.UpdateInningsTimer();
}
}
}
}
}