@@ -150,33 +150,50 @@ void printDashboardByConsole(TGame* pGame) {
150150 int i ;
151151 int j ;
152152
153- for (i = 0 ; i < pGame -> cols + 2 ; i ++ ) printf ("-" );
154- printf ("\n" );
155-
156153 for (i = 0 ; i < pGame -> rows ; i ++ ) {
157- printf ("|" );
154+ printf ("\n" );
155+
158156 for (j = 0 ; j < pGame -> cols ; j ++ ) {
159157 printf ("%c" , pGame -> dashboard [i ][j ]);
160158 }
161-
162- printf ("|\n" );
163159 }
164-
165- for (i = 0 ; i < pGame -> cols + 2 ; i ++ ) printf ("-" );
166160}
167161
168- void printGame (TGame * pGame ) {
162+ void printGameByConsole (TGame * pGame ) {
169163 int i ;
164+ int j ;
165+
166+ // Print header
170167 for (i = 0 ; i < pGame -> cols + 2 ; i ++ ) printf ("-" );
171168
172169 printf ("\n| Cells alive: %*d |" , pGame -> cols - 17 + 2 , pGame -> cellsAlive );
173170 printf ("\n| Cells dead: %*d |" , pGame -> cols - 16 + 2 , pGame -> cellsDead );
174171 printf ("\n| Generation: %*d |" , pGame -> cols - 16 + 2 , pGame -> generation );
175- printf ("\n| Maximum generation: %*d |" , pGame -> cols - 25 + 3 , pGame -> maximumGeneration );
176- printf ("\n| Delay between generations: %*d |\n" , pGame -> cols - 32 + 3 ,
172+
173+ if (pGame -> maximumGeneration == INT_MAX ) {
174+ printf ("\n| Maximum generation: %*s |" , pGame -> cols - 25 + 3 , "infinity" );
175+ } else {
176+ printf ("\n| Maximum generation: %*d |" , pGame -> cols - 25 + 3 , pGame -> maximumGeneration );
177+ }
178+
179+ printf ("\n| Delay between generations: %*d ms |\n" , pGame -> cols - 35 + 3 ,
177180 pGame -> delayBetweenGenerations );
178181
179- printDashboardByConsole (pGame );
182+ // Print dashboard
183+ for (i = 0 ; i < pGame -> cols + 2 ; i ++ ) printf ("-" );
184+
185+ for (i = 0 ; i < pGame -> rows ; i ++ ) {
186+ printf ("\n|" );
187+
188+ for (j = 0 ; j < pGame -> cols ; j ++ ) {
189+ printf ("%c" , pGame -> dashboard [i ][j ]);
190+ }
191+
192+ printf ("|" );
193+ }
194+
195+ printf ("\n" );
196+ for (i = 0 ; i < pGame -> cols + 2 ; i ++ ) printf ("-" );
180197}
181198
182199void setDashboardCenter (TGame * pGame ) {
@@ -189,25 +206,25 @@ void setDashboardCenter(TGame* pGame) {
189206
190207void startGameByConsole (TGame * pGame , int maxGeneration , int delayBetweenGenerations ) {
191208 int generation = 0 ;
209+ int isToInfinity = maxGeneration == INT_MAX ;
192210
193211 pGame -> generation = 0 ;
194212 pGame -> maximumGeneration = maxGeneration ;
195213 pGame -> delayBetweenGenerations = delayBetweenGenerations ;
196214
197215 system ("cls" );
198- printGame (pGame );
216+ printGameByConsole (pGame );
199217 if (generation == maxGeneration ) return ;
200218 sleep (delayBetweenGenerations );
201219
202- while (generation < maxGeneration ) {
220+ while (isToInfinity || generation < maxGeneration ) {
203221 generateNextGeneration (pGame );
204222
205- generation ++ ;
206-
223+ if (generation + 1 != INT_MAX ) generation ++ ;
207224 pGame -> generation = generation ;
208225
209226 system ("cls" );
210- printGame (pGame );
227+ printGameByConsole (pGame );
211228 if (generation != maxGeneration ) sleep (delayBetweenGenerations );
212229 }
213230}
0 commit comments