[gnome-games/gnibbles-clutter] Removed old worm.c|h & some trivial code refactoring
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter] Removed old worm.c|h & some trivial code refactoring
- Date: Wed, 12 Aug 2009 23:14:41 +0000 (UTC)
commit f1da6c80309c07af79d175c195b27adde17c9776
Author: Guillaume Beland <guillaume beland gmail com>
Date: Wed Aug 12 19:13:46 2009 -0400
Removed old worm.c|h & some trivial code refactoring
gnibbles/gnibbles.c | 3 -
gnibbles/worm-clutter.c | 109 +++----
gnibbles/worm.c | 920 -----------------------------------------------
gnibbles/worm.h | 87 -----
4 files changed, 47 insertions(+), 1072 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index f975b4d..7e5d71e 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -262,9 +262,6 @@ gnibbles_move_worms (void)
}
}
- printf ("head: (%d,%d), tail (%d,%d)\n",
- worms[0]->xhead, worms[0]->yhead,
- worms[0]->xtail, worms[0]->ytail);
for (i = 0; i < properties->numworms; i++) {
dead[i] = !gnibbles_worm_test_move_head (worms[i]);
status &= !dead[i];
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 0c70d41..0dda5c4 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -477,9 +477,8 @@ gnibbles_worm_reset (ClutterAnimation *anim, GnibblesWorm *worm)
{
gint j;
- for (j = 0; j < g_list_length(worm->list); j++) {
+ for (j = 0; j < g_list_length(worm->list); j++)
gnibbles_worm_move_tail_pointer (worm);
- }
worm->xhead = worm->xstart;
worm->yhead = worm->ystart;
@@ -492,21 +491,6 @@ gnibbles_worm_reset (ClutterAnimation *anim, GnibblesWorm *worm)
worm->change = SLENGTH - 1;
gnibbles_worm_show (worm);
}
- /* DEBUG *//*
- gint i;
- FILE *fo;
- fo = fopen ("output.txt", "w" );
- for (i = 0; i < BOARDHEIGHT; i++) {
- for (j = 0; j < BOARDWIDTH; j++) {
- if (board->walls[j][i] == 'a')
- fprintf(fo, "%c", ' ');
- else
- fprintf (fo , "%c", board->walls[j][i]);
- }
- fprintf (fo, "\n");
- }
- fclose (fo);
- */
}
GnibblesWorm*
@@ -556,11 +540,6 @@ gnibbles_worm_destroy (GnibblesWorm *worm)
{
while (worm->list)
gnibbles_worm_remove_actor (worm);
-
- //if (worm->list)
- // g_list_free (worm->list);
-
- //g_free (worm);
}
void
@@ -774,18 +753,18 @@ gnibbles_worm_ai_deadend (gint x, gint y, gint lengthleft)
cx = x;
cy = y;
switch (cdir) {
- case WORMUP:
- cy -= 1;
- break;
- case WORMDOWN:
- cy += 1;
- break;
- case WORMLEFT:
- cx -= 1;
- break;
- case WORMRIGHT:
- cx += 1;
- break;
+ case WORMUP:
+ cy -= 1;
+ break;
+ case WORMDOWN:
+ cy += 1;
+ break;
+ case WORMLEFT:
+ cx -= 1;
+ break;
+ case WORMRIGHT:
+ cx += 1;
+ break;
}
if (cx >= BOARDWIDTH)
@@ -839,28 +818,32 @@ gnibbles_worm_ai_deadend_after (gint x, gint y, gint dir, gint length)
cx = worms[i]->xhead;
cy = worms[i]->yhead;
if(cx != x || cy != y) {
- if(cx > 0) deadendboard[cx-1][cy] = deadend_runnumber;
- if(cy > 0) deadendboard[cx][cy-1] = deadend_runnumber;
- if(cx < BOARDWIDTH-1) deadendboard[cx+1][cy] = deadend_runnumber;
- if(cy < BOARDHEIGHT-1) deadendboard[cx][cy+1] = deadend_runnumber;
+ if(cx > 0)
+ deadendboard[cx-1][cy] = deadend_runnumber;
+ if(cy > 0)
+ deadendboard[cx][cy-1] = deadend_runnumber;
+ if(cx < BOARDWIDTH-1)
+ deadendboard[cx+1][cy] = deadend_runnumber;
+ if(cy < BOARDHEIGHT-1)
+ deadendboard[cx][cy+1] = deadend_runnumber;
}
}
cx = x;
cy = y;
switch (dir) {
- case WORMUP:
- cy -= 1;
- break;
- case WORMDOWN:
- cy += 1;
- break;
- case WORMLEFT:
- cx -= 1;
- break;
- case WORMRIGHT:
- cx += 1;
- break;
+ case WORMUP:
+ cy -= 1;
+ break;
+ case WORMDOWN:
+ cy += 1;
+ break;
+ case WORMLEFT:
+ cx -= 1;
+ break;
+ case WORMRIGHT:
+ cx += 1;
+ break;
}
if (cx >= BOARDWIDTH)
@@ -959,7 +942,8 @@ gnibbles_worm_ai_wander (gint x, gint y, gint dir, gint ox, gint oy)
return 0;
break;
default:
- if (board->walls[x][y] > EMPTYCHAR && board->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)
@@ -979,12 +963,14 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
opposite = (worm->direction + 1) % 4 + 1;
- front = gnibbles_worm_ai_wander
- (worm->xhead, worm->yhead, worm->direction, worm->xhead, worm->yhead);
- left = gnibbles_worm_ai_wander
- (worm->xhead, worm->yhead, worm->direction - 1, worm->xhead, worm->yhead);
- right = gnibbles_worm_ai_wander
- (worm->xhead, worm->yhead, worm->direction + 1, worm->xhead, worm->yhead);
+ front = gnibbles_worm_ai_wander (worm->xhead, worm->yhead,
+ worm->direction, worm->xhead, worm->yhead);
+ left = gnibbles_worm_ai_wander (worm->xhead, worm->yhead,
+ worm->direction - 1,
+ worm->xhead, worm->yhead);
+ right = gnibbles_worm_ai_wander (worm->xhead, worm->yhead,
+ worm->direction + 1,
+ worm->xhead, worm->yhead);
if (!front) {
if (left) {
@@ -1045,8 +1031,8 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
if(!gnibbles_worm_is_move_safe (worm))
thislen += 4;
- thislen += gnibbles_worm_ai_deadend_after
- (worm->xhead, worm->yhead, dir, worm->length + worm->change);
+ thislen += gnibbles_worm_ai_deadend_after (worm->xhead, worm->yhead, dir,
+ worm->length + worm->change);
if (dir == olddir && !thislen)
thislen -= 100;
@@ -1072,10 +1058,9 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
for (dir = 1; dir <= 4; dir++) {
if (dir == opposite)
continue;
- if (!gnibbles_worm_test_move_head (worm)) {
+ if (!gnibbles_worm_test_move_head (worm))
worm->direction = dir;
- } else {
+ else
continue;
- }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]