Skip to content

Commit 0c391d9

Browse files
authored
Merge pull request #69 from krayon/auto-move-to-foundation
Auto-move a card to foundation pile when unselected
2 parents 9c7212c + 77d67ed commit 0c391d9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/game.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int maneuvre_begin_x(int x) {
5656
}
5757
}
5858

59-
static bool waste_pile_stack(struct stack *stack) {
59+
bool waste_pile_stack(struct stack *stack) {
6060
return ((stack->card->frame->begin_y == WASTE_PILE_BEGIN_Y) &&
6161
(stack->card->frame->begin_x == WASTE_PILE_BEGIN_X));
6262
}

src/game.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct game {
3838
extern struct deck *deck;
3939
extern struct cursor *cursor;
4040

41+
bool waste_pile_stack(struct stack *);
4142
bool maneuvre_stack(struct stack *);
4243
bool stock_stack(struct stack *);
4344
bool valid_move(struct stack *, struct stack *);

src/keyboard.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ static void handle_card_movement(struct cursor *cursor) {
167167
move_card(origin, destination);
168168
}
169169
}
170+
171+
/* If they only had one card selected... */
172+
if (*origin == *destination && ((maneuvre_stack(*origin) && _marked_cards_count == 1) || waste_pile_stack(*origin))) {
173+
/* see if we can automatically move card to foundation */
174+
for (int i = 0; i <= 3; ++i) {
175+
destination = (&(deck->foundation[i]));
176+
if (valid_move(*origin, *destination)) {
177+
move_card(origin, destination);
178+
break;
179+
}
180+
}
181+
}
182+
170183
draw_stack(*origin);
171184
draw_stack(*destination);
172185
if (maneuvre_stack(*origin) && *origin == *destination) {

0 commit comments

Comments
 (0)