From deb68bff30f081b18bc06257aafb23eb28da4b50 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 2 Jan 2022 19:48:34 +0000 Subject: Added autofill when puzzle complete. --- klondike.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/klondike.c b/klondike.c index 153cb03..539553d 100644 --- a/klondike.c +++ b/klondike.c @@ -137,6 +137,7 @@ static void KlondikeHelp(void) "", "Use 'P' to put the current card on the suits piles.", "If invalid it will attempt to move the card from the drawn pile.", + "If the cards are all shown this will automatically finish the puzzle.", "", "Press '1', '2', '3' or '4' to move the top card from the hearts, ", "diamonds, spades or clubs suit pile respectively back onto the board.", @@ -181,6 +182,7 @@ int Klondike(int draw, int thoughtful) int won = FALSE; int quit = FALSE; int show = FALSE; + int autofill = FALSE; int pos_x = 0; int pos_y = 0; int move_pos_x = -1; @@ -254,6 +256,18 @@ int Klondike(int draw, int thoughtful) mvaddch(2 + column_down[pos_x].no + pos_y, pos_x * 5 + 4, '<'); } + if (autofill) + { + for(f = 0; f < 7; f++) + { + if (PutCardOnSuitPile(&column_up[f], + &hearts, &diamonds, &spades, &clubs)) + { + RevealCard(&column_down[pos_x], &column_up[pos_x]); + } + } + } + if (hearts.no == 13 && diamonds.no == 13 && spades.no == 13 && clubs.no == 13) { @@ -262,7 +276,7 @@ int Klondike(int draw, int thoughtful) refresh(); - if (!won) + if (!won && !autofill) { key = getch(); } @@ -321,6 +335,20 @@ int Klondike(int draw, int thoughtful) PutCardOnSuitPile(&turned, &hearts, &diamonds, &spades, &clubs); } + + if (pile.no == 0 && turned.no == 0) + { + autofill = TRUE; + + for(f = 0; f < 7; f++) + { + if (column_down[f].no) + { + autofill = FALSE; + } + } + } + break; case 'Q': -- cgit v1.2.3