summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-12-20 08:49:56 +0000
committerIan C <ianc@noddybox.co.uk>2018-12-20 08:49:56 +0000
commit3671091be220ebed449be036f0b94041155ef476 (patch)
tree51098b7af4e0703d1506e19c0ec80f9a52fe1756
parent6e1cf47ab6384717e77f79017a584437957be75c (diff)
Added win screen and allowed cars to be moved from suit piles back onto the
board.
-rw-r--r--csol.c154
1 files changed, 149 insertions, 5 deletions
diff --git a/csol.c b/csol.c
index 5d9524d..ea3d2ff 100644
--- a/csol.c
+++ b/csol.c
@@ -29,7 +29,6 @@
#include <stdarg.h>
#include <time.h>
-#include <unistd.h>
#include <curses.h>
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;
}