chiark / gitweb /
Keyboard shortcuts for Twiddle: abcdABCD in line with the notation
authorSimon Tatham <anakin@pobox.com>
Tue, 17 May 2005 11:53:42 +0000 (11:53 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 17 May 2005 11:53:42 +0000 (11:53 +0000)
Gareth and I have been using to analyse the game, and also the
number pad. They don't work sensibly for all sizes, but they'll be
handy for the most common ones.

[originally from svn r5793]

twiddle.c

index 07a735ff3b423068b783c50665370d57c786b036..871bd7fe4b8d8c18ab10daa31defbabc03dbd15e 100644 (file)
--- a/twiddle.c
+++ b/twiddle.c
@@ -604,30 +604,66 @@ static game_state *make_move(game_state *from, game_ui *ui, int x, int y,
        y -= (n-1) * TILE_SIZE / 2;
        x = FROMCOORD(x);
        y = FROMCOORD(y);
-       if (x < 0 || x > w-n || y < 0 || y > w-n)
+       dir = (button == LEFT_BUTTON ? 1 : -1);
+       if (x < 0 || x > w-n || y < 0 || y > h-n)
            return NULL;
+    } else if (button == 'a' || button == 'A' || button==MOD_NUM_KEYPAD+'7') {
+        x = y = 0;
+        dir = (button == 'A' ? -1 : +1);
+    } else if (button == 'b' || button == 'B' || button==MOD_NUM_KEYPAD+'9') {
+        x = w-n;
+        y = 0;
+        dir = (button == 'B' ? -1 : +1);
+    } else if (button == 'c' || button == 'C' || button==MOD_NUM_KEYPAD+'1') {
+        x = 0;
+        y = h-n;
+        dir = (button == 'C' ? -1 : +1);
+    } else if (button == 'd' || button == 'D' || button==MOD_NUM_KEYPAD+'3') {
+        x = w-n;
+        y = h-n;
+        dir = (button == 'D' ? -1 : +1);
+    } else if (button==MOD_NUM_KEYPAD+'8' && (w-n) % 2 == 0) {
+        x = (w-n) / 2;
+        y = 0;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'2' && (w-n) % 2 == 0) {
+        x = (w-n) / 2;
+        y = h-n;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'4' && (h-n) % 2 == 0) {
+        x = 0;
+        y = (h-n) / 2;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'6' && (h-n) % 2 == 0) {
+        x = w-n;
+        y = (h-n) / 2;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'5' && (w-n) % 2 == 0 && (h-n) % 2 == 0){
+        x = (w-n) / 2;
+        y = (h-n) / 2;
+        dir = +1;
+    } else {
+        return NULL;                   /* no move to be made */
+    }
 
-       /*
-        * This is a valid move. Make it.
-        */
-       ret = dup_game(from);
-       ret->just_used_solve = FALSE;  /* zero this in a hurry */
-       ret->movecount++;
-       dir = (button == LEFT_BUTTON ? 1 : -1);
-       do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir);
-       ret->lastx = x;
-       ret->lasty = y;
-       ret->lastr = dir;
+    /*
+     * This is a valid move. Make it.
+     */
+    ret = dup_game(from);
+    ret->just_used_solve = FALSE;  /* zero this in a hurry */
+    ret->movecount++;
+    do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir);
+    ret->lastx = x;
+    ret->lasty = y;
+    ret->lastr = dir;
 
-       /*
-        * See if the game has been completed. To do this we simply
-        * test that the grid contents are in increasing order.
-        */
-       if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable))
-           ret->completed = ret->movecount;
-       return ret;
-    }
-    return NULL;
+    /*
+     * See if the game has been completed. To do this we simply
+     * test that the grid contents are in increasing order.
+     */
+    if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable))
+        ret->completed = ret->movecount;
+    return ret;
 }
 
 /* ----------------------------------------------------------------------