[gnome-games] Merged level.c to board.c ...



commit 71067e001aa0083caeb0ac325bcf0815a5962558
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Mon Jul 27 11:32:25 2009 -0400

    Merged level.c to board.c ...
    
    The code in level.c had no real good reason to be seperated from the code in
    board.c, the merge reduce the complexity of the code as well as its use

 gnibbles/Makefile.am    |    2 -
 gnibbles/board.c        |  251 ++++++++++++++++++++++++++++++++++++++++++-
 gnibbles/board.h        |   16 +++-
 gnibbles/boni.c         |   36 +++---
 gnibbles/gnibbles.c     |    4 +-
 gnibbles/level.c        |  274 -----------------------------------------------
 gnibbles/level.h        |   45 --------
 gnibbles/main.c         |   13 +--
 gnibbles/warpmanager.c  |   12 +-
 gnibbles/worm-clutter.c |   92 ++++++++--------
 10 files changed, 335 insertions(+), 410 deletions(-)
---
diff --git a/gnibbles/Makefile.am b/gnibbles/Makefile.am
index c3fa30a..c181451 100644
--- a/gnibbles/Makefile.am
+++ b/gnibbles/Makefile.am
@@ -30,8 +30,6 @@ gnibbles_SOURCES = \
 	main.h \
 	board.c \
 	board.h \
-	level.c \
-	level.h \
 	worm-clutter.c \
 	worm-clutter.h \
 	$(NULL)
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 8d2c7d9..15692b6 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -34,9 +34,17 @@
 #include "gnibbles.h"
 #include "properties.h"
 #include "board.h"
+#include "worm-clutter.h"
+#include "boni.h"
 
-extern GnibblesProperties *properties;
+#ifdef GGZ_CLIENT
+#include "ggz-network.h"
+#endif
 
+extern GnibblesWorm *worms[];
+extern GnibblesProperties *properties;
+extern GnibblesWarpManager *warpmanager;
+extern GnibblesBoni *boni;
 extern GdkPixbuf *wall_pixmaps[];
 
 GnibblesBoard *
@@ -85,8 +93,8 @@ gnibbles_board_new (ClutterActor *stage)
   return board;
 }
 
