From 3671091be220ebed449be036f0b94041155ef476 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 20 Dec 2018 08:49:56 +0000 Subject: Added win screen and allowed cars to be moved from suit piles back onto the board. --- csol.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 149 insertions(+), 5 deletions(-) (limited to 'csol.c') diff --git a/csol.c b/csol.c index 5d9524d..ea3d2ff 100644 --- a/csol.c +++ b/csol.c @@ -29,7 +29,6 @@ #include #include -#include #include typedef enum @@ -258,6 +257,111 @@ static void DrawCard(int y, int x, int face_down, Card c) } } +static double DRand() +{ + return (double)(rand() % 1000) / 1000.0; +} + +static void WinScreen() +{ + static const char *text[] = + { + "# # ## # # # # ## # #", + " # # # # # # # # # # ## #", + " # # # # # # # # # # # ##", + " # # # # # ## ## # # # #", + " # ## ## # # ## # #", + NULL, + }; + + static const int NO_STAR = 100; + + typedef struct + { + double x,y,yi; + } Star; + + Star *star; + + int f; + + star = malloc(sizeof *star * NO_STAR); + + if (!star) + { + Fatal("Memory allocation failed"); + } + + for(f = 0; f < NO_STAR; f++) + { + star[f].x = rand() % COLS; + star[f].y = rand() % LINES; + + do + { + star[f].yi = DRand() * 2; + } while(star[f].yi == 0); + } + + halfdelay(1); + + erase(); + + while(getch() != ' ') + { + for(f = 0; f < NO_STAR; f++) + { + mvaddch(star[f].y, star[f].x, ' '); + + star[f].y -= star[f].yi; + + if (star[f].y < 0) + { + star[f].x = rand() % COLS; + star[f].y = LINES - 1; + + do + { + star[f].yi = DRand() * 2; + } while(star[f].yi == 0); + } + } + + for(f = 0; f < NO_STAR; f++) + { + mvaddch(star[f].y, star[f].x, '.'); + } + + for(f = 0 ; text[f]; f++) + { + int x = COLS / 2 - strlen(text[f]) / 2; + int i; + + for(i = 0; text[f][i]; i++) + { + if (text[f][i] != ' ') + { + mvaddch(f + 4, x++, text[f][i]); + } + else + { + x++; + } + } + } + + Centre(f + 7, "PRESS SPACE"); + + refresh(); + } + + nocbreak(); + cbreak(); + erase(); + + free(star); +} + static int CanCardSitOnTop(Card card, Card on) { int ret = FALSE; @@ -365,6 +469,9 @@ 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.", "", + "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.", + "", "Press 'Q' to quit.", "", "", @@ -491,6 +598,7 @@ static void Klondike(int draw) switch(key) { + case 'w': won = TRUE;break; case ' ': if (pile.no) { @@ -600,6 +708,38 @@ static void Klondike(int draw) } break; + case '1': + if (CanCardSitOnTop(TopOfPile(&hearts), + TopOfPile(&column_up[pos_x]))) + { + MoveTopCard(&hearts, &column_up[pos_x]); + } + break; + + case '2': + if (CanCardSitOnTop(TopOfPile(&diamonds), + TopOfPile(&column_up[pos_x]))) + { + MoveTopCard(&diamonds, &column_up[pos_x]); + } + break; + + case '3': + if (CanCardSitOnTop(TopOfPile(&spades), + TopOfPile(&column_up[pos_x]))) + { + MoveTopCard(&spades, &column_up[pos_x]); + } + break; + + case '4': + if (CanCardSitOnTop(TopOfPile(&clubs), + TopOfPile(&column_up[pos_x]))) + { + MoveTopCard(&clubs, &column_up[pos_x]); + } + break; + case KEY_LEFT: if (pos_x) { @@ -651,10 +791,7 @@ static void Klondike(int draw) if (won) { - Centre(5, "YOU WON!"); - Centre(7, "PRESS SPACE"); - refresh(); - while(getch() != ' '); + WinScreen(); } } @@ -696,6 +833,13 @@ int main(int argc, char *argv[]) case 'Q': quit = TRUE; break; + case '?': + erase(); + Centre(2, "Press the indicated key to select the menu item."); + Centre(4, "Press SPACE to continue."); + refresh(); + while(getch() != ' '); + break; default: break; } -- cgit v1.2.3