about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-03-24 00:08:11 -0400
committerJune McEnroe <june@causal.agency>2019-03-24 00:08:11 -0400
commit248e66cdb112b4881f7a56c6508f3ef61ea7e3cb (patch)
tree8b8e7bf238a5395701c35da2977789c49b646bd4
parentTreat multiple-of-two-clicks as double-clicks (diff)
downloadcards-248e66cdb112b4881f7a56c6508f3ef61ea7e3cb.tar.gz
cards-248e66cdb112b4881f7a56c6508f3ef61ea7e3cb.zip
Factor out suit, color and rank functions
I plan to implement other solitaire games.
Diffstat (limited to '')
-rw-r--r--sol.c27
-rw-r--r--stack.h24
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;