~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to gnobots2/game.c

  • Committer: Package Import Robot
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 12:08:49 UTC
  • mfrom: (1.2.1)
  • mto: (163.1.3 precise) (3.2.1 sid) (1.4.1)
  • mto: This revision was merged to the branch mainline in revision 40.
  • Revision ID: package-import@ubuntu.com-20070502120849-p1824p19fzg6y0c8
Tags: upstream-2.19.1
ImportĀ upstreamĀ versionĀ 2.19.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <gnome.h>
24
24
#include <stdlib.h>
25
25
#include <math.h>
 
26
#include <games-scores.h>
 
27
#include <games-scores-dialog.h>
26
28
 
27
29
#include "gbdefs.h"
28
30
#include "gameconfig.h"
119
121
/**
120
122
 * show_scores
121
123
 * @pos: score-table position
 
124
 * @endofgame: game state
122
125
 *
123
126
 * Description:
124
127
 * Displays the high-score table
125
128
 **/
126
 
void
127
 
show_scores (guint pos)
 
129
 
 
130
gint
 
131
show_scores (gint pos, gboolean endofgame)
128
132
{
129
 
  static GtkWidget *score_dialog = NULL;
130
 
  gchar *sbuf = NULL;
131
 
  gchar *nbuf = NULL;
132
 
 
133
 
  if (properties_super_safe_moves ()) {
134
 
    sbuf =
135
 
      g_strdup_printf ("%s-super-safe",
136
 
                       game_config_filename (current_game_config ()));
137
 
  } else if (properties_safe_moves ()) {
138
 
    sbuf =
139
 
      g_strdup_printf ("%s-safe",
140
 
                       game_config_filename (current_game_config ()));
141
 
  } else {
142
 
    sbuf =
143
 
      g_strdup_printf ("%s", game_config_filename (current_game_config ()));
144
 
  }
145
 
 
146
 
  if (properties_super_safe_moves ()) {
147
 
    nbuf = g_strdup_printf (_("'%s' with super-safe moves"),
148
 
                            _(game_config_name (current_game_config ())));
149
 
  } else if (properties_safe_moves ()) {
150
 
    nbuf = g_strdup_printf (_("'%s' with safe moves"),
151
 
                            _(game_config_name (current_game_config ())));
152
 
  } else {
153
 
    nbuf =
154
 
      g_strdup_printf ("'%s'", _(game_config_name (current_game_config ())));
155
 
  }
156
 
 
157
 
  if (score_dialog != NULL) {
158
 
    gtk_window_present (GTK_WINDOW (score_dialog));
159
 
    return;
160
 
  }
161
 
  score_dialog = gnome_scores_display (nbuf, GAME_NAME, sbuf, pos);
162
 
  g_free (sbuf);
163
 
  g_free (nbuf);
164
 
 
165
 
  if (!score_dialog)
166
 
    return;
167
 
 
168
 
  gtk_window_set_transient_for (GTK_WINDOW (score_dialog), GTK_WINDOW (app));
169
 
  gtk_dialog_set_has_separator (GTK_DIALOG (score_dialog), FALSE);
170
 
  gtk_container_set_border_width (GTK_CONTAINER (score_dialog), 5);
171
 
  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (score_dialog)->vbox), 2);
172
 
  gtk_window_set_resizable (GTK_WINDOW (score_dialog), FALSE);
173
 
  g_signal_connect (G_OBJECT (score_dialog), "destroy",
174
 
                    G_CALLBACK (gtk_widget_destroyed), &score_dialog);
 
133
  gchar *message;
 
134
  static GtkWidget *scoresdialog = NULL;
 
135
  static GtkWidget *sorrydialog = NULL;
 
136
  GtkWidget *dialog;
 
137
  gint result;
 