-void 
-gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level) 
+static void 
+gnibbles_board_load_level (GnibblesBoard *board) 
 {
   gint i,j;
   gint x_pos, y_pos;
@@ -103,7 +111,7 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
     y_pos = i * properties->tilesize;
     for (j = 0; j < BOARDWIDTH; j++) {
       is_wall = TRUE;
-      switch (level->walls[j][i]) {
+      switch (board->walls[j][i]) {
         case 'a': // empty space
           is_wall = FALSE;
           break; // break right away
@@ -201,3 +209,238 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
     clutter_actor_set_size (tmp ,newtile, newtile);
   }
 }
+
+void
+gnibbles_board_level_new (GnibblesBoard *board, gint level)
+{
+  //GnibblesLevel *board = g_new (GnibblesLevel, 1);
+  //board->level = level;
+  board->current_level = level;
+  gchar *tmp = NULL;
+  const char *dirname;
+  gchar *filename;
+  FILE *in;
+  gchar tmpboard [BOARDWIDTH +2];
+  gint i,j;
+  gint count = 0;
+
+  tmp = g_strdup_printf("level%03d.gnl", level);
+  
+  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_GAMES_DIRECTORY);
+  filename = g_build_filename (dirname, tmp, NULL);
+
+  g_free (tmp);
+
+  if ((in = fopen (filename, "r")) == NULL) {
+    char *message =
+      g_strdup_printf (_
+                        ("Nibbles couldn't load level file:\n%s\n\n"
+                        "Please check your Nibbles installation"), filename);
+    //gnibbles_error (window, message);
+    g_free (message);
+  }
+
+  if (boni)
+    gnibbles_boni_destroy (boni);
+
+  boni = gnibbles_boni_new ();
+
+  for (i = 0; i < properties->numworms; i++)
+    if (worms[i])
+      gnibbles_worm_destroy (worms[i]);
+
+  for (i = 0; i < BOARDHEIGHT; i++) {
+    if (!fgets (tmpboard, sizeof (tmpboard), in)) {
+      char *message =
+        g_strdup_printf (_
+                         ("Level file appears to be damaged:\n%s\n\n"
+                         "Please check your Nibbles installation"), filename);
+      //gnibbles_error (window, message);
+      g_free (message);
+      break;
+    }
+
+    for (j = 0; j < BOARDWIDTH; j++) {
+      board->walls[j][i] = tmpboard[j];
+      switch (board->walls[j][i]) {
+        case 'm':
+          board->walls[j][i] = EMPTYCHAR;
+          if (count < properties->numworms) {
+            worms[count] = gnibbles_worm_new (count, j, i, WORMUP);
+            count++;
+          }
+          break;
+        case 'n':
+          board->walls[j][i] = EMPTYCHAR;
+          if (count < properties->numworms) {
+            worms[count] = gnibbles_worm_new (count, j, i, WORMLEFT);
+            count++;
+          }
+          break;
+        case 'o':
+          board->walls[j][i] = EMPTYCHAR;
+          if (count < properties->numworms) {
+            worms[count] = gnibbles_worm_new (count, j, i, WORMDOWN);
+            count++;
+          }
+          break;
+        case 'p':
+          board->walls[j][i] = EMPTYCHAR;
+          if (count < properties->numworms) {
+            worms[count] = gnibbles_worm_new (count, j, i, WORMRIGHT);
+            count++;
+          }
+          break;
+        case 'Q':
+          gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
+          break;
+        case 'R':
+        case 'S':
+        case 'T':
+        case 'U':
+        case 'V':
+        case 'W':
+        case 'X':
+        case 'Y':
+        case 'Z':
+          gnibbles_warpmanager_add_warp
+            (warpmanager, j - 1, i - 1, -(board->walls[j][i]), 0);
+          break;
+        case 'r':
+        case 's':
+        case 't':
+        case 'u':
+        case 'v':
+        case 'w':
+        case 'x':
+        case 'y':
+        case 'z':
+          gnibbles_warpmanager_add_warp
+            (warpmanager, -(board->walls[j][i] - 'a' + 'A'), 0, j, i);
+          board->walls[j][i] = EMPTYCHAR;
+          break;
+       }
+    }
+  }
+
+  g_free (filename);
+  fclose (in);
+
+  for (i = 0; i < count; i++) {
+    board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+
+    if (worms[i]->direction == WORMRIGHT) {
+      for (j = 0; j < worms[i]->length; j++)
+        board->walls[++worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+    } else if ( worms[i]->direction == WORMLEFT) {
+      for (j = 0; j < worms[i]->length; j++)
+        board->walls[--worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+    } else if (worms[i]->direction == WORMDOWN) {
+      for (j = 0; j < worms[i]->length; j++)
+        board->walls[worms[i]->xhead][++worms[i]->yhead] = WORMCHAR;
+    } else if (worms[i]->direction == WORMUP) {
+      for (j = 0; j < worms[i]->length; j++)
+        board->walls[worms[i]->xhead][--worms[i]->yhead] = WORMCHAR;
+    }
+  }
+
+  gnibbles_board_load_level (board); 
+
+}
+
+void
+gnibbles_board_level_add_bonus (GnibblesBoard *board, gint regular)
+{
+  gint x, y, good;
+
+#ifdef GGZ_CLIENT
+  if (!network_is_host ()) {
+    return;
+  }
+#endif
+
+  if (regular) {
+    good = 0;
+  } else {
+    good = rand () % 50;
+    if (good)
+      return;
+  }
+
+  do {
+    good = 1;
+    x = rand () % (BOARDWIDTH - 1);
+    y = rand () % (BOARDHEIGHT - 1);
+    if (board->walls[x][y] != EMPTYCHAR)
+      good = 0;
+    if (board->walls[x + 1][y] != EMPTYCHAR)
+      good = 0;
+    if (board->walls[x][y + 1] != EMPTYCHAR)
+      good = 0;
+    if (board->walls[x + 1][y + 1] != EMPTYCHAR)
+      good = 0;
+  } while (!good);
+
+  if (regular) {
+    if ((rand () % 7 == 0) && properties->fakes)
+      gnibbles_boni_add_bonus (boni, x, y, BONUSREGULAR, 1, 300);
+    good = 0;
+    while (!good) {
+      good = 1;
+      x = rand () % (BOARDWIDTH - 1);
+      y = rand () % (BOARDHEIGHT - 1);
+      if (board->walls[x][y] != EMPTYCHAR)
+	      good = 0;
+      if (board->walls[x + 1][y] != EMPTYCHAR)
+	      good = 0;
+      if (board->walls[x][y + 1] != EMPTYCHAR)
+	      good = 0;
+      if (board->walls[x + 1][y + 1] != EMPTYCHAR)
+	      good = 0;
+    }
+    gnibbles_boni_add_bonus (boni, x, y, BONUSREGULAR, 0, 300);
+  } else if (boni->missed <= MAXMISSED) {
+    good = rand () % 7;
+
+    if (good)
+      good = 0;
+    else
+      good = 1;
+
+    if (good && !properties->fakes)
+      return;
+
+    switch (rand () % 21) {
+    case 0:
+    case 1:
+    case 2:
+    case 3:
+    case 4:
+    case 5:
+    case 6:
+    case 7:
+    case 8:
+    case 9:
+      gnibbles_boni_add_bonus (boni, x, y, BONUSHALF, good, 200);
+      break;
+    case 10:
+    case 11:
+    case 12:
+    case 13:
+    case 14:
+      gnibbles_boni_add_bonus (boni, x, y, BONUSDOUBLE, good, 150);
+      break;
+    case 15:
+      gnibbles_boni_add_bonus (boni, x, y, BONUSLIFE, good, 100);
+      break;
+    case 16:
+    case 17:
+    case 18:
+    case 19:
+    case 20:
+      if (properties->numworms > 1)
+	      gnibbles_boni_add_bonus (boni, x, y, BONUSREVERSE, good, 150);
+      break;
+    }
+  }
+}
diff --git a/gnibbles/board.h b/gnibbles/board.h
index 9ed8461..3b34f72 100644
--- a/gnibbles/board.h
+++ b/gnibbles/board.h
@@ -23,10 +23,17 @@
 #ifndef BOARD_H_
 #define BOARD_H_
 
+#include <config.h>
+
 #include <gtk/gtk.h>
 #include <clutter/clutter.h>
 
-#include "level.h"
+#define BOARDWIDTH 92
+#define BOARDHEIGHT 66
+
+#define EMPTYCHAR 'a'
+#define WORMCHAR 'w'
+
 
 typedef struct {
   gint width;
@@ -34,10 +41,13 @@ typedef struct {
   ClutterActor *stage;
   ClutterActor *surface;
   ClutterActor *level;
+
+  gchar walls[BOARDWIDTH][BOARDHEIGHT];
+  gint current_level;
 } GnibblesBoard;
 
 GnibblesBoard* gnibbles_board_new (ClutterActor *stage);
-void gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level);
 void gnibbles_board_resize (GnibblesBoard *board, gint newtile);
-
+void gnibbles_board_level_new (GnibblesBoard *board, gint level);
+void gnibbles_board_level_add_bonus (GnibblesBoard *board, gint regular);
 #endif
diff --git a/gnibbles/boni.c b/gnibbles/boni.c
index b8139b0..866ee7e 100644
--- a/gnibbles/boni.c
+++ b/gnibbles/boni.c
@@ -31,9 +31,9 @@
 #include "bonus.h"
 #include "boni.h"
 #include "ggz-network.h"
-#include "level.h"
+#include "board.h"
 
-extern GnibblesLevel *level;
+extern GnibblesBoard *board;
 
 GnibblesBoni *
 gnibbles_boni_new (void)
@@ -72,10 +72,10 @@ gnibbles_boni_add_bonus (GnibblesBoni * boni, gint t_x, gint t_y,
 							                                          t_type, t_fake,
 							                                          t_countdown);
 
-  level->walls[t_x][t_y] = t_type = 'A';
-  level->walls[t_x + 1][t_y] = t_type + 'A';
-  level->walls[t_x][t_y + 1] = t_type + 'A';
-  level->walls[t_x + 1][t_y + 1] = t_type + 'A';
+  board->walls[t_x][t_y] = t_type = 'A';
+  board->walls[t_x + 1][t_y] = t_type + 'A';
+  board->walls[t_x][t_y + 1] = t_type + 'A';
+  board->walls[t_x + 1][t_y + 1] = t_type + 'A';
 
   gnibbles_bonus_draw (boni->bonuses[boni->numbonuses]);
   
@@ -99,10 +99,10 @@ gnibbles_boni_add_bonus_final (GnibblesBoni * boni, gint t_x, gint t_y,
 							t_type, t_fake,
 							t_countdown);
 
-  level->walls[t_x][t_y] = t_type + 'A';
-  level->walls[t_x + 1][t_y] = t_type + 'A';
-  level->walls[t_x][t_y + 1] = t_type + 'A';
-  level->walls[t_x + 1][t_y + 1] = t_type + 'A';
+  board->walls[t_x][t_y] = t_type + 'A';
+  board->walls[t_x + 1][t_y] = t_type + 'A';
+  board->walls[t_x][t_y + 1] = t_type + 'A';
+  board->walls[t_x + 1][t_y + 1] = t_type + 'A';
 
   gnibbles_bonus_draw (boni->bonuses[boni->numbonuses]);
   boni->numbonuses++;
@@ -149,10 +149,10 @@ gnibbles_boni_remove_bonus (GnibblesBoni * boni, gint x, gint y)
 	      y == boni->bonuses[i]->y + 1) ||
 	      (x == boni->bonuses[i]->x + 1 && y == boni->bonuses[i]->y + 1)) {
 
-      level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1]	= EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x][boni->bonuses[i]->y] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1]	= EMPTYCHAR;
 
       gnibbles_bonus_erase (boni->bonuses[i]);
       boni->bonuses[i] = boni->bonuses[--boni->numbonuses];
