Back to index

gcompris  8.2.2
Classes | Defines | Typedefs | Functions | Variables
algebra_guesscount.c File Reference
#include "gcompris/gcompris.h"

Go to the source code of this file.

Classes

struct  _token

Defines

#define NUMBER_OF_SUBLEVELS   3
#define NUMBER_OF_LEVELS   4
#define MAX_NUMBER   5
#define TEXT_COLOR_FRONT   "yellow"
#define TEXT_COLOR_BACK   "black"
#define TEXT_RESULT_COLOR_FRONT   "red"
#define TEXT_RESULT_COLOR_BACK   "orange"
#define BLANK   "___"
#define NO_RESULT   -1
#define BUTTON_WIDTH   81
#define BUTTON_HEIGHT   64
#define HORIZONTAL_SEPARATION   20
#define VERTICAL_SEPARATION   20
#define NUM_VALUES   13
#define Y_OPE   20
#define Y_NUM   100
#define Y_ANS   200
#define X_NUM1   300
#define X_OPE   400
#define X_NUM2   500
#define X_EQUAL   600
#define X_RESULT   700

Typedefs

typedef struct _token

Functions

static void start_board (GcomprisBoard *agcomprisBoard)
static void pause_board (gboolean pause)
static void end_board (void)
static gboolean is_our_board (GcomprisBoard *gcomprisBoard)
static void set_level (guint level)
static void process_ok (void)
static void process_time (void)
static void game_won (void)
static void destroy_board (void)
static GnomeCanvasItem * algebra_guesscount_create_item (GnomeCanvasGroup *parent)
static void algebra_guesscount_destroy_all_items (void)
static void algebra_guesscount_next_level (void)
static gint item_event_num (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static gint item_event_oper (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static gint item_event_oper_moved (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static int generate_numbers ()
static int token_result ()
static void update_line_calcul ()
static int oper_char_to_pixmap_index (char oper)

Variables

static GcomprisBoard * gcomprisBoard = NULL
static gboolean board_paused = TRUE
static int gamewon
static gint process_time_id = 0
static char * background_images []
static const char oper_values [] = {'+', '-', 'x', ':', '='}
static const char * oper_images [] = {"plus", "minus", "by", "div", "equal"}
static const int num_values [] = {1,2,3,4,5,6,7,8,9,10,25,50,100}
token token_value [MAX_NUMBER *2-1]
token * ptr_token_selected [MAX_NUMBER *2-1]
static const int y_equal_offset []
static const int x_token_offset [] = {X_NUM1,X_OPE,X_NUM2,X_OPE,X_NUM2,X_OPE,X_NUM2,X_OPE,X_NUM2}
static const int y_token_offset []
static char answer_oper [MAX_NUMBER-1]
static int answer_num_index [MAX_NUMBER]
static int token_count
static int result_to_find
static GnomeCanvasGroup * boardRootItem = NULL
static GdkPixbuf * num_pixmap [NUM_VALUES]
static GdkPixbuf * oper_pixmap [5]
static GdkPixbuf * button_pixmap = NULL
static GnomeCanvasItem * oper_item [4]
static GnomeCanvasItem * num_item [MAX_NUMBER]
static GnomeCanvasItem * equal_item [NUMBER_OF_LEVELS]
static GnomeCanvasItem * calcul_line_item [NUMBER_OF_LEVELS *2]
static GnomeCanvasItem * calcul_line_item_back [NUMBER_OF_LEVELS *2]
static GnomeCanvasItem * result_item_front
static GnomeCanvasItem * result_item_back
static BoardPlugin menu_bp

Class Documentation

struct _token

Definition at line 83 of file algebra_guesscount.c.

Class Members
gboolean isMoved
gboolean isNumber
GnomeCanvasItem * item
int num
char oper
int signal_id
int xOffset_original

Define Documentation

#define BLANK   "___"

Definition at line 55 of file algebra_guesscount.c.

#define BUTTON_HEIGHT   64

Definition at line 60 of file algebra_guesscount.c.

#define BUTTON_WIDTH   81

Definition at line 59 of file algebra_guesscount.c.

#define HORIZONTAL_SEPARATION   20

Definition at line 61 of file algebra_guesscount.c.

#define MAX_NUMBER   5

Definition at line 47 of file algebra_guesscount.c.

#define NO_RESULT   -1

Definition at line 57 of file algebra_guesscount.c.

#define NUM_VALUES   13

Definition at line 71 of file algebra_guesscount.c.

#define NUMBER_OF_LEVELS   4

Definition at line 46 of file algebra_guesscount.c.

#define NUMBER_OF_SUBLEVELS   3

Definition at line 45 of file algebra_guesscount.c.

#define TEXT_COLOR_BACK   "black"

Definition at line 50 of file algebra_guesscount.c.

#define TEXT_COLOR_FRONT   "yellow"

Definition at line 49 of file algebra_guesscount.c.

#define TEXT_RESULT_COLOR_BACK   "orange"

Definition at line 53 of file algebra_guesscount.c.

#define TEXT_RESULT_COLOR_FRONT   "red"

Definition at line 52 of file algebra_guesscount.c.

#define VERTICAL_SEPARATION   20

Definition at line 62 of file algebra_guesscount.c.

#define X_EQUAL   600

Definition at line 79 of file algebra_guesscount.c.

#define X_NUM1   300

Definition at line 76 of file algebra_guesscount.c.

#define X_NUM2   500

Definition at line 78 of file algebra_guesscount.c.

#define X_OPE   400

Definition at line 77 of file algebra_guesscount.c.

#define X_RESULT   700

Definition at line 80 of file algebra_guesscount.c.

#define Y_ANS   200

Definition at line 74 of file algebra_guesscount.c.

#define Y_NUM   100

Definition at line 73 of file algebra_guesscount.c.

#define Y_OPE   20

Definition at line 72 of file algebra_guesscount.c.


Typedef Documentation

typedef struct _token

Definition at line 82 of file algebra_guesscount.c.


Function Documentation

static GnomeCanvasItem * algebra_guesscount_create_item ( GnomeCanvasGroup *  parent) [static]

Definition at line 396 of file algebra_guesscount.c.

                                                                                 {
  int i, xOffset, sid;
  char str[10];

  result_to_find = generate_numbers();

  boardRootItem = GNOME_CANVAS_GROUP(
                                 gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                                                     gnome_canvas_group_get_type (),
                                                     "x", (double) 0,
                                                     "y", (double) 0,
                                                     NULL));

  // the intermediate result, line by line, when empty is BLANK
  for (i=0; i<gcomprisBoard->level; i++) {
    calcul_line_item_back[i*2] = gnome_canvas_item_new (boardRootItem,
                                                 gnome_canvas_text_get_type (),
                                                 "text", BLANK,
                                                 "font", gc_skin_font_board_title_bold,
                                                 "x", (double) X_EQUAL+BUTTON_WIDTH*1.5 + 1,
                                                 "y", (double) y_equal_offset[i]+BUTTON_HEIGHT/2 + 1,
                                                 "anchor", GTK_ANCHOR_CENTER,
                                                 "fill_color", TEXT_COLOR_BACK,
                                                 NULL);
    calcul_line_item[i*2] = gnome_canvas_item_new (boardRootItem,
                                             gnome_canvas_text_get_type (),
                                             "text", BLANK,
                                             "font", gc_skin_font_board_title_bold,
                                             "x", (double) X_EQUAL+BUTTON_WIDTH*1.5,
                                             "y", (double) y_equal_offset[i]+BUTTON_HEIGHT/2,
                                             "anchor", GTK_ANCHOR_CENTER,
                                             "fill_color", TEXT_COLOR_FRONT,
                                             NULL);
  }

  for (i=0; i<gcomprisBoard->level-1; i++) {
    calcul_line_item_back[i*2+1] = gnome_canvas_item_new (boardRootItem,
                                                   gnome_canvas_text_get_type (),
                                                   "text", BLANK,
                                                   "font", gc_skin_font_board_title_bold,
                                                   "x", (double) X_NUM1+BUTTON_WIDTH/2 + 1,
                                                   "y", (double) y_equal_offset[i+1]+BUTTON_HEIGHT/2 + 1,
                                                   "anchor", GTK_ANCHOR_CENTER,
                                                   "fill_color", TEXT_COLOR_BACK,
                                                   NULL);
    calcul_line_item[i*2+1] = gnome_canvas_item_new (boardRootItem,
                                               gnome_canvas_text_get_type (),
                                               "text", BLANK,
                                               "font", gc_skin_font_board_title_bold,
                                               "x", (double) X_NUM1+BUTTON_WIDTH/2,
                                               "y", (double) y_equal_offset[i+1]+BUTTON_HEIGHT/2,
                                               "anchor", GTK_ANCHOR_CENTER,
                                               "fill_color", TEXT_COLOR_FRONT,
                                               NULL);
  }

  xOffset = (gcomprisBoard->width - 4 * BUTTON_WIDTH - 3 * HORIZONTAL_SEPARATION)/2;
  for (i=0; i<4; i++) {
    oper_item[i] = gnome_canvas_item_new (boardRootItem,
                                     gnome_canvas_pixbuf_get_type (),
                                     "pixbuf", oper_pixmap[i],
                                     "x", (double) xOffset ,
                                     "y", (double) Y_OPE,
                                     "width", (double) BUTTON_WIDTH,
                                     "height", (double) BUTTON_HEIGHT,
                                     "width_set", TRUE,
                                     "height_set", TRUE,
                                     NULL);
    xOffset += BUTTON_WIDTH+HORIZONTAL_SEPARATION;
    gtk_signal_connect(GTK_OBJECT(oper_item[i]), "event", (GtkSignalFunc) item_event_oper,
                     GINT_TO_POINTER(&(token_value[i*2+1])) );
    token_value[i*2+1].isNumber = FALSE;
    token_value[i*2+1].isMoved = FALSE;
    token_value[i*2+1].oper = oper_values[i];
  }

  // displays the target result
  sprintf(str,"%d",result_to_find);
  result_item_back = gnome_canvas_item_new (boardRootItem,
                                       gnome_canvas_text_get_type (),
                                       "text", str,
                                       "font", gc_skin_font_board_title_bold,
                                       "x", (double) xOffset+BUTTON_WIDTH +1,
                                       "y", (double) Y_OPE+BUTTON_HEIGHT/2 +1,
                                       "anchor", GTK_ANCHOR_CENTER,
                                       "fill_color", TEXT_RESULT_COLOR_BACK,
                                       NULL);
  result_item_front = gnome_canvas_item_new (boardRootItem,
                                        gnome_canvas_text_get_type (),
                                        "text", str,
                                        "font", gc_skin_font_board_title_bold,
                                        "x", (double) xOffset+BUTTON_WIDTH,
                                        "y", (double) Y_OPE+BUTTON_HEIGHT/2,
                                        "anchor", GTK_ANCHOR_CENTER,
                                        "fill_color", TEXT_RESULT_COLOR_FRONT,
                                        NULL);

  xOffset = (gcomprisBoard->width - (gcomprisBoard->level+1) * BUTTON_WIDTH - gcomprisBoard->level * HORIZONTAL_SEPARATION)/2;
  for (i=0; i<gcomprisBoard->level+1; i++) {
    num_item[i] = gnome_canvas_item_new (boardRootItem,
                                    gnome_canvas_pixbuf_get_type (),
                                    "pixbuf", num_pixmap[answer_num_index[i]],
                                    "x", (double) xOffset ,
                                    "y", (double) Y_NUM,
                                    "width", (double) BUTTON_WIDTH,
                                    "height", (double) BUTTON_HEIGHT,
                                    "width_set", TRUE,
                                    "height_set", TRUE,
                                    NULL);
    sid = gtk_signal_connect(GTK_OBJECT(num_item[i]), "event", (GtkSignalFunc) item_event_num,
                          (void *)&(token_value[i*2]));
    token_value[i*2].isNumber = TRUE;
    token_value[i*2].num = answer_num_index[i];
    token_value[i*2].signal_id = sid;
    token_value[i*2].item = num_item[i];
    token_value[i*2].isMoved = FALSE;
    token_value[i*2].xOffset_original = xOffset;
    xOffset += BUTTON_WIDTH+HORIZONTAL_SEPARATION;
  }

  // items "="
  for (i=0; i<gcomprisBoard->level; i++) {
    equal_item[i] = gnome_canvas_item_new (boardRootItem,
                                      gnome_canvas_pixbuf_get_type (),
                                      "pixbuf", oper_pixmap[4],
                                      "x", (double) X_EQUAL ,
                                      "y", (double) y_equal_offset[i],
                                      "width", (double) BUTTON_WIDTH,
                                      "height", (double) BUTTON_HEIGHT,
                                      "width_set", TRUE,
                                      "height_set", TRUE,
                                      NULL);
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void algebra_guesscount_destroy_all_items ( void  ) [static]

Definition at line 272 of file algebra_guesscount.c.

                                                   {
  if(boardRootItem!=NULL)
    gtk_object_destroy (GTK_OBJECT(boardRootItem));

  boardRootItem = NULL;
}

Here is the caller graph for this function:

static void algebra_guesscount_next_level ( void  ) [static]

Definition at line 258 of file algebra_guesscount.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void destroy_board ( void  ) [static]

Definition at line 677 of file algebra_guesscount.c.

                            {
  int i;

  for (i=0; i<NUM_VALUES; i++)
    gdk_pixbuf_unref(num_pixmap[i]);
  for (i=0; i<5; i++)
    gdk_pixbuf_unref(oper_pixmap[i]);
}

Here is the caller graph for this function:

static void end_board ( void  ) [static]

Definition at line 225 of file algebra_guesscount.c.

Here is the call graph for this function:

static void game_won ( void  ) [static]

Definition at line 533 of file algebra_guesscount.c.

                       {
  gcomprisBoard->sublevel++;

  if(gcomprisBoard->sublevel>gcomprisBoard->number_of_sublevel) {
    /* Try the next level */
    gcomprisBoard->sublevel=1;
    gcomprisBoard->level++;

    if(gcomprisBoard->level>gcomprisBoard->maxlevel) {
      gc_bonus_end_display(BOARD_FINISHED_TUXPLANE);
      return;
    }
    gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),background_images[gcomprisBoard->level-1]);
  }
  algebra_guesscount_next_level();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int generate_numbers ( ) [static]

Definition at line 332 of file algebra_guesscount.c.

                              {
  int i, r, j, result;
  gboolean minus, divide;

  for (i=0; i<gcomprisBoard->level+1; i++) {
    j = RAND(0,NUM_VALUES-1);
    answer_num_index[i] = j;
  }

  result = num_values[answer_num_index[0]];
  for (i=0; i<gcomprisBoard->level; i++) {
    // + and x can always be chosen, but we must ensure - and / are valid
    minus = (result - num_values[answer_num_index[i+1]] >= 0);

    if(gcomprisBoard->level > 2 && num_values[answer_num_index[i+1]] <= 5) {       /* Avoid div operator at lower level */
      divide = (result % num_values[answer_num_index[i+1]] == 0);
    } else {
      divide = 0;
    }
    r = 2 + minus + divide;

    switch (RAND(1,r)) {
    case 1 :
      answer_oper[i] = '+';
      result += num_values[answer_num_index[i+1]];
      break;
    case 2 :         // prevent result from getting too big and accept only < 10 bor the by operator
      if ( (result*num_values[answer_num_index[i+1]] < 1000 ) &&
          ( num_values[answer_num_index[i+1]] < 10) ) {
       answer_oper[i] = 'x';
       result *= num_values[answer_num_index[i+1]];
      } else {
       answer_oper[i] = '+';
       result += num_values[answer_num_index[i+1]];
      }
      break;
    case 3 :
      if (minus) {
       answer_oper[i] = '-';
       result -= num_values[answer_num_index[i+1]];
       g_assert(result >= 0);
      } else {
       answer_oper[i] = ':';
       g_assert(result%num_values[answer_num_index[i+1]] == 0);
       result /= num_values[answer_num_index[i+1]];
      }
      break;
    case 4 :
      if ( RAND(0,1) == 0) {
       answer_oper[i] = '-';
       result -= num_values[answer_num_index[i+1]];
       g_assert(result >= 0);
      } else {
       answer_oper[i] = ':';
       g_assert(result%num_values[answer_num_index[i+1]] == 0);
       result /= num_values[answer_num_index[i+1]];
      }
      break;
    default : g_warning("Bug in guesscount\n"); break;
    }
  }
  return result;
}

Here is the caller graph for this function:

static gboolean is_our_board ( GcomprisBoard *  gcomprisBoard) [static]

Definition at line 245 of file algebra_guesscount.c.

                                                            {
  if (gcomprisBoard) {
    if(g_strcasecmp(gcomprisBoard->type, "algebra_guesscount")==0) {
      /* Set the plugin entry */
      gcomprisBoard->plugin=&menu_bp;
      return TRUE;
    }
  }
  return FALSE;
}
static gint item_event_num ( GnomeCanvasItem *  item,
GdkEvent *  event,
gpointer  data 
) [static]

Definition at line 627 of file algebra_guesscount.c.

                                                                                 {
  token *t = (token *)data;
  char str[12];

  if(board_paused)
    return FALSE;

  switch (event->type){
  case GDK_BUTTON_PRESS:
    if (t->isMoved) {
      if (item != ptr_token_selected[token_count-1]->item)
       return FALSE;
      // we put back in its original place a number item
      gc_item_absolute_move(item, t->xOffset_original, Y_NUM);
      token_count--;
      update_line_calcul();
      t->isMoved = FALSE;
    } else { // the item is at its original place
      if (token_count % 2 == 1 || token_count > 2*gcomprisBoard->level+1)
       return FALSE;
      token_count++;
      ptr_token_selected[token_count-1] = t;
      // some operations are illegal A - B must be > 0 and A/B an integer
      if (token_result() == NO_RESULT && token_count != 1) {
       token_count--;
       return FALSE;
      }

      gc_item_absolute_move(item, x_token_offset[token_count-1], y_token_offset[token_count-1]);
      t->isMoved = TRUE;

      // update result text items
      if (token_count != 1 && token_count % 2 == 1) {
       sprintf(str,"%d",token_result());

       gnome_canvas_item_set(calcul_line_item[token_count-3], "text", str, NULL);
       gnome_canvas_item_set(calcul_line_item_back[token_count-3], "text", str, NULL);

       if(token_count < 2*gcomprisBoard->level+1) {                   /* No next line to update on last line */
         gnome_canvas_item_set(calcul_line_item[token_count-2], "text", str, NULL);
         gnome_canvas_item_set(calcul_line_item_back[token_count-2], "text", str, NULL);
       }
      }
    }
    break;
  default : break;
  }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gint item_event_oper ( GnomeCanvasItem *  item,
GdkEvent *  event,
gpointer  data 
) [static]

Definition at line 576 of file algebra_guesscount.c.

                                                                                  {
  token *t = (       token *)data;

  GnomeCanvasItem * tmp_item;

  if(board_paused)
    return FALSE;
  // first verify it is oper turn
  if (token_count % 2 == 0 || token_count >= 2*gcomprisBoard->level+1)
    return FALSE;

  switch (event->type) {
  case GDK_BUTTON_PRESS:
    ptr_token_selected[token_count] = t;
    tmp_item = gnome_canvas_item_new (boardRootItem,
                                  gnome_canvas_pixbuf_get_type (),
                                  "pixbuf", oper_pixmap[oper_char_to_pixmap_index(t->oper)],
                                  "x", (double) x_token_offset[token_count],
                                  "y", (double) y_token_offset[token_count],
                                  "width", (double) BUTTON_WIDTH,
                                  "height", (double) BUTTON_HEIGHT,
                                  "width_set", TRUE,
                                  "height_set", TRUE,
                                  NULL);
    token_count++;
    gtk_signal_connect(GTK_OBJECT(tmp_item), "event", (GtkSignalFunc) item_event_oper_moved, GINT_TO_POINTER(token_count));
    break;
  default : break;
  }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gint item_event_oper_moved ( GnomeCanvasItem *  item,
GdkEvent *  event,
gpointer  data 
) [static]

Definition at line 608 of file algebra_guesscount.c.

                                                                                        {
  int count = GPOINTER_TO_INT(data);

  if(board_paused)
    return FALSE;
  // we only allow the undo of an operation if it is the last element displayed
  switch (event->type) {
  case GDK_BUTTON_PRESS:
    if (count == token_count) {
      gtk_object_destroy (GTK_OBJECT(item));
      token_count--;
      update_line_calcul();
    }
    break;
  default : break;
  }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int oper_char_to_pixmap_index ( char  oper) [static]

Definition at line 564 of file algebra_guesscount.c.

                                                {
  int i;

  g_assert(oper == '+' || oper == '-' || oper == 'x' || oper == ':' || oper == '=');

  for (i=0; i<5; i++)
    if (oper_values[i] == oper)
      return i;

  return -1;
}

Here is the caller graph for this function:

static void pause_board ( gboolean  pause) [static]

Definition at line 169 of file algebra_guesscount.c.

                                        {
  if(gcomprisBoard==NULL)
    return;

  if(gamewon == TRUE && pause == FALSE) {
    game_won();
  }

  board_paused = pause;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_ok ( void  ) [static]

Definition at line 551 of file algebra_guesscount.c.

                        {
  gamewon = (result_to_find == token_result());
  process_time_id = gtk_timeout_add (50, (GtkFunction) process_time, NULL);
}

Here is the call graph for this function:

static void process_time ( void  ) [static]

Definition at line 556 of file algebra_guesscount.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_level ( guint  level) [static]

Definition at line 236 of file algebra_guesscount.c.

                                    {
  if(gcomprisBoard!=NULL) {
    gcomprisBoard->level=level;
    gcomprisBoard->sublevel=1;
    algebra_guesscount_next_level();
  }
}

Here is the call graph for this function:

static void start_board ( GcomprisBoard *  agcomprisBoard) [static]

Definition at line 181 of file algebra_guesscount.c.

                                                        {
  int i;
  gchar *str;

  if(agcomprisBoard!=NULL){
    gcomprisBoard=agcomprisBoard;

    // load pixmap files
    g_warning("loading pixmaps in start_board\n");
    for (i=0; i<NUM_VALUES; i++) {
      str = g_strdup_printf("%s/%d.png", gcomprisBoard->boarddir,num_values[i]);
      num_pixmap[i] = gc_pixmap_load(str);
      g_free(str);
    }
    for (i=0; i<5; i++) {
      str = g_strdup_printf("%s/%s.png", gcomprisBoard->boarddir,oper_images[i]);
      oper_pixmap[i] = gc_pixmap_load(str);
      g_free(str);
    }

    str = g_strdup_printf("%s/%s", gcomprisBoard->boarddir,"button.png");
    button_pixmap = gc_pixmap_load(str);
    g_free(str);

    gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),"gcompris/animals/tiger1_by_Ralf_Schmode.jpg");
    gcomprisBoard->level=1;
    gcomprisBoard->maxlevel=NUMBER_OF_LEVELS;
    gcomprisBoard->sublevel=1;
    gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS; /* Go to next level after this number of 'play' */
    gc_score_start(SCORESTYLE_NOTE,
                      50,
                      gcomprisBoard->height - 50,
                      gcomprisBoard->number_of_sublevel);
    gc_bar_set(GC_BAR_LEVEL|GC_BAR_OK);

    algebra_guesscount_next_level();

    gamewon = FALSE;

    pause_board(FALSE);
  }
}

Here is the call graph for this function:

static int token_result ( ) [static]

Definition at line 279 of file algebra_guesscount.c.

                          {
  int result, i;

  if (token_count < 2)
    return NO_RESULT;

  g_assert(ptr_token_selected[0]->isNumber);
  result = num_values[ptr_token_selected[0]->num];

  for (i=2; i<token_count; i+=2) {
    g_assert(!ptr_token_selected[i-1]->isNumber);
    switch (ptr_token_selected[i-1]->oper) {
    case '+' :       result += num_values[ptr_token_selected[i]->num];
      break;
    case '-' :              if (result - num_values[ptr_token_selected[i]->num] < 0)
      return NO_RESULT;
      result -= num_values[ptr_token_selected[i]->num];
      break;
    case 'x' :       result *= num_values[ptr_token_selected[i]->num];
      break;
    case ':' :              if (result%num_values[ptr_token_selected[i]->num] != 0)
      return NO_RESULT;
      result /= num_values[ptr_token_selected[i]->num];
      break;
    default : g_warning("bug in token_result()\n"); break;
    }
  }
  return result;
}

Here is the caller graph for this function:

static void update_line_calcul ( ) [static]

Definition at line 309 of file algebra_guesscount.c.

                                 {
  int line;
  char str[12];

  // finds which line has to be zeroed.
  if (token_count%2 == 0)
    line = (int)(token_count/2-1);
  else
    line = (int)(token_count/2);

  if(line==-1)
    return;

  sprintf(str, "%d",token_result());
  gnome_canvas_item_set(calcul_line_item[line*2],      "text", BLANK, NULL);
  gnome_canvas_item_set(calcul_line_item_back[line*2], "text", BLANK, NULL);

  if(line < gcomprisBoard->level-1) {                   /* No next line to update on last line */
    gnome_canvas_item_set(calcul_line_item[line*2+1],      "text", BLANK, NULL);
    gnome_canvas_item_set(calcul_line_item_back[line*2+1], "text", BLANK, NULL);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 107 of file algebra_guesscount.c.

char answer_oper[MAX_NUMBER-1] [static]

Definition at line 106 of file algebra_guesscount.c.

char* background_images[] [static]
Initial value:
 {"gcompris/animals/tiger1_by_Ralf_Schmode",
                                "gcompris/animals/tigerdrink001.jpg",
                                "gcompris/animals/tigercub003.jpg",
                                "gcompris/animals/tigerplay001.jpg"}

Definition at line 64 of file algebra_guesscount.c.

gboolean board_paused = TRUE [static]

Definition at line 23 of file algebra_guesscount.c.

GnomeCanvasGroup* boardRootItem = NULL [static]

Definition at line 112 of file algebra_guesscount.c.

GdkPixbuf* button_pixmap = NULL [static]

Definition at line 116 of file algebra_guesscount.c.

GnomeCanvasItem* calcul_line_item[NUMBER_OF_LEVELS *2] [static]

Definition at line 121 of file algebra_guesscount.c.

GnomeCanvasItem* calcul_line_item_back[NUMBER_OF_LEVELS *2] [static]

Definition at line 122 of file algebra_guesscount.c.

GnomeCanvasItem* equal_item[NUMBER_OF_LEVELS] [static]

Definition at line 120 of file algebra_guesscount.c.

int gamewon [static]

Definition at line 31 of file algebra_guesscount.c.

GcomprisBoard* gcomprisBoard = NULL [static]

Definition at line 22 of file algebra_guesscount.c.

BoardPlugin menu_bp [static]
Initial value:
  {
    NULL,
    NULL,
    "Guess operations",
    "Guess operations",
    "Pascal Georges pascal.georges1@free.fr>",
    NULL,
    NULL,
    NULL,
    NULL,
    start_board,
    pause_board,
    end_board,
    is_our_board,
    NULL,
    process_ok,
    set_level,
    NULL,
    NULL,
    NULL,
    NULL
  }

Definition at line 136 of file algebra_guesscount.c.

GnomeCanvasItem* num_item[MAX_NUMBER] [static]

Definition at line 119 of file algebra_guesscount.c.

GdkPixbuf* num_pixmap[NUM_VALUES] [static]

Definition at line 114 of file algebra_guesscount.c.

const int num_values[] = {1,2,3,4,5,6,7,8,9,10,25,50,100} [static]

Definition at line 70 of file algebra_guesscount.c.

const char* oper_images[] = {"plus", "minus", "by", "div", "equal"} [static]

Definition at line 69 of file algebra_guesscount.c.

GnomeCanvasItem* oper_item[4] [static]

Definition at line 118 of file algebra_guesscount.c.

GdkPixbuf* oper_pixmap[5] [static]

Definition at line 115 of file algebra_guesscount.c.

const char oper_values[] = {'+', '-', 'x', ':', '='} [static]

Definition at line 68 of file algebra_guesscount.c.

gint process_time_id = 0 [static]

Definition at line 32 of file algebra_guesscount.c.

Definition at line 95 of file algebra_guesscount.c.

GnomeCanvasItem * result_item_back [static]

Definition at line 123 of file algebra_guesscount.c.

GnomeCanvasItem* result_item_front [static]

Definition at line 123 of file algebra_guesscount.c.

int result_to_find [static]

Definition at line 109 of file algebra_guesscount.c.

int token_count [static]

Definition at line 108 of file algebra_guesscount.c.

token token_value[MAX_NUMBER *2-1]

Definition at line 94 of file algebra_guesscount.c.

Definition at line 100 of file algebra_guesscount.c.

const int y_equal_offset[] [static]
Initial value:

Definition at line 97 of file algebra_guesscount.c.

const int y_token_offset[] [static]