From 45576f235e753eba1a361b86092e029dc0d73e26 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 27 Aug 2019 17:01:09 -0400 Subject: Show game number in title --- freecell.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/freecell.c b/freecell.c index 0e74793..3f1ec8d 100644 --- a/freecell.c +++ b/freecell.c @@ -96,11 +96,14 @@ static uint lcgRand(void) { } // -static void deal(void) { - kingIndex = Cards_KingRight; +static void deal(uint game) { + lcgState = game; + + queue.r = queue.w = queue.u = 0; for (uint i = 0; i < StacksLen; ++i) { clear(&stacks[i]); } + kingIndex = Cards_KingRight; struct Stack deck = {0}; for (Card i = Cards_A; i <= Cards_K; ++i) { @@ -338,13 +341,21 @@ static enum Choice chooseMove(void) { return choice; } +static void newGame(void) { + uint game = 1 + randUniform(32000); + deal(game); + char buf[sizeof("FreeCell Game #32000")]; + snprintf(buf, sizeof(buf), "FreeCell Game #%u", game); + SDL_SetWindowTitle(window, buf); +} + static Card hiliteRank; static SDL_Point revealPoint; static uint fromStack = StacksLen; static bool keyDown(SDL_KeyboardEvent key) { switch (key.keysym.sym) { - case SDLK_F2: deal(); return true; + case SDLK_F2: newGame(); return true; case SDLK_BACKSPACE: return undo(); } if (key.repeat) return false; @@ -388,7 +399,7 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) { static bool mouseButtonUp(SDL_MouseButtonEvent button) { if (win() && playAgain()) { - deal(); + newGame(); return true; } @@ -581,7 +592,7 @@ int main(void) { } srand(time(NULL)); - deal(); + newGame(); initRects(); for (;;) { -- cgit 1.4.1