138
 
 
139
  if (endofgame && (pos <= 0)) {
 
140
    if (sorrydialog != NULL) {
 
141
      gtk_window_present (GTK_WINDOW (sorrydialog));
 
142
    } else {
 
143
      sorrydialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app),
 
144
                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
 
145
                                                        GTK_MESSAGE_INFO,
 
146
                                                        GTK_BUTTONS_NONE,
 
147
                                                        "<b>%s</b>\n%s",
 
148
                                                        _
 
149
                                                        ("Game over!"),
 
150
                                                        _
 
151
                                                        ("Great work, but unfortunately your score did not make the top ten."));
 
152
      gtk_dialog_add_buttons (GTK_DIALOG (sorrydialog), GTK_STOCK_QUIT,
 
153
                              GTK_RESPONSE_REJECT, _("_New Game"),
 
154
                              GTK_RESPONSE_ACCEPT, NULL);
 
155
      gtk_dialog_set_default_response (GTK_DIALOG (sorrydialog),
 
156
                                       GTK_RESPONSE_ACCEPT);
 
157
      gtk_window_set_title (GTK_WINDOW (sorrydialog), "");
 
158
    }
 
159
    dialog = sorrydialog;
 
160
  } else {
 
161
 
 
162
    if (scoresdialog != NULL) {
 
163
      gtk_window_present (GTK_WINDOW (scoresdialog));
 
164
    } else {
 
165
      scoresdialog = games_scores_dialog_new (GTK_WINDOW (app), 
 
166
                                        highscores, _("Klotski Scores"));
 
167
      games_scores_dialog_set_category_description (GAMES_SCORES_DIALOG
 
168
                                                    (scoresdialog),
 
169
                                                    _("Map:"));
 
170
    }
 
171
 
 
172
    if (pos > 0) {
 
173
      games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (scoresdialog),
 
174
                                       pos);
 
175
      message = g_strdup_printf ("<b>%s</b>\n\n%s",
 
176
                                 _("Congratulations!"),
 
177
                                 _("Your score has made the top ten."));
 
178
      games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
 
179
                                       message);
 
180
      g_free (message);
 
181
    } else {
 
182
      games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
 
183
                                       NULL);
 
184
    }
 
185
 
 
186
    if (endofgame) {
 
187
      games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog),
 
188
                                       GAMES_SCORES_QUIT_BUTTON |
 
189
                                       GAMES_SCORES_NEW_GAME_BUTTON);
 
190
    } else {
 
191
      games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog), 0);
 
192
    }
 
193
    dialog = scoresdialog;
 
194
  }
 
195
 
 
196
  result = gtk_dialog_run (GTK_DIALOG (dialog));
 
197
  gtk_widget_hide (dialog);
 
198
 
 
199
  return result;
175
200
}
176
201
 
177
 
 
178
202
/**
179
203
 * log_score
180
204
 * @sc: score
190
214
{
191
215
  guint pos = 0;
192
216
  gchar *sbuf = NULL;
 
217
  GamesScoreValue score;
193
218
 
194
219
  if (properties_super_safe_moves ()) {
195
220
    sbuf =
204
229
      g_strdup_printf ("%s", game_config_filename (current_game_config ()));
205
230
  }
206
231
 
207
 
  if (sc != 0)
208
 
    pos = gnome_score_log ((gfloat) sc, sbuf, TRUE);
 
232
  if (sc != 0) {
 
233
    score.plain = (guint32) sc;
 
234
    games_scores_set_category (highscores, sbuf);
 
235
    pos = games_scores_add_score (highscores, score);
 
236
  }
209
237
  g_free (sbuf);
210
238
  update_score_state ();
211
239
 
585
613
        sp = log_score (score);
586
614
        if (sp > 0) {
587
615
          play_sound (SOUND_VICTORY);
588
 
          show_scores (sp);
 
616
          if (show_scores (sp, TRUE) == GTK_RESPONSE_REJECT) {
 
617
            quit_game ();
 
618
          }
589
619
        }
590
620
      }
591
621
      start_new_game ();