]> git.cworth.org Git - dvonn/commitdiff
Implement right-click for pass
authorCarl Worth <cworth@cworth.org>
Thu, 5 Mar 2009 17:42:08 +0000 (09:42 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 5 Mar 2009 17:42:08 +0000 (09:42 -0800)
An actual button would be better, but I'm being lazy as far
as real UI again.

dvonn-board.c
dvonn-board.h
dvonn.c

index b6b36e5eac7dfefcbf1e6cce6d53901a8fcd7ff8..4aaac54aadc19bcb65f3a5f360c967206e417e51 100644 (file)
@@ -192,6 +192,17 @@ dvonn_board_next_player (dvonn_board_t *board)
        board->player = DVONN_PLAYER_BLACK;
 }
 
+int
+dvonn_board_pass (dvonn_board_t *board)
+{
+    /* XXX: Should check here and only allow a pass if there are
+     * no legal moves. */
+
+    dvonn_board_next_player (board);
+
+    return TRUE;
+}
+
 int
 dvonn_board_place (dvonn_board_t *board,
                   int x, int y,
index 66464d8dee95d9fbd421dfc466cb70e6b3dfada9..7a361c3e6e3f3ebc2bdb415f9bae69352b096414 100644 (file)
@@ -88,6 +88,12 @@ dvonn_board_move (dvonn_board_t *board,
                int x2, int y2,
                char **error);
 
+/* Pass rather than moving, allowing the turn to pass to the
+ * opponent. This should only be allowed if there are no legal moves,
+ * but that is not yet enforced. Returns TRUE if the pass succeeds. */
+int
+dvonn_board_pass (dvonn_board_t *board);
+
 /* Is the cell at (x,y) occupied by a piece. Returns FALSE for all
  * out-of-bounds coordinates. */
 dvonn_bool_t
diff --git a/dvonn.c b/dvonn.c
index 8ac72b1cdd40f4efdd97de2d968a0c40812783bd..94146ce00c19df6418791f4910b14ece75e3512a 100644 (file)
--- a/dvonn.c
+++ b/dvonn.c
@@ -161,6 +161,13 @@ on_button_press_event (GtkWidget   *widget,
     if (event->type >= GDK_2BUTTON_PRESS)
        return TRUE;
 
+    /* Right-click means pass, (yes, it would be better to add some
+     * actual UI elements... */
+    if (event->button == 3) {
+       dvonn_board_pass (&game->board);
+       return TRUE;
+    }
+
     x = event->x;
     y = event->y;
     layout_device_to_board (layout, &x, &y);