[gnome-games] Ending the game when a player do not have lives left
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] Ending the game when a player do not have lives left
- Date: Wed, 14 Oct 2009 02:55:47 +0000 (UTC)
commit f05bcbf565f9a28632eb458a909550c077d48148
Author: Guillaume Beland <guillaume beland gmail com>
Date: Fri Aug 21 20:05:45 2009 -0400
Ending the game when a player do not have lives left
gnibbles/gnibbles.c | 20 ++++++++++-------
gnibbles/main.c | 59 +++++++++++++++++++++++++--------------------------
gnibbles/worm.c | 3 +-
3 files changed, 43 insertions(+), 39 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 1e9d782..bf100fb 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -229,9 +229,9 @@ gnibbles_move_worms (void)
{
gint i, j, olddir;
gint status = 1, nlives = 1;
- gboolean *dead;
+ gint *dead;
- dead = g_new (gboolean, properties->numworms);
+ dead = g_new (gint, properties->numworms);
for (i = 0; i < properties->numworms; i++) {
olddir = worms[i]->direction;
@@ -266,10 +266,8 @@ gnibbles_move_worms (void)
worms[0]->xtail, worms[0]->ytail);
*/
for (i = 0; i < properties->numworms; i++) {
- if (!worms[i]->stop) {
- dead[i] = !gnibbles_worm_test_move_head (worms[i]);
- status &= !dead[i];
- }
+ dead[i] = !gnibbles_worm_test_move_head (worms[i]);
+ status &= !dead[i];
}
for (i = 0; i < properties->numworms; i++) {
@@ -309,7 +307,12 @@ gnibbles_move_worms (void)
if (status & GAMEOVER) {
games_sound_play ("crash");
games_sound_play ("gameover");
- return (GAMEOVER);
+ return GAMEOVER;
+ }
+
+ for (i = 0; i < properties->numworms; i++) {
+ if (worms[i]->human && worms[i]->lives <= 0)
+ return GAMEOVER;
}
for (i = 0; i < properties->numworms; i++) {
@@ -318,7 +321,8 @@ gnibbles_move_worms (void)
}
if (nlives == 1 && (properties->ai + properties->human > 1)) {
- /* There is one player left, the other AI players are dead, and that player has won! */
+ /* There is one player left, the other AI players are dead,
+ * and that player has won! */
return VICTORY;
} else if (nlives == 0) {
/* There was only one worm, and it died. */
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 91567d9..5b6821f 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -633,7 +633,35 @@ main_loop (gpointer data)
(GSourceFunc) erase_worms_cb,
(gpointer) ERASESIZE);
gnibbles_log_score (window);
- return (FALSE);
+ return FALSE;
+ }
+
+ if (status == NEWROUND) {
+#ifdef GGZ_CLIENT
+ if (ggz_network_mode) {
+ end_game (TRUE);
+ add_chat_text (_("The game is over."));
+ return FALSE;
+ }
+#endif
+
+ if (keyboard_id) {
+ g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
+ keyboard_id = 0;
+ }
+ if (add_bonus_id)
+ g_source_remove (add_bonus_id);
+
+ if (main_id) {
+ g_source_remove (main_id);
+ main_id = 0;
+ }
+ add_bonus_id = 0;
+ erase_id = g_timeout_add (ERASETIME / ERASESIZE,
+ (GSourceFunc) erase_worms_cb,
+ (gpointer) ERASESIZE);
+ restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
+ return FALSE;
}
if (boni->numleft == 0) {
@@ -666,35 +694,6 @@ main_loop (gpointer data)
return FALSE;
}
- if (status == NEWROUND) {
-
-#ifdef GGZ_CLIENT
- if (ggz_network_mode) {
- end_game (TRUE);
- add_chat_text (_("The game is over."));
- return FALSE;
- }
-#endif
-
- if (keyboard_id) {
- g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
- keyboard_id = 0;
- }
- if (add_bonus_id)
- g_source_remove (add_bonus_id);
-
- if (main_id) {
- g_source_remove (main_id);
- main_id = 0;
- }
- add_bonus_id = 0;
- erase_id = g_timeout_add (ERASETIME / ERASESIZE,
- (GSourceFunc) erase_worms_cb,
- (gpointer) ERASESIZE);
- restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
- return FALSE;
- }
-
return TRUE;
}
diff --git a/gnibbles/worm.c b/gnibbles/worm.c
index 97970c4..a205af3 100644
--- a/gnibbles/worm.c
+++ b/gnibbles/worm.c
@@ -537,6 +537,7 @@ gnibbles_worm_set_start (GnibblesWorm *worm, guint t_xhead,
worm->direction_start = t_direction;
worm->length = SLENGTH;
worm->change = 0;
+ worm->stop = FALSE;
gnibbles_worm_queue_empty (worm);
}
@@ -839,7 +840,7 @@ gnibbles_worm_test_move_head (GnibblesWorm * worm)
if (board->walls[x][y] > EMPTYCHAR
&& board->walls[x][y] < 'z' + properties->numworms)
- return (FALSE);
+ return FALSE;
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]