about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--freecell.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/freecell.c b/freecell.c
index 233a720..f7a19cb 100644
--- a/freecell.c
+++ b/freecell.c
@@ -183,11 +183,44 @@ static void updateLayout(void) {
 	}
 }
 
+static void revealRank(Card rank) {
+	for (uint i = 0; i < layout.main.len; ++i) {
+		struct Item item = layout.main.items[i];
+		if (cardRank(item.card) != rank) continue;
+		listPush(&reveal, &item.rect, item.card);
+	}
+}
+
 static bool keyDown(SDL_KeyboardEvent key) {
 	switch (key.keysym.sym) {
 		case SDLK_F2: gameDeal(); return true;
-		default: return false;
 	}
+	if (key.repeat) return false;
+	switch (key.keysym.sym) {
+		break; case SDLK_a: revealRank(Cards_A);
+		break; case SDLK_2: revealRank(Cards_2);
+		break; case SDLK_3: revealRank(Cards_3);
+		break; case SDLK_4: revealRank(Cards_4);
+		break; case SDLK_5: revealRank(Cards_5);
+		break; case SDLK_6: revealRank(Cards_6);
+		break; case SDLK_7: revealRank(Cards_7);
+		break; case SDLK_8: revealRank(Cards_8);
+		break; case SDLK_9: revealRank(Cards_9);
+		break; case SDLK_1: revealRank(Cards_10);
+		break; case SDLK_0: revealRank(Cards_10);
+		break; case SDLK_j: revealRank(Cards_J);
+		break; case SDLK_q: revealRank(Cards_Q);
+		break; case SDLK_k: revealRank(Cards_K);
+		break; default: return false;
+	}
+	return true;
+}
+
+static bool keyUp(SDL_KeyboardEvent key) {
+	(void)key;
+	if (!reveal.len) return false;
+	reveal.len = 0;
+	return true;
 }
 
 static bool mouseButtonDown(SDL_MouseButtonEvent button) {
@@ -223,7 +256,6 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) {
 		return true;
 	}
 
-	// TODO: Right click to reveal?
 	if (!item) return false;
 	if (!gameAvail(item->card)) return false;
 	layout.dragItem = *item;
@@ -368,6 +400,8 @@ int main(void) {
 				goto quit;
 			} else if (event.type == SDL_KEYDOWN) {
 				if (keyDown(event.key)) break;
+			} else if (event.type == SDL_KEYUP) {
+				if (keyUp(event.key)) break;
 			} else if (event.type == SDL_MOUSEBUTTONDOWN) {
 				if (mouseButtonDown(event.button)) break;
 			} else if (event.type == SDL_MOUSEBUTTONUP) {