Back to index

gcompris  8.2.2
awele.c
Go to the documentation of this file.
00001 /*
00002  * gcompris - awele.c Copyright (C) 2005 Frederic Mazzarol This program is
00003  * free software; you can redistribute it and/or modify it under the terms
00004  * of the GNU General Public License as published by the Free Software
00005  * Foundation; either version 2 of the License, or (at your option) any
00006  * later version.  This program is distributed in the hope that it will
00007  * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00008  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00009  * General Public License for more details.  You should have received a
00010  * copy of the GNU General Public License along with this program; if not,
00011  * write to the Free Software Foundation, Inc., 59 Temple Place, Suite
00012  * 330, Boston, MA 02111-1307 USA
00013  */
00014 
00015 #include "gcompris/gcompris.h"
00016 #include <awele_utils.h>
00017 #include <awele.h>
00018 #include <string.h>
00019 #include <unistd.h>
00020 
00021 
00022 static GcomprisBoard *gcomprisBoard = NULL;
00023 static gboolean board_paused = TRUE;
00024 
00025 char errorMsg[30];
00026 AWALE *staticAwale;
00027 int caseCoord[12] =
00028        { 102, 206, 309, 413, 522, 628, 626, 520, 411, 307, 201, 100 };
00029 static GRAPHICS_ELT *graphsElt = NULL;
00030 
00031 static void start_board (GcomprisBoard * agcomprisBoard);
00032 static void pause_board (gboolean pause);
00033 static void end_board (void);
00034 static void set_level (guint level);
00035 static int gamewon;
00036 static void game_won (void);
00037 static void repeat(void);
00038 
00039 static GnomeCanvasGroup *boardRootItem = NULL;
00040 
00041 static gboolean is_our_board (GcomprisBoard * gcomprisBoard);
00042 static GnomeCanvasItem *awele_create_item (GnomeCanvasGroup * parent);
00043 static void awele_destroy_all_items (void);
00044 static void awele_next_level (void);
00045 static gboolean  to_computer(gpointer data);
00046 static gint timeout = 0;
00047 static gboolean computer_turn = FALSE;
00048 static gboolean sublevel_finished = FALSE;
00049 
00050 /*=============================================*/
00051 static GcomprisAnimation *animation;
00052 static GcomprisAnimCanvasItem *anim_item;
00053 
00054 /*
00055  * Description of this plugin
00056  */
00057 static BoardPlugin menu_bp = {
00058        NULL,
00059        NULL,
00060        "The awele game",    /* The name that describe this board */
00061        "African strategy board game",     /* The description that describes
00062                                     * this board */
00063        "Frederic Mazzarol <fmazzarol@gmail.com>",       /* The author of this
00064                                                   * board */
00065        NULL,                /* Called when the plugin is loaded */
00066        NULL,                /* Called when gcompris exit */
00067        NULL,                /* Show the about box */
00068        NULL,                /* Show the configuration dialog */
00069        start_board,         /* Callback to start_board implementation */
00070        pause_board,
00071        end_board,
00072        is_our_board,        /* Return 1 if the plugin can handle the board file */
00073        NULL,
00074        NULL,
00075        set_level,
00076        NULL,
00077        repeat,
00078        NULL,
00079        NULL
00080 };
00081 
00082 /*
00083  * Main entry point mandatory for each Gcompris's game
00084  * ---------------------------------------------------
00085  *
00086  */
00087 
00088 GET_BPLUGIN_INFO (awele)
00089 /*
00090  * in : boolean TRUE = PAUSE : FALSE = CONTINUE
00091  *
00092  */
00093 static void pause_board (gboolean pause)
00094 {
00095        if (gcomprisBoard == NULL)
00096          return;
00097 
00098        board_paused = pause;
00099 
00100        if (pause == FALSE) {
00101          if (gamewon == TRUE)
00102            game_won ();
00103          else
00104            if (computer_turn){
00105              timeout = g_timeout_add (2000,
00106                                    (GSourceFunc) to_computer,
00107                                    NULL);
00108              anim_item = gc_anim_activate( boardRootItem,
00109                                                  animation );
00110              gnome_canvas_item_show(GNOME_CANVAS_ITEM(anim_item->canvas));
00111            }
00112        }
00113        else{
00114          if (computer_turn){
00115            gc_anim_deactivate(anim_item);
00116            if (timeout){
00117              g_source_remove(timeout);
00118              timeout = 0;
00119            }
00120          }
00121        }
00122 }
00123 
00124 /*
00125  */
00126 static void
00127 start_board (GcomprisBoard * agcomprisBoard)
00128 {
00129 
00130        if (agcomprisBoard != NULL)
00131        {
00132               gchar *str;
00133               GdkPixbuf *pixmap = NULL;
00134 
00135               gcomprisBoard = agcomprisBoard;
00136               gcomprisBoard->level = 1;
00137               gcomprisBoard->maxlevel = 9;
00138               gcomprisBoard->sublevel = 1;
00139               gcomprisBoard->number_of_sublevel = 1;    /* Go to next level after
00140                                                   * this number of 'play' */
00141 
00142               str = gc_skin_image_get("button_reload.png");
00143               pixmap = gc_pixmap_load(str);
00144               g_free(str);
00145               if(pixmap) {
00146                 gc_bar_set_repeat_icon(pixmap);
00147                 gdk_pixbuf_unref(pixmap);
00148                 gc_bar_set(GC_BAR_LEVEL|GC_BAR_REPEAT_ICON);
00149               } else {
00150                 gc_bar_set(GC_BAR_LEVEL|GC_BAR_REPEAT);
00151               }
00152 
00153               animation = gc_anim_load( "connect4/sablier.txt" );
00154 
00155               awele_next_level ();
00156 
00157               gamewon = FALSE;
00158               pause_board (FALSE);
00159        }
00160 }
00161 
00162 /*
00163  * =======================================
00164  */
00165 static void
00166 end_board ()
00167 {
00168        if (gcomprisBoard != NULL)
00169        {
00170               pause_board (TRUE);
00171               gc_anim_free(animation);
00172               awele_destroy_all_items ();
00173        }
00174        gcomprisBoard = NULL;
00175 }
00176 
00177 static gboolean
00178 is_our_board (GcomprisBoard * gcomprisBoard)
00179 {
00180        if (gcomprisBoard)
00181        {
00182               if (g_strcasecmp (gcomprisBoard->type, "awele") == 0)
00183               {
00184                      /*
00185                       * Set the plugin entry
00186                       */
00187                      gcomprisBoard->plugin = &menu_bp;
00188 
00189                      return TRUE;
00190               }
00191        }
00192        return FALSE;
00193 }
00194 
00195 /*
00196  * Repeat let the user restart the current level
00197  *
00198  */
00199 static void repeat (){
00200   if (computer_turn){
00201     gc_anim_deactivate(anim_item);
00202     if (timeout){
00203       g_source_remove(timeout);
00204       timeout = 0;
00205     }
00206   }
00207   awele_next_level();
00208 }
00209 
00210 
00211 static void
00212 set_level (guint level)
00213 {
00214 
00215   if(gcomprisBoard!=NULL)
00216     {
00217       gcomprisBoard->level=level;
00218       gcomprisBoard->sublevel = 1;
00219 
00220       if (computer_turn){
00221        gc_anim_deactivate(anim_item);
00222        if (timeout){
00223          g_source_remove(timeout);
00224          timeout = 0;
00225        }
00226       }
00227       awele_next_level();
00228 
00229     }
00230 }
00231 
00232 
00233 /*-------------------------------------------------------------------------------*/
00234 /*-------------------------------------------------------------------------------*/
00235 /*
00236  * set initial values for the next level
00237  */
00238 static void
00239 awele_next_level ()
00240 {
00241         gchar *img;
00242 
00243        img = gc_skin_image_get ("gcompris-bg.jpg");
00244        gc_set_background (gnome_canvas_root (gcomprisBoard->canvas),
00245                              img);
00246        g_free(img);
00247 
00248        gc_bar_set_level (gcomprisBoard);
00249 
00250        awele_destroy_all_items ();
00251        gamewon = FALSE;
00252        computer_turn = FALSE;
00253 
00254        /*
00255         * Create the level
00256         */
00257        awele_create_item (gnome_canvas_root (gcomprisBoard->canvas));
00258 
00259        if ((gcomprisBoard->level % 2) ==0){
00260          computer_turn = TRUE;
00261          staticAwale->player = HUMAN;
00262          timeout = g_timeout_add (2000,
00263                                (GSourceFunc) to_computer,
00264                                NULL);
00265          anim_item = gc_anim_activate( boardRootItem,
00266                                              animation );
00267          gnome_canvas_item_show(GNOME_CANVAS_ITEM(anim_item->canvas));
00268 
00269        } else {
00270          computer_turn = FALSE;
00271        }
00272 }
00273 
00274 /*
00275  * ====================================
00276  */
00277 /*
00278  * Destroy all the items
00279  */
00280 static void
00281 awele_destroy_all_items ()
00282 {
00283         int i;
00284 
00285        if (boardRootItem != NULL)
00286               gtk_object_destroy (GTK_OBJECT (boardRootItem));
00287 
00288        boardRootItem = NULL;
00289 
00290        if(graphsElt)
00291          {
00292            for (i = 0; i < NBHOLE / 2; i++)
00293              {
00294               gdk_pixbuf_unref(graphsElt->pixbufButton[i]);
00295               gdk_pixbuf_unref(graphsElt->pixbufButtonNotify[i]);
00296               gdk_pixbuf_unref(graphsElt->pixbufButtonClicked[i]);
00297              }
00298            g_free(graphsElt);
00299            graphsElt = NULL;
00300          }
00301 
00302 }
00303 
00304 /*
00305  * ====================================
00306  */
00307 static GnomeCanvasItem *
00308 awele_create_item (GnomeCanvasGroup * parent)
00309 {
00310 
00311        GdkPixbuf *pixmap = NULL;
00312        gint i = 0, x1 = 0;
00313        gchar buffer[2];
00314        gchar xpmFile[35] = BOUTON;
00315        gchar xpmFileNotify[35] = BOUTON_NOTIFY;
00316        gchar xpmFileClic[35] = BOUTON_CLIC;
00317 
00318        boardRootItem =
00319               GNOME_CANVAS_GROUP (gnome_canvas_item_new
00320                                 (gnome_canvas_root
00321                                  (gcomprisBoard->canvas),
00322                                  gnome_canvas_group_get_type (), "x",
00323                                  (double) 0, "y", (double) 0, NULL));
00324 
00325        /*
00326         * Load the cute frame
00327         */
00328        pixmap = gc_pixmap_load ("awele/awele_frame.png");
00329 
00330        gnome_canvas_item_new (boardRootItem,
00331                             gnome_canvas_pixbuf_get_type (),
00332                             "pixbuf", pixmap,
00333                             "x", (double) 0,
00334                             "y", (double) 0,
00335                             "width",
00336                             (double) gdk_pixbuf_get_width (pixmap),
00337                             "height",
00338                             (double) gdk_pixbuf_get_height (pixmap),
00339                             "width_set", TRUE, "height_set", TRUE, NULL);
00340        gdk_pixbuf_unref(pixmap);
00341 
00342        /*
00343         * Display text
00344         */
00345        {
00346          int x, y;
00347 
00348          x = 35;
00349          y = 190;
00350          gnome_canvas_item_new (boardRootItem,
00351                              gnome_canvas_text_get_type (),
00352                              "text", _("NORTH"),
00353                              "font", gc_skin_font_board_medium,
00354                              "x", (double) x + 1,
00355                              "y", (double) y + 1,
00356                              "anchor", GTK_ANCHOR_CENTER,
00357                              "fill_color_rgba", gc_skin_color_shadow,
00358                              NULL);
00359 
00360          gnome_canvas_item_new (boardRootItem,
00361                              gnome_canvas_text_get_type (),
00362                              "text", _("NORTH"),
00363                              "font", gc_skin_font_board_medium,
00364                              "x", (double) x,
00365                              "y", (double) y,
00366                              "anchor", GTK_ANCHOR_CENTER,
00367                              "fill_color_rgba", gc_skin_color_text_button,
00368                              NULL);
00369 
00370          x = 765;
00371          y = 295;
00372          gnome_canvas_item_new (boardRootItem,
00373                              gnome_canvas_text_get_type (),
00374                              "text", _("SOUTH"),
00375                              "font", gc_skin_font_board_medium,
00376                              "x", (double) x + 1,
00377                              "y", (double) y + 1,
00378                              "anchor", GTK_ANCHOR_CENTER,
00379                              "fill_color_rgba", gc_skin_color_shadow,
00380                              NULL);
00381 
00382          gnome_canvas_item_new (boardRootItem,
00383                              gnome_canvas_text_get_type (),
00384                              "text", _("SOUTH"),
00385                              "font", gc_skin_font_board_medium,
00386                              "x", (double) x,
00387                              "y", (double) y,
00388                              "anchor", GTK_ANCHOR_CENTER,
00389                              "fill_color_rgba", gc_skin_color_text_button,
00390                              NULL);
00391 
00392        }
00393 
00394        staticAwale = (AWALE *) g_malloc (sizeof (AWALE));
00395 
00396        if (!staticAwale)
00397               exit (1);
00398 
00399        for (i = 0; i < NBHOLE; i++)
00400        {
00401               staticAwale->board[i] = NBBEANSPERHOLE;
00402        }
00403 
00404        /* ->player is last player */
00405        /* next is human */
00406        staticAwale->player = COMPUTER;
00407 
00408        for (i = 0; i < NBPLAYER; i++)
00409        {
00410               staticAwale->CapturedBeans[i] = 0;
00411        }
00412 
00413        graphsElt = (GRAPHICS_ELT *) g_malloc (sizeof (GRAPHICS_ELT));
00414 
00415        /*
00416         * Boucle pour creer et positionner les boutons qui serviront
00417         * a selectionner la case a jouer
00418         */
00419        for (i = 0; i < NBHOLE / 2; i++)
00420        {
00421               sprintf (buffer, "%d", i + 1);
00422               xpmFile[12] = buffer[0];
00423               graphsElt->pixbufButton[i] = gc_pixmap_load (xpmFile);
00424               xpmFileNotify[12] = buffer[0];
00425               graphsElt->pixbufButtonNotify[i] =
00426                      gc_pixmap_load (xpmFileNotify);
00427               xpmFileClic[12] = buffer[0];
00428               graphsElt->pixbufButtonClicked[i] =
00429                      gc_pixmap_load (xpmFileClic);
00430 
00431               /*
00432                * Ajustement de l'ordonnee x, pour positionner le bouton sur la barre de boutons.
00433                */
00434               switch (i)
00435               {
00436               case 0:
00437                      x1 = 120;
00438                      break;
00439               case 1:
00440                      x1 = 220;
00441                      break;
00442               case 2:
00443                      x1 = 325;
00444                      break;
00445               case 3:
00446                      x1 = 432;
00447                      break;
00448               case 4:
00449                      x1 = 539;
00450                      break;
00451               case 5:
00452                      x1 = 643;
00453                      break;
00454               }
00455 
00456               /*
00457                * Ajout des boutons comme items sur le rootGroup du canevas.
00458                * et sauvegarde dans tableau button de type Gnome Canvas Item
00459                * pour attacher les pointeurs de la fonction de rappel buttonClick
00460                * qui servira a detecter quel est l'evenement souris, et en fonction
00461                * declencher la procedure associee. Passage en argument a cette fonction
00462                * du numero de case selectionne par tableau chaine
00463                */
00464               graphsElt->button[i] = gnome_canvas_item_new (boardRootItem,
00465                                                        gnome_canvas_pixbuf_get_type
00466                                                        (), "x",
00467                                                        (double) x1,
00468                                                        "y",
00469                                                        (double)
00470                                                        Y_BOUTONS,
00471                                                        "pixbuf",
00472                                                        graphsElt->
00473                                                        pixbufButton[i],
00474                                                        NULL);
00475 
00476               gtk_signal_connect (GTK_OBJECT (graphsElt->button[i]),
00477                                 "event", GTK_SIGNAL_FUNC (buttonClick),
00478                                 GINT_TO_POINTER(i));
00479 
00480 
00481        }
00482 
00488        for (i = 11; i >= 0; i--)
00489        {
00490 
00491               sprintf (buffer, "%d", staticAwale->board[i]);
00492 
00493               graphsElt->nbBeansHole[i] =
00494                      gnome_canvas_item_new (boardRootItem,
00495                                           gnome_canvas_text_get_type (),
00496                                           "text", buffer,
00497                                           "font", "sans 12",
00498                                           "size", 14000,
00499                                           "x", (double) (caseCoord[i] + 45),
00500                                           "y", (double) ((i < 6) ? 378 : 94),
00501                                           "fill_color", "black", NULL);
00502        }
00503 
00509        for (i = 0; i < 2; i++)
00510        {
00511 
00512               x1 = (i == 1) ? 32 : 762;
00513 
00514               sprintf (buffer, "%d", staticAwale->CapturedBeans[i]);
00515 
00516               graphsElt->Captures[i] = gnome_canvas_item_new (boardRootItem,
00517                                                         gnome_canvas_text_get_type
00518                                                         (), "text",
00519                                                         buffer,
00520                                                         "font",
00521                                                         "sans 12",
00522                                                         "size", 20000,
00523                                                         "x",
00524                                                         (double) x1,
00525                                                         "y",
00526                                                         (double) 246,
00527                                                         "fill_color",
00528                                                         "black",
00529                                                         NULL);
00530        }
00531 
00536        strcpy (xpmFile, BEAN);
00537        for (i = 0; i < 4; i++)
00538        {
00539               sprintf (buffer, "%d", i + 1);
00540               xpmFile[12] = buffer[0];
00541               graphsElt->pixbufBeans[i] = gc_pixmap_load (xpmFile);
00542        }
00543 
00549        initBoardGraphics (graphsElt);
00550 
00551        graphsElt->msg = gnome_canvas_item_new (boardRootItem,
00552                                           gnome_canvas_text_get_type (),
00553                                           "text", _("Choose a house"),
00554                                           "font", "sans 12",
00555                                           "size", 20000,
00556                                           "x", (double) 400,
00557                                           "y", (double) 500,
00558                                           "fill_color", "red",
00559                                           "anchor", GTK_ANCHOR_CENTER,
00560                                           NULL);
00561 
00562        return NULL;
00563 }
00564 
00565 
00566 /*
00567  * ====================================
00568  */
00569 static void
00570 game_won ()
00571 {
00572   if (sublevel_finished){
00573     gcomprisBoard->sublevel++;
00574 
00575     if (gcomprisBoard->sublevel > gcomprisBoard->number_of_sublevel)
00576       {
00577        /*
00578         * Try the next level
00579         */
00580        gcomprisBoard->sublevel = 1;
00581        gcomprisBoard->level++;
00582        if (gcomprisBoard->level > gcomprisBoard->maxlevel)
00583          {           // the
00584                      // current
00585                      // board
00586                      // is
00587                      // finished
00588                      // : bail
00589                      // out
00590            gc_bonus_end_display (BOARD_FINISHED_RANDOM);
00591            return;
00592          }
00593 
00594       }
00595   }
00596   sublevel_finished = FALSE;
00597   awele_next_level ();
00598 }
00599 
00607 static void
00608 initBoardGraphics (GRAPHICS_ELT * graphsElt)
00609 {
00610 
00611        int i, j, k, idxTabBeans = 0;
00612 
00613 
00614        //if (graphsElt->ptBeansHoleLink != NULL)
00615        //      free(graphsElt->ptBeansHoleLink);
00616 
00617        graphsElt->ptBeansHoleLink =
00618               (BEANHOLE_LINK *) malloc (NBTOTALBEAN *
00619                                      sizeof (BEANHOLE_LINK));
00620 
00621        for (i = NBHOLE - 1; i >= 0; i--)
00622        {
00623               for (j = 0;
00624                    j < staticAwale->board[i] && idxTabBeans < NBTOTALBEAN;
00625                    j++, idxTabBeans++)
00626               {
00627                      k = 0 + rand () % 4;
00628                      graphsElt->ptBeansHoleLink[idxTabBeans].beanPixbuf =
00629                             gnome_canvas_item_new (boardRootItem,
00630                                                  gnome_canvas_pixbuf_get_type
00631                                                  (), "x",
00632                                                  (double) caseCoord[i] +
00633                                                  rand () % 50, "y",
00634                                                  (double) (((i <
00635                                                            6) ? 260 :
00636                                                           130) +
00637                                                          rand () %
00638                                                          60),
00639                                                  "pixbuf",
00640                                                  graphsElt->
00641                                                  pixbufBeans[k], NULL);
00642 
00643                      graphsElt->ptBeansHoleLink[idxTabBeans].hole = i;
00644               }
00645        }
00646 }
00647 
00648 
00649 static gboolean  to_computer(gpointer data)
00650 {
00651   short int coup;
00652 
00653   if (!computer_turn){
00654     g_warning ("to_computer called but not compter_turn");
00655     return FALSE;
00656   }
00657 
00658   if (board_paused){
00659     g_warning ("to_computer called but board paused");
00660     timeout = 0;
00661     return TRUE;
00662   }
00663 
00664   coup = think (staticAwale, gcomprisBoard->level);
00665 
00666   gc_anim_deactivate(anim_item);
00667   computer_turn = FALSE;
00668 
00669   if (coup >= 0){
00670     AWALE *tmpAw = staticAwale;
00671     staticAwale = moveAwale (coup, tmpAw);
00672     if (!staticAwale){
00673       g_error("le coup devrait ĂȘtre bon !");
00674     }
00675     gboolean IAmHungry = diedOfHunger(staticAwale);
00676     if (!IAmHungry){
00677       g_free(tmpAw);
00678       updateNbBeans (0);
00679       updateCapturedBeans ();
00680       g_object_set (graphsElt->msg, "text",
00681                   _("Your turn to play ..."), NULL);
00682     } else {
00683       /* computer hungry but human can't give it beans */
00684       /* Human player win by catching all the beans left. */
00685       gamewon = TRUE;
00686       sublevel_finished = TRUE;
00687       gc_bonus_display(TRUE, BONUS_FLOWER);
00688     }
00689   } else {
00690     /* computer can't play. Why? human is hungry and i cannot give it
00691        to eat */
00692     /* if human has 24 beans, it's draw (human win in gcompris) */
00693     /* if not, all staying are captured by computer and computer win */
00694     gamewon = TRUE;
00695     sublevel_finished = (staticAwale->CapturedBeans[HUMAN] ==  24);
00696     gc_bonus_display(sublevel_finished, BONUS_FLOWER);
00697   }
00698 
00699   timeout = 0;
00700   return FALSE;
00701 }
00702 
00714 static gint
00715 buttonClick (GtkWidget * item, GdkEvent * event, gpointer data)
00716 {
00717        gint numeroCase = GPOINTER_TO_INT(data);
00718 
00719        switch (event->type)
00720        {
00721        case GDK_ENTER_NOTIFY:
00722               g_object_set (GTK_OBJECT
00723                            (graphsElt->button[numeroCase]),
00724                            "pixbuf",
00725                            graphsElt->pixbufButtonNotify[numeroCase],
00726                            "y", (double) Y_BOUTONS, NULL);
00727               break;
00728        case GDK_LEAVE_NOTIFY:
00729               g_object_set (GTK_OBJECT
00730                            (graphsElt->button[numeroCase]),
00731                            "pixbuf",
00732                            graphsElt->pixbufButton[numeroCase],
00733                            "y", (double) Y_BOUTONS, NULL);
00734               break;
00735        case GDK_BUTTON_PRESS:
00736          if (computer_turn)
00737            return TRUE;
00738 
00739          g_object_set (GTK_OBJECT
00740                      (graphsElt->button[numeroCase]),
00741                      "pixbuf",
00742                      graphsElt->pixbufButtonClicked[numeroCase],
00743                      "y", (double) Y_BOUTONS + 3, NULL);
00744 
00745          g_object_set (graphsElt->msg, "text", "", NULL);
00746 
00747          AWALE *tmpaw = moveAwale (numeroCase, staticAwale);
00748          if (!tmpaw)
00749            {
00750              g_object_set (graphsElt->msg, "text", _("Not allowed! Try again !"),
00751                          NULL);
00752            }
00753          else
00754            {
00755              g_free(staticAwale);
00756              staticAwale = tmpaw;
00757              updateNbBeans (0);
00758              updateCapturedBeans ();
00759              if (!gamewon){
00760               computer_turn = TRUE;
00761               timeout = g_timeout_add (2000,
00762                                     (GSourceFunc) to_computer,
00763                                     NULL);
00764               anim_item = gc_anim_activate( boardRootItem,
00765                                                   animation );
00766              }
00767            }
00768 
00769          break;
00770        case GDK_BUTTON_RELEASE:
00771          g_object_set (GTK_OBJECT
00772                      (graphsElt->button[numeroCase]),
00773                      "pixbuf",
00774                      graphsElt->pixbufButtonNotify[numeroCase],
00775                      "y", (double) Y_BOUTONS, NULL);
00776          break;
00777        default:
00778               break;
00779        }
00780 
00781        return FALSE;
00782 }
00783 
00796 static BEANHOLE_LINK *
00797 updateNbBeans (int alpha)
00798 {
00799 
00800   char buffer[3];           //Manipulation chaines de caracteres
00801   int i, j, k, idxTabBeans = 0;    //Compteur Boucle Manipulation Elements graphiques
00802   static short int nbActiveBean = NBTOTALBEAN;   //nbre graine restant sur plateau
00803   static short int nbOldActiveBean;       //nbre graine restant sur plateau au tour precedent
00804   BEANHOLE_LINK *ptBeansHoleLink = NULL;  //pointeur sur structures stockant les item graines et la case dans laquelle elles se trouvent.
00805 
00811   if (alpha)
00812     {
00813       nbOldActiveBean = 48;
00814     }
00815   else
00816     {
00817       nbOldActiveBean = nbActiveBean;
00818     }
00819 
00820   nbActiveBean =
00821     NBTOTALBEAN - (staticAwale->CapturedBeans[HUMAN] +
00822                  staticAwale->CapturedBeans[COMPUTER]);
00823 
00828   for (ptBeansHoleLink = &(graphsElt->ptBeansHoleLink)[nbActiveBean], i = 0;
00829        i < nbOldActiveBean - nbActiveBean; i++, ptBeansHoleLink++)
00830     {
00831       gtk_object_destroy (GTK_OBJECT (ptBeansHoleLink->beanPixbuf));
00832     }
00833 
00834 
00841   ptBeansHoleLink =
00842     (BEANHOLE_LINK *) realloc (graphsElt->ptBeansHoleLink,
00843                             nbActiveBean *
00844                             sizeof (BEANHOLE_LINK));
00845 
00851   for (i = NBHOLE - 1; i >= 0; i--)
00852     {
00853       sprintf (buffer, "%d", staticAwale->board[i]);
00854       gnome_canvas_item_set (graphsElt->nbBeansHole[i], "text", buffer, NULL);
00855 
00856       for (j = 0;
00857           j < staticAwale->board[i] && idxTabBeans < nbActiveBean;
00858           j++, idxTabBeans++)
00859        {
00860 
00861          k = 0 + rand () % 4;
00862 
00863          gnome_canvas_item_set (ptBeansHoleLink[idxTabBeans].
00864                              beanPixbuf, "x",
00865                              (double) caseCoord[i] +
00866                              rand () % 50, "y",
00867                              (double) (((i <
00868                                         6) ? 260 : 130) +
00869                                       rand () % 60), NULL);
00870 
00871          ptBeansHoleLink[idxTabBeans].hole = i;
00872        }
00873 
00874     }
00875 
00880   graphsElt->ptBeansHoleLink = ptBeansHoleLink;
00881   return ptBeansHoleLink;
00882 }
00883 
00884 
00891 static void
00892 updateCapturedBeans ()
00893 {
00894 
00895        short int i;
00896        char buffer[3];
00897 
00898        for (i = 0; i < 2; i++)
00899        {
00900               sprintf (buffer, "%d", staticAwale->CapturedBeans[i]);
00901               g_object_set (graphsElt->Captures[i], "text", buffer, NULL);
00902               if (staticAwale->CapturedBeans[i] > 24)
00903                 {
00904                   gamewon = TRUE;
00905                   sublevel_finished = (i==0);
00906                   gc_bonus_display(sublevel_finished, BONUS_FLOWER);
00907                 }
00908        }
00909 }
00910