]> git.cworth.org Git - dvonn/commitdiff
Add visual indication for non-red stacks containing a red piece
authorCarl Worth <cworth@cworth.org>
Thu, 5 Mar 2009 09:46:55 +0000 (01:46 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 5 Mar 2009 09:46:55 +0000 (01:46 -0800)
Also, don't bother displaying the stack-height number until
the stack has at least two pieces in it.

The game is really close to being possible to play manually,
(without the computer enforcing the rules), except that it's
not yet possible to eliminate the disconnected pieces.

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

index f80277531ee7a8ee9bf71ba616a2e8c2ca69ea45..4d09e13be58f0ce25f2ee048bca2ea11391ee2b5 100644 (file)
@@ -63,6 +63,7 @@ dvonn_board_init (dvonn_board_t *board)
        for (y = 0; y < DVONN_BOARD_Y_SIZE; y++) {
            board->cells[x][y].type = DVONN_CELL_EMPTY;
            board->cells[x][y].height = 0;
+           board->cells[x][y].contains_red = FALSE;
        }
     }
 
@@ -140,12 +141,14 @@ dvonn_board_place (dvonn_board_t *board,
        return FALSE;
     }
 
-    if (board->moves < 3)
+    if (board->moves < 3) {
        board->cells[x][y].type = DVONN_CELL_RED;
-    else if (board->moves % 2)
+       board->cells[x][y].contains_red = TRUE;
+    } else if (board->moves % 2) {
        board->cells[x][y].type = DVONN_CELL_BLACK;
-    else
+    } else {
        board->cells[x][y].type = DVONN_CELL_WHITE;
+    }
 
     board->cells[x][y].height = 1;
 
@@ -175,9 +178,11 @@ dvonn_board_move (dvonn_board_t *board,
 
     board->cells[x2][y2].height += board->cells[x1][y1].height;
     board->cells[x2][y2].type = board->cells[x1][y1].type;
+    board->cells[x2][y2].contains_red |= board->cells[x1][y1].contains_red;
 
     board->cells[x1][y1].type = DVONN_CELL_EMPTY;
     board->cells[x1][y1].height = 0;
+    board->cells[x1][y1].contains_red = FALSE;
 
     dvonn_board_next_player (board);
 
index b0ee8cc46a449dfd5d7d4f4201b68140520567fe..2971a2738e31262c5658b8c944a74933c81d7f81 100644 (file)
@@ -45,6 +45,7 @@ typedef enum {
 typedef struct {
     dvonn_cell_type_t type;
     int height;
+    dvonn_bool_t contains_red;
 } dvonn_cell_t;
 
 #define DVONN_BOARD_X_SIZE 11
diff --git a/dvonn.c b/dvonn.c
index 1442923c0acf27243f9ce42fc6de2766abb453bf..806a8e69247c289f3a712d12293b610f54e43384 100644 (file)
--- a/dvonn.c
+++ b/dvonn.c
@@ -72,6 +72,8 @@ on_delete_event_quit (GtkWidget  *widget,
 /* Something like buff */
 #define BACKGROUND_COLOR 0.89, 0.70, 0.40
 
+#define RED_RING_COLOR 0.8, 0.2, 0.2
+
 /* Relative to a unit square. */
 #define RING_OUTER_RADIUS 0.4
 #define RING_INNER_RADIUS 0.2
@@ -350,6 +352,14 @@ on_expose_event_draw (GtkWidget            *widget,
            cairo_translate(cr,
                            x + (y - DVONN_BOARD_Y_SIZE/2) / 2.0,
                            M_SQRT1_2 * y);
+           if (cell.contains_red && cell.type != DVONN_CELL_RED) {
+               cairo_new_sub_path (cr);
+               cairo_arc (cr, 0.5, 0.5,
+                          (RING_INNER_RADIUS + RING_OUTER_RADIUS)/2.0,
+                          0, 2 * M_PI);
+               cairo_set_source_rgb (cr, RED_RING_COLOR);
+               cairo_fill (cr);
+           }
            ring_path (cr);
            switch (cell.type) {
            case DVONN_CELL_WHITE:
@@ -359,7 +369,7 @@ on_expose_event_draw (GtkWidget             *widget,
                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 */
+               cairo_set_source_rgb (cr, RED_RING_COLOR);
                break;
            case DVONN_CELL_EMPTY:
            default:
@@ -375,10 +385,10 @@ on_expose_event_draw (GtkWidget           *widget,
            }
            cairo_fill (cr);
 
-           if (game->board.cells[x][y].height) {
+           if (game->board.cells[x][y].height > 1) {
                PangoLayout *height;
                cairo_move_to (cr,
-                              0.5 - 0.8 * RING_INNER_RADIUS * cos (M_PI_4),
+                              0.5 - 0.7 * RING_INNER_RADIUS * cos (M_PI_4),
                               0.5 - 1.2 * RING_INNER_RADIUS * sin (M_PI_4));
                height = _create_layout_printf (cr, game->font, "%d",
                                                game->board.cells[x][y].height);