diff options
author | June McEnroe <june@causal.agency> | 2019-03-24 00:08:11 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-03-24 00:08:11 -0400 |
commit | 248e66cdb112b4881f7a56c6508f3ef61ea7e3cb (patch) | |
tree | 8b8e7bf238a5395701c35da2977789c49b646bd4 | |
parent | Treat multiple-of-two-clicks as double-clicks (diff) | |
download | cards-248e66cdb112b4881f7a56c6508f3ef61ea7e3cb.tar.gz cards-248e66cdb112b4881f7a56c6508f3ef61ea7e3cb.zip |
Factor out suit, color and rank functions
I plan to implement other solitaire games.
-rw-r--r-- | sol.c | 27 | ||||
-rw-r--r-- | stack.h | 24 |
2 files changed, 27 insertions, 24 deletions
diff --git a/sol.c b/sol.c index 0a0740c..bb73b84 100644 --- a/sol.c +++ b/sol.c @@ -25,27 +25,6 @@ typedef unsigned uint; -static Sint8 cardSuit(Sint8 card) { - card = abs(card); - if (card > Cards_Spade) { - return Cards_Spade; - } else if (card > Cards_Heart) { - return Cards_Heart; - } else if (card > Cards_Diamond) { - return Cards_Diamond; - } else { - return Cards_Club; - } -} - -static Sint8 cardColor(Sint8 card) { - return cardSuit(card) == Cards_Diamond || cardSuit(card) == Cards_Heart; -} - -static Sint8 cardRank(Sint8 card) { - return abs(card) - cardSuit(card); -} - enum { Stock, Waste1, @@ -88,10 +67,10 @@ static void gameDeal(void) { static void gameDraw(void) { stackMoveTo(&stacks[Waste1], &stacks[Waste3], stacks[Waste3].len); if (stacks[Stock].len) { - if (game.draw == 1) { - stackFlipTo(&stacks[Waste1], &stacks[Stock], 1); + if (game.draw > 1) { + stackFlipTo(&stacks[Waste3], &stacks[Stock], game.draw); } else { - stackFlipTo(&stacks[Waste3], &stacks[Stock], 3); + stackFlipTo(&stacks[Waste1], &stacks[Stock], 1); } } else { stackFlipTo(&stacks[Stock], &stacks[Waste1], stacks[Waste1].len); diff --git a/stack.h b/stack.h index e85c43f..a635e8c 100644 --- a/stack.h +++ b/stack.h @@ -19,6 +19,30 @@ #include <SDL_stdinc.h> #include <assert.h> +#include <stdlib.h> + +#include "cards.h" + +static Sint8 cardSuit(Sint8 card) { + card = abs(card); + if (card > Cards_Spade) { + return Cards_Spade; + } else if (card > Cards_Heart) { + return Cards_Heart; + } else if (card > Cards_Diamond) { + return Cards_Diamond; + } else { + return Cards_Club; + } +} + +static Sint8 cardColor(Sint8 card) { + return cardSuit(card) == Cards_Diamond || cardSuit(card) == Cards_Heart; +} + +static Sint8 cardRank(Sint8 card) { + return abs(card) - cardSuit(card); +} struct Stack { Uint8 len; |