guess: Much more efficient keyboard interface

Now rather than mucking around with the cursor keys, you can just type a
four-digit number and press Enter.  Of course, if you still want to muck
around with the cursor keys they work the same as before.

Since Backspace was already assigned to clear the peg under the cursor,
I haven't co-opted it for the obvious action of clearing the peg to the
left of the cursor and moving the cursor left.  The left arrow key is a
reasonable alternative anyway.

For consistency, 'L' now labels the pegs with numbers rather than
letters, and is documented.
This commit is contained in:
Ben Harris
2022-12-07 00:18:56 +00:00
parent 14b434cb88
commit 09f2052fbf
2 changed files with 17 additions and 2 deletions

14
guess.c
View File

@ -414,7 +414,7 @@ struct game_ui {
int drag_col, drag_x, drag_y; /* x and y are *center* of peg! */ int drag_col, drag_x, drag_y; /* x and y are *center* of peg! */
int drag_opeg; /* peg index, if dragged from a peg (from current guess), otherwise -1 */ int drag_opeg; /* peg index, if dragged from a peg (from current guess), otherwise -1 */
bool show_labels; /* label the colours with letters */ bool show_labels; /* label the colours with numbers */
pegrow hint; pegrow hint;
}; };
@ -900,6 +900,16 @@ static char *interpret_move(const game_state *from, game_ui *ui,
set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1); set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1);
ret = UI_UPDATE; ret = UI_UPDATE;
} }
} else if (((button >= '1' && button <= '0' + from->params.ncolours) ||
(button == '0' && from->params.ncolours == 10)) &&
ui->peg_cur < from->params.npegs) {
ui->display_cur = true;
/* Number keys insert a peg and advance the cursor. */
set_peg(&from->params, ui, ui->peg_cur,
button == '0' ? 10 : button - '0');
if (ui->peg_cur + 1 < from->params.npegs + ui->markable)
ui->peg_cur++;
ret = UI_UPDATE;
} else if (button == 'D' || button == 'd' || button == '\b') { } else if (button == 'D' || button == 'd' || button == '\b') {
ui->display_cur = true; ui->display_cur = true;
set_peg(&from->params, ui, ui->peg_cur, 0); set_peg(&from->params, ui, ui->peg_cur, 0);
@ -1196,7 +1206,7 @@ static void draw_peg(drawing *dr, game_drawstate *ds, int cx, int cy,
if (labelled && col) { if (labelled && col) {
char buf[2]; char buf[2];
buf[0] = 'a'-1 + col; buf[0] = '0' + (col % 10);
buf[1] = '\0'; buf[1] = '\0';
draw_text(dr, cx+PEGRAD, cy+PEGRAD, FONT_VARIABLE, PEGRAD, draw_text(dr, cx+PEGRAD, cy+PEGRAD, FONT_VARIABLE, PEGRAD,
ALIGN_HCENTRE|ALIGN_VCENTRE, COL_FRAME, buf); ALIGN_HCENTRE|ALIGN_VCENTRE, COL_FRAME, buf);

View File

@ -1339,6 +1339,11 @@ peg position, and the Enter key to place a peg of the
selected colour in the chosen position. \q{D} or Backspace removes a selected colour in the chosen position. \q{D} or Backspace removes a
peg, and Space adds a hold marker. peg, and Space adds a hold marker.
The number keys can also be used to insert pegs: \q{1} inserts the
top-most colour, \q{2} the second one, and so forth. These also
move the peg cursor to the right. Pressing \q{L} will label the
pegs with their numbers.
Pressing \q{h} or \q{?} will fill the current guess with a suggested Pressing \q{h} or \q{?} will fill the current guess with a suggested
guess. Using this is not recommended for 10 or more pegs as it is guess. Using this is not recommended for 10 or more pegs as it is
slow. slow.