@@ -175,10 +175,10 @@ gnibbles_boni_remove_bonus_final (GnibblesBoni * boni, gint x, gint y)
 	      y == boni->bonuses[i]->y + 1) ||
 	      (x == boni->bonuses[i]->x + 1 && y == boni->bonuses[i]->y + 1)) {
 
-      level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
-      level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x][boni->bonuses[i]->y] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
+      board->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1] = EMPTYCHAR;
 
       gnibbles_bonus_erase (boni->bonuses[i]);
       boni->bonuses[i] = boni->bonuses[--boni->numbonuses];
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 4b704d9..96557f3 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -44,7 +44,6 @@
 #include "properties.h"
 #include "scoreboard.h"
 #include "board.h"
-#include "level.h"
 #include "worm-clutter.h"
 
 #ifdef GGZ_CLIENT
@@ -74,7 +73,6 @@ GdkPixbuf *boni_pixmaps[9] = { NULL, NULL, NULL, NULL, NULL,
 
 extern GtkWidget *drawing_area;
 
-extern GnibblesLevel *level;
 extern GnibblesBoard *board;
 
 extern GnibblesProperties *properties;
@@ -248,7 +246,7 @@ gnibbles_move_worms (void)
                                     boni->bonuses[i]->x, 
                                     boni->bonuses[i]->y);
 	      boni->missed++;
