aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-06-23 16:14:38 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-06-23 16:15:02 +0100
commit1d565270144003e6f5406b208d4ab35a1ac14fcb (patch)
tree056d47f366f151f271adf32e026244b1cbcc0e4c
parent6db5cdadd09fad0c8373e32dcfc7ab5b8bcb74e6 (diff)
downloadpuzzles-1d565270144003e6f5406b208d4ab35a1ac14fcb.zip
puzzles-1d565270144003e6f5406b208d4ab35a1ac14fcb.tar.gz
puzzles-1d565270144003e6f5406b208d4ab35a1ac14fcb.tar.bz2
puzzles-1d565270144003e6f5406b208d4ab35a1ac14fcb.tar.xz
Distinguish MOVE_UNUSED from MOVE_NO_EFFECT in Pegs
Slightly more complicated than usual, because Pegs has irregularly shaped grids so detecting whether a click is inside requires more than just a range check. Also fixed a typo in a nearby comment.
-rw-r--r--pegs.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/pegs.c b/pegs.c
index badfbdd..1a2b9cd 100644
--- a/pegs.c
+++ b/pegs.c
@@ -887,16 +887,23 @@ static char *interpret_move(const game_state *state, game_ui *ui,
tx = FROMCOORD(x);
ty = FROMCOORD(y);
- if (tx >= 0 && tx < w && ty >= 0 && ty < h &&
- state->grid[ty*w+tx] == GRID_PEG) {
- ui->dragging = true;
- ui->sx = tx;
- ui->sy = ty;
- ui->dx = x;
- ui->dy = y;
- ui->cur_visible = false;
- ui->cur_jumping = false;
- return MOVE_UI_UPDATE;
+ if (tx >= 0 && tx < w && ty >= 0 && ty < h) {
+ switch (state->grid[ty*w+tx]) {
+ case GRID_PEG:
+ ui->dragging = true;
+ ui->sx = tx;
+ ui->sy = ty;
+ ui->dx = x;
+ ui->dy = y;
+ ui->cur_visible = false;
+ ui->cur_jumping = false;
+ return MOVE_UI_UPDATE;
+ case GRID_HOLE:
+ return MOVE_NO_EFFECT;
+ case GRID_OBST:
+ default:
+ return MOVE_UNUSED;
+ }
}
} else if (button == LEFT_DRAG && ui->dragging) {
/*
@@ -982,14 +989,14 @@ static char *interpret_move(const game_state *state, game_ui *ui,
return MOVE_UI_UPDATE;
}
if (state->grid[ui->cur_y*w+ui->cur_x] == GRID_PEG) {
- /* cursor is on peg: next arrow-move wil jump. */
+ /* cursor is on peg: next arrow-move will jump. */
ui->cur_jumping = true;
return MOVE_UI_UPDATE;
}
- return NULL;
+ return MOVE_NO_EFFECT;
}
- return NULL;
+ return MOVE_UNUSED;
}
static game_state *execute_move(const game_state *state, const char *move)