diff options
author | June McEnroe <june@causal.agency> | 2019-08-27 17:01:09 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-08-27 17:01:09 -0400 |
commit | 45576f235e753eba1a361b86092e029dc0d73e26 (patch) | |
tree | 3d069c31b22840972451c442bcc18444b73ed2ee | |
parent | Replicate the FreeCell LCG and deal algorithm (diff) | |
download | wep-45576f235e753eba1a361b86092e029dc0d73e26.tar.gz wep-45576f235e753eba1a361b86092e029dc0d73e26.zip |
Show game number in title
-rw-r--r-- | freecell.c | 21 |
1 files 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) { } // <https://rosettacode.org/wiki/Deal_cards_for_FreeCell> -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 (;;) { |