-	      gnibbles_level_add_bonus (level, 1);
+	      gnibbles_board_level_add_bonus (board, 1);
       } else {
 	      gnibbles_boni_remove_bonus (boni, 
                                     boni->bonuses[i]->x, 
diff --git a/gnibbles/main.c b/gnibbles/main.c
index bd08204..2502aea 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -86,7 +86,6 @@ extern GdkPixbuf *logo_pixmap;
 GnibblesProperties *properties;
 
 GnibblesBoard *board; 
-GnibblesLevel *level;
 
 GnibblesScoreboard *scoreboard;
 
@@ -382,9 +381,8 @@ new_game (void)
   }
 
   hide_logo ();
-  level = gnibbles_level_new (current_level);
-  gnibbles_board_load_level (board, level);
-  gnibbles_level_add_bonus (level, 1);
+  gnibbles_board_level_new (board, current_level);
+  gnibbles_board_level_add_bonus (board, 1);
   gnibbles_init ();
 
   paused = 0;
@@ -526,16 +524,15 @@ end_game_cb (GtkAction * action, gpointer data)
 static gint
 add_bonus_cb (gpointer data)
 {
-  gnibbles_level_add_bonus (level, 0);
+  gnibbles_board_level_add_bonus (board, 0);
   return (TRUE);
 }
 
 static gint
 restart_game (gpointer data)
 {
-  level = gnibbles_level_new (current_level);
-  gnibbles_board_load_level (board, level);
-  gnibbles_level_add_bonus (level, 1);
+  gnibbles_board_level_new (board, current_level);
+  gnibbles_board_level_add_bonus (board, 1);
   dummy_id = g_timeout_add_seconds (1, (GSourceFunc) new_game_2_cb, NULL);
   restart_id = 0;
   
diff --git a/gnibbles/warpmanager.c b/gnibbles/warpmanager.c
index fd51a4b..902311a 100644
--- a/gnibbles/warpmanager.c
+++ b/gnibbles/warpmanager.c
@@ -29,9 +29,9 @@
 #include "warpmanager.h"
 #include "boni.h"
 #include "main.h"
-#include "level.h"
+#include "board.h"
 
-extern GnibblesLevel *level;
+extern GnibblesBoard *board;
 extern GnibblesBoni *boni;
 
 GnibblesWarpManager *
@@ -97,10 +97,10 @@ gnibbles_warpmanager_add_warp (GnibblesWarpManager * warpmanager, gint t_x,
       warpmanager->numwarps++;
     }
 
-    level->walls[t_x][t_y] = WARPLETTER;
-    level->walls[t_x + 1][t_y] = WARPLETTER;
-    level->walls[t_x][t_y + 1] = WARPLETTER;
-    level->walls[t_x + 1][t_y + 1] = WARPLETTER;
+    board->walls[t_x][t_y] = WARPLETTER;
+    board->walls[t_x + 1][t_y] = WARPLETTER;
+    board->walls[t_x][t_y + 1] = WARPLETTER;
+    board->walls[t_x + 1][t_y + 1] = WARPLETTER;
 
     gnibbles_warp_draw (warpmanager->warps[draw]);
   }
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 303d1fb..faebb47 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -34,7 +34,6 @@
 
 #include "main.h"
 #include "gnibbles.h"
-#include "level.h"
 #include "boni.h"
 #include "bonus.h"
 #include "warpmanager.h"
@@ -48,7 +47,6 @@
 
 extern GnibblesProperties *properties;
 extern GdkPixbuf *worm_pixmaps[];
-extern GnibblesLevel *level;
 extern GnibblesBoni *boni;
 extern GnibblesWarpManager *warpmanager;
 extern GnibblesWorm *worms[NUMWORMS];
@@ -225,7 +223,7 @@ gnibbles_worm_grok_bonus (GnibblesWorm *worm)
     return;
   }
 
