@@ -14,10 +14,21 @@ public partial class FigureForm : Form
1414 {
1515 public List < string > images = new List < string > ( ) ;
1616 public List < string > imageHolder = new List < string > ( ) ;
17+ private List < int > quantityList = new List < int > ( ) ;
1718
1819 public List < Interval > intervals = new List < Interval > ( ) ;
1920 public List < int > times = new List < int > ( ) ;
2021 public int startTime ;
22+ private bool playPauseToggle = true ;
23+
24+ private bool wasSkip = false ;
25+
26+ private int secondsSpent = 0 ;
27+ private int figuresCompleted = 0 ;
28+
29+ private int currentTimeInterval = 0 ;
30+
31+ private int figCount = 0 ;
2132
2233 public FigureForm ( )
2334 {
@@ -28,6 +39,7 @@ private void buildTimes()
2839 {
2940 foreach ( Interval interval in intervals )
3041 {
42+ quantityList . Add ( interval . getQuantity ( ) ) ;
3143 for ( int i = 0 ; i < interval . getQuantity ( ) ; i ++ )
3244 {
3345 if ( interval . getUnit ( ) . Equals ( "Minutes" ) )
@@ -43,9 +55,34 @@ private void buildTimes()
4355 }
4456 }
4557
58+ private void shuffle ( IList < string > listIn )
59+ {
60+ Random rand = new Random ( ) ;
61+
62+ for ( int i = listIn . Count - 1 ; i > 0 ; i -- )
63+ {
64+ int k = rand . Next ( i + 1 ) ;
65+ string value = listIn [ k ] ;
66+ listIn [ k ] = listIn [ i ] ;
67+ listIn [ i ] = value ;
68+ }
69+ }
70+
71+ private void FigureForm_FormClosing ( object sender , FormClosingEventArgs e )
72+ {
73+ FigureTimer . Stop ( ) ;
74+ FigureTimer . Tick -= timerTick ;
75+ FigureTimer = new System . Windows . Forms . Timer ( ) ;
76+ }
77+
4678 private void FigureForm_Load ( object sender , EventArgs e )
4779 {
4880 this . WindowState = FormWindowState . Maximized ;
81+ this . FormClosing += new FormClosingEventHandler ( FigureForm_FormClosing ) ;
82+ PausePlayButton . Text = "⏸" ;
83+
84+ shuffle ( images ) ;
85+
4986 figureImage . Image = Image . FromFile ( images [ 0 ] ) ;
5087 imageHolder . Add ( images [ 0 ] ) ;
5188 images . RemoveAt ( 0 ) ;
@@ -54,53 +91,170 @@ private void FigureForm_Load(object sender, EventArgs e)
5491 buildTimes ( ) ;
5592
5693 startTime = times [ 0 ] ;
94+ figCount = quantityList [ 0 ] ;
95+ currentTimeInterval = startTime ;
5796 times . RemoveAt ( 0 ) ;
97+ quantityList . RemoveAt ( 0 ) ;
98+
99+ FiguresLeftLabel . Text = "Figures Left: " + figCount . ToString ( ) ;
58100
59101 FigureTimer . Tick += timerTick ;
60102 FigureTimer . Interval = 1000 ;
61103 FigureTimer . Start ( ) ;
62104
63105 }
64106
65- private void timerTick ( object sends , EventArgs e )
107+ private void nextImage ( )
66108 {
67- startTime -- ;
68- TimeLabel . Text = startTime . ToString ( ) ;
109+ if ( images . Count != 0 )
110+ {
111+ figureImage . Image = Image . FromFile ( images [ 0 ] ) ;
112+ imageHolder . Add ( images [ 0 ] ) ;
113+ images . RemoveAt ( 0 ) ;
114+ }
115+ else
116+ {
117+ foreach ( string image in imageHolder )
118+ {
119+ images . Add ( image ) ;
120+ }
69121
70- if ( startTime == 0 )
122+ imageHolder = new List < string > ( ) ;
123+ shuffle ( images ) ;
124+ figureImage . Image = Image . FromFile ( images [ 0 ] ) ;
125+ imageHolder . Add ( images [ 0 ] ) ;
126+ images . RemoveAt ( 0 ) ;
127+ }
128+ if ( ! wasSkip )
71129 {
72- FigureTimer . Stop ( ) ;
130+ figuresCompleted += 1 ;
131+ }
132+ }
73133
74- if ( times . Count != 0 )
75- {
76- startTime = times [ 0 ] + 1 ;
77- times . RemoveAt ( 0 ) ;
134+ private void updateStats ( )
135+ {
136+
137+ if ( File . Exists ( "stats.txt" ) )
138+ {
139+ int currentSeconds = 0 ;
140+ int currentSessions = 0 ;
141+ int currentFigures = 0 ;
142+ int lineNum = 0 ;
78143
79- if ( images . Count != 0 )
144+ IEnumerable < string > lines = File . ReadLines ( "stats.txt" ) ;
145+
146+ foreach ( string line in lines )
147+ {
148+ if ( lineNum == 0 )
80149 {
81- figureImage . Image = Image . FromFile ( images [ 0 ] ) ;
82- imageHolder . Add ( images [ 0 ] ) ;
83- images . RemoveAt ( 0 ) ;
84- }
85- else
150+ currentSeconds = Int32 . Parse ( line . Substring ( line . IndexOf ( "]" ) + 1 ) ) ;
151+ } else if ( lineNum == 1 )
152+ {
153+ currentSessions = Int32 . Parse ( line . Substring ( line . IndexOf ( "]" ) + 1 ) ) ;
154+ } else if ( lineNum == 2 )
86155 {
87- foreach ( string image in imageHolder )
88- {
89- images . Add ( image ) ;
90- }
156+ currentFigures = Int32 . Parse ( line . Substring ( line . IndexOf ( "]" ) + 1 ) ) ;
91157 }
92-
158+ lineNum ++ ;
159+ }
160+
161+ File . Delete ( "stats.txt" ) ;
93162
94- FigureTimer . Start ( ) ;
163+ using ( StreamWriter writer = new StreamWriter ( "stats.txt" ) )
164+ {
165+ writer . WriteLine ( "[TimeSpentDrawing]" + ( currentSeconds + secondsSpent ) . ToString ( ) ) ;
166+ writer . WriteLine ( "[NumberOfSessions]" + ( currentSessions + 1 ) . ToString ( ) ) ;
167+ writer . WriteLine ( "[NumberOfFigures]" + ( figuresCompleted + currentFigures ) . ToString ( ) ) ;
95168 }
96- else
169+ }
170+ else
171+ {
172+ using ( StreamWriter writer = new StreamWriter ( "stats.txt" ) )
97173 {
98- MessageBox . Show ( "Session completed!" ) ;
99- this . Close ( ) ;
174+ writer . WriteLine ( "[TimeSpentDrawing]" + secondsSpent . ToString ( ) ) ;
175+ writer . WriteLine ( "[NumberOfSessions]1" ) ;
176+ writer . WriteLine ( "[NumberOfFigures]" + figuresCompleted . ToString ( ) ) ;
100177 }
101-
102-
103178 }
104179 }
180+
181+ private void updateTime ( )
182+ {
183+ FigureTimer . Stop ( ) ;
184+
185+ if ( times . Count != 0 )
186+ {
187+ startTime = times [ 0 ] ;
188+ currentTimeInterval = startTime ;
189+ times . RemoveAt ( 0 ) ;
190+
191+ nextImage ( ) ;
192+
193+ FigureTimer . Start ( ) ;
194+ }
195+ else
196+ {
197+ MessageBox . Show ( "Session completed!" ) ;
198+ FigureTimer . Tick -= timerTick ;
199+ updateStats ( ) ;
200+ this . Close ( ) ;
201+ }
202+
203+ figCount -= 1 ;
204+
205+ if ( figCount == 0 && quantityList . Count != 0 )
206+ {
207+ figCount = quantityList [ 0 ] ;
208+ quantityList . RemoveAt ( 0 ) ;
209+ }
210+
211+ FiguresLeftLabel . Text = "Figures Left: " + figCount . ToString ( ) ;
212+
213+
214+ }
215+
216+ private void timerTick ( object sends , EventArgs e )
217+ {
218+ startTime -- ;
219+ secondsSpent += 1 ;
220+ TimeLabel . Text = startTime . ToString ( ) ;
221+
222+ if ( startTime == 0 )
223+ {
224+ updateTime ( ) ;
225+ }
226+ }
227+
228+ private void PausePlayButton_Click ( object sender , EventArgs e )
229+ {
230+ if ( playPauseToggle )
231+ {
232+ PausePlayButton . Text = "▶" ;
233+ playPauseToggle = false ;
234+ FigureTimer . Stop ( ) ;
235+ }
236+ else
237+ {
238+ PausePlayButton . Text = "⏸" ;
239+ playPauseToggle = true ;
240+ FigureTimer . Start ( ) ;
241+ }
242+ }
243+
244+ private void SkipImageButton_Click ( object sender , EventArgs e )
245+ {
246+ FigureTimer . Stop ( ) ;
247+ wasSkip = true ;
248+ nextImage ( ) ;
249+ wasSkip = false ;
250+
251+ startTime = currentTimeInterval ;
252+ FigureTimer . Start ( ) ;
253+ }
254+
255+ private void SkipTimeButton_Click ( object sender , EventArgs e )
256+ {
257+ updateTime ( ) ;
258+ }
105259 }
106260}
0 commit comments