@@ -173,7 +173,6 @@ int print_tableau(int y, int x, Card *bottom, Theme *theme) {
173
173
}
174
174
}
175
175
176
-
177
176
void print_pile (Pile * pile , Theme * theme ) {
178
177
int y = pile -> rule -> y * (theme -> height + theme -> y_spacing );
179
178
if (pile -> rule -> type == RULE_STOCK ) {
@@ -191,8 +190,27 @@ void print_pile(Pile *pile, Theme *theme) {
191
190
}
192
191
}
193
192
193
+ int ui_victory (Pile * piles ) {
194
+ getmaxyx (stdscr , win_h , win_w );
195
+ int start_y = win_h / 2 - 3 ;
196
+ int start_x = win_w >= 38 ? win_w / 2 - 19 : 0 ;
197
+ mvprintw (start_y , start_x , "**************************************" );
198
+ mvprintw (start_y + 1 , start_x , "* VICTORY! *" );
199
+ mvprintw (start_y + 2 , start_x , "* Press 'r' to redeal or 'q' to quit *" );
200
+ mvprintw (start_y + 3 , start_x , "**************************************" );
201
+ while (1 ) {
202
+ switch (getch ()) {
203
+ case 'r' :
204
+ return 1 ;
205
+ case 'q' :
206
+ return 0 ;
207
+ }
208
+ }
209
+ }
210
+
194
211
int ui_loop (Game * game , Theme * theme , Pile * piles ) {
195
212
MEVENT mouse ;
213
+ int move_made = 0 ;
196
214
int mouse_action = 0 ;
197
215
selection = NULL ;
198
216
selection_pile = NULL ;
@@ -224,6 +242,14 @@ int ui_loop(Game *game, Theme *theme, Pile *piles) {
224
242
refresh ();
225
243
226
244
attron (COLOR_PAIR (COLOR_PAIR_BACKGROUND ));
245
+
246
+ if (move_made ) {
247
+ if (check_win_condition (piles )) {
248
+ return ui_victory (piles );
249
+ }
250
+ move_made = 0 ;
251
+ }
252
+
227
253
int ch ;
228
254
if (mouse_action ) {
229
255
ch = mouse_action ;
@@ -291,6 +317,7 @@ int ui_loop(Game *game, Theme *theme, Pile *piles) {
291
317
if (cursor_card -> up ) {
292
318
if (selection == cursor_card ) {
293
319
if (move_to_foundation (cursor_card , cursor_pile , piles ) || move_to_free_cell (cursor_card , cursor_pile , piles )) {
320
+ move_made = 1 ;
294
321
clear ();
295
322
selection = NULL ;
296
323
selection_pile = NULL ;
@@ -301,13 +328,15 @@ int ui_loop(Game *game, Theme *theme, Pile *piles) {
301
328
}
302
329
} else if (cursor_pile -> rule -> type == RULE_STOCK ) {
303
330
if (move_to_waste (cursor_card , cursor_pile , piles )) {
331
+ move_made = 1 ;
304
332
clear ();
305
333
}
306
334
} else {
307
335
turn_card (cursor_card );
308
336
}
309
337
} else if (cursor_pile -> rule -> type == RULE_STOCK ) {
310
338
if (redeal (cursor_pile , piles )) {
339
+ move_made = 1 ;
311
340
clear ();
312
341
} else {
313
342
mvprintw (0 , 0 , "no more redeals" );
@@ -319,6 +348,7 @@ int ui_loop(Game *game, Theme *theme, Pile *piles) {
319
348
case 10 : // enter
320
349
if (selection && cursor_pile ) {
321
350
if (legal_move_stack (cursor_pile , selection , selection_pile )) {
351
+ move_made = 1 ;
322
352
clear ();
323
353
selection = NULL ;
324
354
selection_pile = NULL ;
@@ -327,6 +357,7 @@ int ui_loop(Game *game, Theme *theme, Pile *piles) {
327
357
break ;
328
358
case 'a' :
329
359
if (auto_move_to_foundation (piles )) {
360
+ move_made = 1 ;
330
361
clear ();
331
362
}
332
363
break ;
0 commit comments