]> git.cworth.org Git - dvonn/blobdiff - dvonn.c
Implement placement phase of game
[dvonn] / dvonn.c
diff --git a/dvonn.c b/dvonn.c
index e19ea437e435ee262c3a1407641e095c6888e528..d4099d9984505656984668d3a7d9c72d45c41cce 100644 (file)
--- a/dvonn.c
+++ b/dvonn.c
@@ -163,14 +163,17 @@ on_button_press_event (GtkWidget  *widget,
     if (game->board.cells[x][y].type == DVONN_CELL_INVALID)
        return TRUE;
 
-    if (game->board.cells[x][y].type == DVONN_CELL_EMPTY)
-       game->board.cells[x][y].type = DVONN_CELL_WHITE;
-    else if (game->board.cells[x][y].type == DVONN_CELL_WHITE)
-       game->board.cells[x][y].type = DVONN_CELL_EMPTY;
-
-    dvonn_game_update_windows (game);
+    if (game->board.phase == DVONN_PHASE_PLACEMENT) {
+       if (dvonn_board_place (&game->board, x, y, &error))
+           dvonn_game_update_windows (game);
+       else
+           printf ("Illegal placement %c%d: %s\n",
+                   'a' + x,
+                   y + 1,
+                   error);
 
-    return TRUE;
+       return TRUE;
+    }
 
     if (! game->has_selected) {
        if (game->board.cells[x][y].type == game->board.player) {
@@ -182,8 +185,7 @@ on_button_press_event (GtkWidget    *widget,
        return TRUE;
     }
 
-    if (x == game->selected_x &&
-       y == game->selected_y)
+    if (x == game->selected_x && y == game->selected_y)
     {
        game->has_selected = FALSE;
        dvonn_game_update_windows (game);
@@ -200,9 +202,9 @@ on_button_press_event (GtkWidget    *widget,
     } else {
        printf ("Illegal move %c%d%c%d: %s\n",
                'a' + game->selected_x,
-               DVONN_BOARD_Y_SIZE - game->selected_y,
+               game->selected_y + 1,
                'a' + x,
-               DVONN_BOARD_Y_SIZE - y,
+               y + 1,
                error);
     }
 
@@ -270,10 +272,21 @@ on_expose_event_draw (GtkWidget           *widget,
                            x + (y - DVONN_BOARD_Y_SIZE/2) / 2.0,
                            M_SQRT1_2 * y);
            ring_path (cr);
-           if (cell.type == DVONN_CELL_WHITE)
+           switch (cell.type) {
+           case DVONN_CELL_WHITE:
                cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
-           else
+               break;
+           case DVONN_CELL_BLACK:
+               cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+               break;
+           case DVONN_CELL_RED:
+               cairo_set_source_rgb (cr, 0.8, 0.2, 0.2); /* red */
+               break;
+           case DVONN_CELL_EMPTY:
+           default:
                cairo_set_source_rgba (cr, 0.0, 0.0, 0.2, 0.1);
+               break;
+           }
            cairo_fill (cr);
 
            cairo_restore (cr);