WIP.
This commit is contained in:
parent
6545b996f2
commit
58fff35a20
@ -7,6 +7,9 @@
|
|||||||
#define CURSOR_STARTING_X 4
|
#define CURSOR_STARTING_X 4
|
||||||
#define CURSOR_STARTING_Y 7
|
#define CURSOR_STARTING_Y 7
|
||||||
|
|
||||||
|
#define CURSOR_INVALID_SPOT_X 20
|
||||||
|
#define CURSOR_INVALID_SPOT_Y 7
|
||||||
|
|
||||||
#define CURSOR_STOCK_X 4
|
#define CURSOR_STOCK_X 4
|
||||||
#define CURSOR_WASTE_PILE_X 12
|
#define CURSOR_WASTE_PILE_X 12
|
||||||
#define CURSOR_FOUNDATION_0_X 28
|
#define CURSOR_FOUNDATION_0_X 28
|
||||||
|
@ -12,22 +12,22 @@ struct stack *cursor_stack(struct cursor *cursor) {
|
|||||||
|
|
||||||
if (cursor->y == CURSOR_STARTING_Y) {
|
if (cursor->y == CURSOR_STARTING_Y) {
|
||||||
switch (cursor->x) {
|
switch (cursor->x) {
|
||||||
case CURSOR_STOCK_X: cursor_stack = deck->stock;
|
case CURSOR_STOCK_X: cursor_stack = deck->stock; break;
|
||||||
case CURSOR_WASTE_PILE_X: cursor_stack = deck->waste_pile;
|
case CURSOR_WASTE_PILE_X: cursor_stack = deck->waste_pile; break;
|
||||||
case CURSOR_FOUNDATION_0_X: cursor_stack = deck->foundation_0;
|
case CURSOR_FOUNDATION_0_X: cursor_stack = deck->foundation_0; break;
|
||||||
case CURSOR_FOUNDATION_1_X: cursor_stack = deck->foundation_1;
|
case CURSOR_FOUNDATION_1_X: cursor_stack = deck->foundation_1; break;
|
||||||
case CURSOR_FOUNDATION_2_X: cursor_stack = deck->foundation_2;
|
case CURSOR_FOUNDATION_2_X: cursor_stack = deck->foundation_2; break;
|
||||||
case CURSOR_FOUNDATION_3_X: cursor_stack = deck->foundation_3;
|
case CURSOR_FOUNDATION_3_X: cursor_stack = deck->foundation_3; break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (cursor->x) {
|
switch (cursor->x) {
|
||||||
case CURSOR_MANEUVRE_0_X: cursor_stack = deck->maneuvre_0;
|
case CURSOR_MANEUVRE_0_X: cursor_stack = deck->maneuvre_0; break;
|
||||||
case CURSOR_MANEUVRE_1_X: cursor_stack = deck->maneuvre_1;
|
case CURSOR_MANEUVRE_1_X: cursor_stack = deck->maneuvre_1; break;
|
||||||
case CURSOR_MANEUVRE_2_X: cursor_stack = deck->maneuvre_2;
|
case CURSOR_MANEUVRE_2_X: cursor_stack = deck->maneuvre_2; break;
|
||||||
case CURSOR_MANEUVRE_3_X: cursor_stack = deck->maneuvre_3;
|
case CURSOR_MANEUVRE_3_X: cursor_stack = deck->maneuvre_3; break;
|
||||||
case CURSOR_MANEUVRE_4_X: cursor_stack = deck->maneuvre_4;
|
case CURSOR_MANEUVRE_4_X: cursor_stack = deck->maneuvre_4; break;
|
||||||
case CURSOR_MANEUVRE_5_X: cursor_stack = deck->maneuvre_5;
|
case CURSOR_MANEUVRE_5_X: cursor_stack = deck->maneuvre_5; break;
|
||||||
case CURSOR_MANEUVRE_6_X: cursor_stack = deck->maneuvre_6;
|
case CURSOR_MANEUVRE_6_X: cursor_stack = deck->maneuvre_6; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +38,10 @@ bool cursor_on_stack(struct cursor *cursor, struct stack *stack) {
|
|||||||
return(cursor_stack(cursor) == stack);
|
return(cursor_stack(cursor) == stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cursor_on_invalid_spot(struct cursor *cursor) {
|
||||||
|
return(cursor->x == CURSOR_INVALID_SPOT_X &&
|
||||||
|
cursor->y == CURSOR_INVALID_SPOT_Y);
|
||||||
|
}
|
||||||
void handle_stock_event() {
|
void handle_stock_event() {
|
||||||
if (!empty(deck->stock)) {
|
if (!empty(deck->stock)) {
|
||||||
/* erase the stack before emptying it */
|
/* erase the stack before emptying it */
|
||||||
@ -61,6 +65,12 @@ void handle_card_movement(struct cursor *cursor) {
|
|||||||
mark_origin(cursor);
|
mark_origin(cursor);
|
||||||
origin = cursor_stack(cursor);
|
origin = cursor_stack(cursor);
|
||||||
|
|
||||||
|
/* trying to move cards from the space between the waste pile and the
|
||||||
|
* foundations */
|
||||||
|
if (cursor_on_invalid_spot(cursor)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (option = getch()) {
|
switch (option = getch()) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -80,7 +90,9 @@ void handle_card_movement(struct cursor *cursor) {
|
|||||||
move_cursor(cursor, RIGHT);
|
move_cursor(cursor, RIGHT);
|
||||||
break;
|
break;
|
||||||
case KEY_SPACEBAR:
|
case KEY_SPACEBAR:
|
||||||
if (!cursor_on_stock(cursor) && !cursor_on_stack(cursor, origin)) {
|
if (!cursor_on_invalid_spot(cursor) &&
|
||||||
|
!cursor_on_stock(cursor) &&
|
||||||
|
!cursor_on_stack(cursor, origin)) {
|
||||||
destination = cursor_stack(cursor);
|
destination = cursor_stack(cursor);
|
||||||
move_card(&origin, &destination);
|
move_card(&origin, &destination);
|
||||||
draw_stack(origin);
|
draw_stack(origin);
|
||||||
|
@ -11,6 +11,7 @@ extern struct deck *deck;
|
|||||||
void mark_origin(struct cursor *);
|
void mark_origin(struct cursor *);
|
||||||
struct stack *cursor_stack(struct cursor *);
|
struct stack *cursor_stack(struct cursor *);
|
||||||
bool cursor_on_stack(struct cursor *, struct stack *);
|
bool cursor_on_stack(struct cursor *, struct stack *);
|
||||||
|
bool cursor_on_invalid_spot(struct cursor *);
|
||||||
void handle_stock_event();
|
void handle_stock_event();
|
||||||
void handle_card_movement(struct cursor *);
|
void handle_card_movement(struct cursor *);
|
||||||
int key_event();
|
int key_event();
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../lib/cursor.h"
|
#include "../lib/cursor.h"
|
||||||
#include "../lib/keyboard.h"
|
#include "../lib/keyboard.h"
|
||||||
|
|
||||||
|
extern struct deck *deck;
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
int option;
|
int option;
|
||||||
struct cursor *cursor;
|
struct cursor *cursor;
|
||||||
@ -56,6 +58,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
case 'q':
|
case 'q':
|
||||||
case 'Q':
|
case 'Q':
|
||||||
end_curses();
|
end_curses();
|
||||||
|
print_deck(deck);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user