aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-08-09 11:30:24 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-08-09 11:47:41 +0100
commit8c768e7444707b1985788d610e8f14148bc36ab6 (patch)
treefc3d3442c5c909ce30c0bc2a96a553d295bcbdd5
parent5ec86c03a8bc911bb3dbd77fb7c827eeca975594 (diff)
downloadpuzzles-8c768e7444707b1985788d610e8f14148bc36ab6.zip
puzzles-8c768e7444707b1985788d610e8f14148bc36ab6.tar.gz
puzzles-8c768e7444707b1985788d610e8f14148bc36ab6.tar.bz2
puzzles-8c768e7444707b1985788d610e8f14148bc36ab6.tar.xz
Use move_cursor() for cursor movement in Guess
This makes interpret_move() properly return MOVE_NO_EFFECT when the cursor can't move, and simplifies the code as well.
-rw-r--r--guess.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/guess.c b/guess.c
index bddb1e8..2796bca 100644
--- a/guess.c
+++ b/guess.c
@@ -914,25 +914,15 @@ static char *interpret_move(const game_state *from, game_ui *ui,
}
/* keyboard input */
- if (button == CURSOR_UP || button == CURSOR_DOWN) {
- ui->display_cur = true;
- if (button == CURSOR_DOWN && (ui->colour_cur+1) < from->params.ncolours)
- ui->colour_cur++;
- if (button == CURSOR_UP && ui->colour_cur > 0)
- ui->colour_cur--;
- ret = MOVE_UI_UPDATE;
- } else if (button == 'h' || button == 'H' || button == '?') {
- compute_hint(from, ui);
- ret = MOVE_UI_UPDATE;
- } else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) {
+ if (IS_CURSOR_MOVE(button)) {
int maxcur = from->params.npegs;
if (ui->markable) maxcur++;
- ui->display_cur = true;
- if (button == CURSOR_RIGHT && (ui->peg_cur+1) < maxcur)
- ui->peg_cur++;
- if (button == CURSOR_LEFT && ui->peg_cur > 0)
- ui->peg_cur--;
+ ret = move_cursor(button, &ui->peg_cur, &ui->colour_cur,
+ maxcur, from->params.ncolours,
+ false, &ui->display_cur);
+ } else if (button == 'h' || button == 'H' || button == '?') {
+ compute_hint(from, ui);
ret = MOVE_UI_UPDATE;
} else if (button == CURSOR_SELECT) {
ui->display_cur = true;