Пример #1
0
/****************************************************************************
  Callback function that's called by the library when we launch a game.  This
  means we now have a connection to a gnect server so handling can be given
  back to the regular gnect code.
****************************************************************************/
static void
ggz_game_launched (void)
{
  gchar *str = NULL;

  network_init ();
  end_game (TRUE);

  str = g_strdup_printf (_("Welcome to a network game of %s."),
			 NETWORK_ENGINE);
  add_chat_text (str);
  add_chat_text ("\n");
  g_free (str);

}
Пример #2
0
static int
get_players (void)
{
  int i, old;
  static int firsttime = 1;
  char *tmp;

  if (ggz_read_int (fd, &num_players) < 0)
    return -1;
  for (i = 0; i < num_players; i++) {
    old = seats[i];
    if (ggz_read_int (fd, &seats[i]) < 0)
      return -1;
    if (seats[i] != GGZ_SEAT_OPEN) {
      if (ggz_read_string (fd, (char *) &names[i], 17) < 0)
	return -1;
      /*display_set_name(i, game.names[i]); */
      if (old == GGZ_SEAT_OPEN && !firsttime) {
	tmp = g_strdup_printf (_("%s joined the game.\n"), names[i]);
	add_chat_text (tmp);
	g_free (tmp);
      }
    } 

    if (seats[i] == GGZ_SEAT_ABANDONED) {
      if (i == 0) {
	tmp =
	  g_strdup_printf (_
			   ("The game ended because the host %s left the game.\n"),
			   names[i]);
	add_chat_text (tmp);
	g_free (tmp);
      } else {
	tmp =
	  g_strdup_printf (_("%s left the game.\n"),
			   names[i]);
	add_chat_text (tmp);
	g_free (tmp);
      }
    }
  }

  firsttime = 0;
  /* game.got_players++; */

  return 0;
}
Пример #3
0
/****************************************************************************
  Callback function that's called by the library when we launch a game.  This
  means we now have a connection to a gnect server so handling can be given
  back to the regular gnect code.
****************************************************************************/
static void
ggz_game_launched (void)
{
  gchar *str = NULL;

  network_init ();
  game_reset ();
  gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), MAIN_PAGE);

  str = g_strdup_printf (_("Welcome to a network game of %s."),
			 NETWORK_ENGINE);
  add_chat_text (str);
  g_free (str);

}
Пример #4
0
gboolean
main_loop (gpointer data)
{
  gint status;
  gint tmp, winner;
  gchar *str = NULL;

  status = gnibbles_move_worms ();
  gnibbles_scoreboard_update (scoreboard);

  if (status == VICTORY) {
    end_game (TRUE);
    winner = gnibbles_get_winner ();

    if (winner == -1)
      return FALSE;

    str = g_strdup_printf (_("Game over! The game has been won by %s!"),
                             names[winner]);
#ifdef GGZ_CLIENT
    add_chat_text (str);
#endif
    g_free (str);

    if (keyboard_id) {
      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
      keyboard_id = 0;
    }
    if (main_id) {
      g_source_remove (main_id);
      main_id = 0;
    }
    if (add_bonus_id)
      g_source_remove (add_bonus_id);

    add_bonus_id = 0;

    animate_end_game ();
    gnibbles_log_score (window);

    return FALSE;
  }

  if (status == GAMEOVER) {

    if (keyboard_id) {
      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
      keyboard_id = 0;
    }
    main_id = 0;
    if (add_bonus_id)
      g_source_remove (add_bonus_id);

    add_bonus_id = 0;

    animate_end_game ();
    gnibbles_log_score (window);

    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;

    animate_end_game ();
    restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);

    return FALSE;
  }

  if (boni->numleft == 0) {
    if (restart_id)
      return TRUE;

    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);

    add_bonus_id = 0;
    if (main_id) {
      g_source_remove (main_id);
      main_id = 0;
    }
    if ((current_level < MAXLEVEL) && (!properties->random
                                       || ggz_network_mode)) {
      current_level++;
    } else if (properties->random && !ggz_network_mode) {
      tmp = rand () % MAXLEVEL + 1;
      while (tmp == current_level)
        tmp = rand () % MAXLEVEL + 1;
      current_level = tmp;
    }
    animate_end_game ();
    restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
    return FALSE;
  }

  return TRUE;
}