-  switch (level->walls[worm->xhead][worm->yhead] - 'A') {
+  switch (board->walls[worm->xhead][worm->yhead] - 'A') {
   case BONUSREGULAR:
     boni->numleft--;
     worm->change += (NUMBONI - boni->numleft) * GROWFACTOR;
@@ -309,7 +307,7 @@ gnibbles_worm_get_actor_length (ClutterActor *actor) {
   gfloat w,h;
 
   clutter_actor_get_size (CLUTTER_ACTOR (actor), &w, &h);
-  size = w > h ? roundf(w) : roundf(h);
+  size = MAX (w,h);
   size = roundf (size / properties->tilesize);
 
   return size;
@@ -334,24 +332,24 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
     switch (tail_dir) {
       case WORMUP:
         for (i = 0; i < tail_length; i++)
-          level->walls[worm->xtail][worm->ytail--] = EMPTYCHAR;
+          board->walls[worm->xtail][worm->ytail--] = EMPTYCHAR;
         break;
       case WORMDOWN:
         for (i = 0; i < tail_length; i++)
-          level->walls[worm->xtail][worm->ytail++] = EMPTYCHAR;
+          board->walls[worm->xtail][worm->ytail++] = EMPTYCHAR;
         break;
       case WORMLEFT:
         for (i = 0; i < tail_length; i++)
-          level->walls[worm->xtail--][worm->ytail] = EMPTYCHAR;
+          board->walls[worm->xtail--][worm->ytail] = EMPTYCHAR;
         break;
       case WORMRIGHT:
         for (i = 0; i < tail_length; i++)
-          level->walls[worm->xtail++][worm->ytail] = EMPTYCHAR;
+          board->walls[worm->xtail++][worm->ytail] = EMPTYCHAR;
         break;
       default:
         break;
     }
-    level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+    board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
     gnibbles_worm_remove_actor (worm);
   }
 
@@ -364,19 +362,19 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
 
   if (!(worm->lives <= 0)) {
     gnibbles_worm_show (worm);
-    level->walls[worm->xhead][worm->yhead] = WORMCHAR;
+    board->walls[worm->xhead][worm->yhead] = WORMCHAR;
     if (worm->direction == WORMRIGHT) {
       for (j = 0; j < worm->length; j++)
-        level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+        board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
     } else if ( worm->direction == WORMLEFT) {
       for (j = 0; j < worm->length; j++)
-        level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+        board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
     } else if (worm->direction == WORMDOWN) {
       for (j = 0; j < worm->length; j++)
-        level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+        board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
     } else if (worm->direction == WORMUP) {
       for (j = 0; j < worm->length; j++)
-        level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+        board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
     }
   }
 /*
@@ -384,10 +382,10 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
   fo = fopen ("output.txt", "w" );
   for (i = 0; i < BOARDWIDTH; i++) {
     for (j = 0; j < BOARDHEIGHT; j++) {
-      if (level->walls[i][j] == 'a')
+      if (board->walls[i][j] == 'a')
         fprintf(fo, "%c", ' ');
       else
-        fprintf (fo , "%c", level->walls[i][j]);
+        fprintf (fo , "%c", board->walls[i][j]);
     }
     fprintf (fo, "\n");
   }
@@ -703,16 +701,16 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
 
   clutter_actor_get_position (CLUTTER_ACTOR (head), &x, &y);
 
-  if ((level->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
-      (level->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+  if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
+      (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
     
     gnibbles_worm_grok_bonus (worm);
     
-    if ((level->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
+    if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
 	      !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
       gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
       if (boni->numleft != 0)
-	      gnibbles_level_add_bonus (level, 1);
+	      gnibbles_board_level_add_bonus (board, 1);
     } else
       gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
   }
@@ -721,8 +719,8 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
     case WORMRIGHT:
       clutter_actor_set_x (CLUTTER_ACTOR (head), 
                                  x + properties->tilesize);
-      level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
-      level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+      board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+      board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
       if (worm->xtail == BOARDWIDTH)
         worm->xtail = 0;
       else 
@@ -731,8 +729,8 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
     case WORMDOWN:
       clutter_actor_set_y (CLUTTER_ACTOR (head), 
                                   y + properties->tilesize);
-      level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
-      level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+      board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+      board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
       if (worm->ytail == BOARDHEIGHT)
         worm->ytail = 0;
       else
@@ -741,8 +739,8 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
     case WORMLEFT:
       clutter_actor_set_x (CLUTTER_ACTOR (head), 
                                  x - properties->tilesize);
-      level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
-      level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+      board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+      board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
       if (worm->xtail == 0)
         worm->xtail = BOARDWIDTH - 1;
       else
@@ -751,8 +749,8 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
     case WORMUP:
       clutter_actor_set_y (CLUTTER_ACTOR (head), 
                                   y - properties->tilesize);
-      level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
-      level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+      board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+      board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
       if (worm->ytail == 0)
         worm->ytail = BOARDHEIGHT - 1;
       else
@@ -787,16 +785,16 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
   size = w < h ? floorf (h) : floorf (w);
   size = floorf (size + properties->tilesize);
 
-  if ((level->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
-      (level->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+  if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
+      (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
     
     gnibbles_worm_grok_bonus (worm);
     
-    if ((level->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
+    if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
 	      !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
       gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
       if (boni->numleft != 0)
-	      gnibbles_level_add_bonus (level, 1);
+	      gnibbles_board_level_add_bonus (board, 1);
     } else
       gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
   }
@@ -805,23 +803,23 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
   switch (worm->direction) {
     case WORMRIGHT:
       clutter_actor_set_width (CLUTTER_ACTOR (head), size);
-      level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+      board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
       break;
     case WORMDOWN:
       clutter_actor_set_height (CLUTTER_ACTOR (head), size);
-      level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+      board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
       break;
     case WORMLEFT:
       clutter_actor_set_width (CLUTTER_ACTOR (head), size);
       clutter_actor_set_x (CLUTTER_ACTOR (head), 
                                   x - properties->tilesize);
-      level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+      board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
       break;
     case WORMUP:
       clutter_actor_set_height (CLUTTER_ACTOR (head), size);
       clutter_actor_set_y (CLUTTER_ACTOR (head), 
                                   y - properties->tilesize);
-      level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+      board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
       break;
     default:
       break;
@@ -848,7 +846,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
 
   clutter_actor_get_size (CLUTTER_ACTOR (tail), &w, &h);
   clutter_actor_get_position (CLUTTER_ACTOR (tail), &x, &y);
-  size = w < h ? floorf (h) : floorf (w);
+  size = MAX (w, h);
   size = floorf (size - properties->tilesize);
 
   if (size <= 0) {
@@ -861,7 +859,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
         clutter_actor_set_x (CLUTTER_ACTOR (tail), 
                                     x + properties->tilesize);
 
-        level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+        board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
         if (worm->xtail == BOARDWIDTH) 
           worm->xtail = 0;
         else 
@@ -871,7 +869,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
         clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
         clutter_actor_set_y (CLUTTER_ACTOR (tail), 
                                     y + properties->tilesize);
-        level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+        board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
         if (worm->ytail == BOARDHEIGHT)
           worm->ytail = 0;
         else
@@ -879,7 +877,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
         break;
       case WORMLEFT:
         clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
-        level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+        board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
         if (worm->xtail == 0)
           worm->xtail = BOARDWIDTH - 1;
         else
@@ -887,7 +885,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
         break;
       case WORMUP:
         clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
-        level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+        board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
         if (worm->ytail == 0)
           worm->ytail = BOARDHEIGHT - 1;
         else
@@ -916,7 +914,7 @@ gnibbles_worm_shrink (GnibblesWorm *worm, gint shrinksize)
   for (i = 0; i < nbr_actor; i++) {
     tmp = CLUTTER_ACTOR (g_list_last (worm->list)->data); 
     clutter_actor_get_size (CLUTTER_ACTOR (tmp), &w, &h);
-    actor_size = w < h ? roundf (h) : roundf (w);
+    actor_size = MAX (w, h);
     actor_size /= properties->tilesize;
 
     if (actor_size > shrinksize) {
@@ -1042,7 +1040,7 @@ gnibbles_worm_test_move_head (GnibblesWorm * worm)
 
   gnibbles_worm_position_move_head(worm, &x, &y);
 
-  if (level->walls[x][y] > EMPTYCHAR && level->walls[x][y] < 'z' + properties->numworms)
+  if (board->walls[x][y] > EMPTYCHAR && board->walls[x][y] < 'z' + properties->numworms)
     return (FALSE);
 
   return TRUE;
@@ -1125,8 +1123,8 @@ gnibbles_worm_ai_deadend (gint x, gint y, gint lengthleft)
     if (cy < 0)
       cy = BOARDHEIGHT - 1;
 
-    if ((level->walls[cx][cy] <= EMPTYCHAR
-	      || level->walls[x][y] >= 'z' + properties->numworms)
+    if ((board->walls[cx][cy] <= EMPTYCHAR
+	      || board->walls[x][y] >= 'z' + properties->numworms)
 	      && deadendboard[cx][cy] != deadend_runnumber) {
        
       deadendboard[cx][cy] = deadend_runnumber;
@@ -1276,7 +1274,7 @@ gnibbles_worm_ai_wander (gint x, gint y, gint dir, gint ox, gint oy)
   if (y < 0)
     y = BOARDHEIGHT - 1;
 
-  switch (level->walls[x][y] - 'A') {
+  switch (board->walls[x][y] - 'A') {
     case BONUSREGULAR:
     case BONUSDOUBLE:
     case BONUSLIFE:
@@ -1287,7 +1285,7 @@ gnibbles_worm_ai_wander (gint x, gint y, gint dir, gint ox, gint oy)
       return 0;
       break;
     default: 
-      if (level->walls[x][y] > EMPTYCHAR && level->walls[x][y] < 'z' + properties->numworms) {
+      if (board->walls[x][y] > EMPTYCHAR && board->walls[x][y] < 'z' + properties->numworms) {
         return 0;
       } else {
         if (ox == x && oy == y)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]