]> git.cworth.org Git - kub/commitdiff
Move tile 'out of hand' and onto the board area
authorKevin Worth <kworth@ibuntu.localdomain>
Sat, 17 Apr 2010 12:27:02 +0000 (08:27 -0400)
committerKevin Worth <kworth@ibuntu.localdomain>
Sat, 17 Apr 2010 12:27:02 +0000 (08:27 -0400)
kub.c

diff --git a/kub.c b/kub.c
index d21109bcb80399761bad17ad9c44e3eeb0b166a4..d60accfb675ac7c9c7466e05f2ed36a2e6419e21 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -55,6 +55,7 @@ typedef struct tile {
     int y;
     int selected;
     int owned;
+    int in_hand;//Draw the tile in the hand, or elsewhere on the board?
 } tile_t;
 
 #define DECK_MAX_TILES 104
@@ -71,7 +72,7 @@ typedef struct tile_group {
     int num_tiles;
 } tile_group_t;
 
-#define BOARD_MAX_TILE_GROUPS (DECK_MAX_TILES / 3)
+#define BOARD_MAX_TILE_GROUPS DECK_MAX_TILES
 
 typedef struct board {
     tile_group_t groups[BOARD_MAX_TILE_GROUPS];
@@ -141,6 +142,7 @@ static void tile_init (tile_t *tile, color_t color, int number)
     tile->y = 0;
     tile->selected = 0;
     tile->owned = 0;
+    tile->in_hand = 1;
 }
 
 static void tile_set_x_y (tile_t *tile, int x, int y)
@@ -531,12 +533,14 @@ static void hand_draw(game_t *game, int player, cairo_t *cr, GdkRegion *region,
     int num_tiles = game->players[player].hand.num_tiles;
     for (i = 0; i < num_tiles; i++)
     {
-       tile_set_x_y(&game->players[player].hand.tiles[i],
-                    ((width/num_tiles)) * i, (height - TILE_HEIGHT - 6) );
+       if (game->players[player].hand.tiles[i].in_hand)
+           tile_set_x_y(&game->players[player].hand.tiles[i],
+                        ((width/num_tiles)) * i, (height - TILE_HEIGHT - 6) );
     }
     for (i = 0; i < game->players[player].hand.num_tiles; i++)
     {
-       tile_draw(game, &game->players[player].hand.tiles[i], cr, region);
+//     if (game->players[player].hand.tiles[i].in_hand)
+           tile_draw(game, &game->players[player].hand.tiles[i], cr, region);
     }
 }
 
@@ -544,14 +548,18 @@ static void save_state(game_t *game)
 {
     game->state.board = game->board;
     game->state.deck = game->deck;
-    //game->state.players = game->players;
+    int i;
+    for (i=0; i < game->num_players; i++)
+       game->state.players[i] = game->players[i];
 }
 
 static void restore_state(game_t *game)
 {
     game->board = game->state.board;
     game->deck = game->state.deck;
-    //game->players = game->state.players;
+    int i;
+    for (i=0; i < game->num_players; i++)
+       game->players[i] = game->state.players[i];
 }
 
 static void game_init(game_t *game)
@@ -643,6 +651,8 @@ static gboolean on_key_press_event (GtkWidget *widget, GdkEventKey *event, game_
            gtk_widget_queue_draw(widget);
        }
     }
+    else if (event->keyval == 115)             //HIT "s"
+       save_state(game);
     else if (event->keyval == 65293)           //HIT ENTER
     {
        save_state(game);
@@ -672,7 +682,7 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event,
 {
     int i, tile_x, tile_y;
     tile_t *curr_tile;
-    player_t *curr_player = &game->players[0];
+    player_t *curr_player = &game->players[game->current_player];
 
     /*Handle tiles in player's hand */
     for (i = 0; i < curr_player->hand.num_tiles; i++)
@@ -690,6 +700,7 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event,
         {
            game->select_mode = 0;
            game->current_tile = curr_tile;
+           curr_tile->in_hand = 0;
            if (!curr_tile->selected)
                curr_tile->selected = 1;
            else