[gnome-mines] Replace the hint button with a flag icon



commit 27d03f3d5ca1871448453b8d114f4ac5afd89097
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Apr 16 23:29:03 2014 -0500

    Replace the hint button with a flag icon
    
    As per the new design. (The flag icon is temporary.)

 src/gnome-mines.vala |   40 ++++---------------------
 src/minefield.vala   |   77 --------------------------------------------------
 2 files changed, 7 insertions(+), 110 deletions(-)
---
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 29878fe..553a435 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -32,7 +32,6 @@ public class Mines : Gtk.Application
 
     private Gtk.Box clock_box;
     private Gtk.Label clock_label;
-    private Gtk.Button hint_button;
 
     private Menu app_main_menu;
 
@@ -66,7 +65,6 @@ public class Mines : Gtk.Application
     private SimpleAction new_game_action;
     private SimpleAction repeat_size_action;
     private SimpleAction pause_action;
-    private SimpleAction hint_action;
     private Gtk.AspectFrame new_game_screen;
     private Gtk.AspectFrame custom_game_screen;
     private bool is_new_game_screen;
@@ -75,7 +73,6 @@ public class Mines : Gtk.Application
     {
         { "new-game",      new_game_cb                                            },
         { "repeat-size",   repeat_size_cb                                         },
-        { "hint",          hint_cb                                                },
         { "pause",         toggle_pause_cb                                        },
         { "scores",        scores_cb                                              },
         { "preferences",   preferences_cb                                         },
@@ -105,8 +102,6 @@ public class Mines : Gtk.Application
         new_game_action.set_enabled (false);
         repeat_size_action = lookup_action ("repeat-size") as SimpleAction;
         repeat_size_action.set_enabled (false);
-        hint_action = lookup_action ("hint") as SimpleAction;
-        hint_action.set_enabled (false);
         pause_action = lookup_action ("pause") as SimpleAction;
         pause_action.set_enabled (false);
 
@@ -187,21 +182,15 @@ public class Mines : Gtk.Application
 
         var size = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
 
-        hint_button = new Gtk.Button ();
         var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 2);
-        var image = new Gtk.Image.from_icon_name ("dialog-question-symbolic", Gtk.IconSize.DND);
-        box.pack_start (image);
+        // Obviously a FIXME image
+        var image = new Gtk.Image.from_icon_name ("preferences-desktop-locale-symbolic", Gtk.IconSize.DND);
+        box.pack_start (image, false, false, 0);
         flag_label = new Gtk.Label ("");
-        box.pack_start (flag_label);
-        hint_button.add (box);
-        hint_button.valign = Gtk.Align.CENTER;
-        hint_button.halign = Gtk.Align.CENTER;
-        hint_button.relief = Gtk.ReliefStyle.NONE;
-        hint_button.action_name = "app.hint";
-        hint_button.tooltip_text = _("Receive a hint for your next move");
-        buttons_box.pack_start (hint_button, false, false, 0);
-        size.add_widget (hint_button);
-        hint_button.show_all ();
+        box.pack_start (flag_label, false, false, 0);
+        buttons_box.pack_start (box, false, false, 0);
+        size.add_widget (box);
+        box.show_all ();
 
         clock_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 2);
         var clock_image = new Gtk.Image.from_icon_name ("preferences-system-time-symbolic", 
Gtk.IconSize.DND);
@@ -530,7 +519,6 @@ public class Mines : Gtk.Application
 
         new_game_action.set_enabled (false);
         repeat_size_action.set_enabled (false);
-        hint_action.set_enabled (false);
         pause_action.set_enabled (false);
         buttons_box.hide ();
     }
@@ -593,17 +581,11 @@ public class Mines : Gtk.Application
         new_game_action.set_enabled (true);
         repeat_size_action.set_enabled (true);
         pause_action.set_enabled (true);
-        hint_action.set_enabled (true);
 
         minefield.paused = false;
         pause_requested = false;
     }
 
-    private void hint_cb ()
-    {
-        minefield.hint ();
-    }
-
     private void new_game_cb ()
     {
         if (can_start_new_game ())
@@ -632,15 +614,9 @@ public class Mines : Gtk.Application
     private void paused_changed_cb ()
     {
         if (minefield.paused)
-        {
-            hint_action.set_enabled (false);
             display_unpause_button ();
-        }
         else if (minefield.elapsed > 0)
-        {
-            hint_action.set_enabled (true);
             display_pause_button ();
-        }
     }
 
     private void marks_changed_cb (Minefield minefield)
@@ -653,7 +629,6 @@ public class Mines : Gtk.Application
         new_game_button.show ();
         replay_button.show ();
         high_scores_button.show ();
-        hint_action.set_enabled (false);
         pause_action.set_enabled (false);
         play_pause_button.hide ();
     }
@@ -673,7 +648,6 @@ public class Mines : Gtk.Application
             new_game_button.show ();
             replay_button.show ();
             high_scores_button.show ();
-            hint_action.set_enabled (false);
             pause_action.set_enabled (false);
             play_pause_button.hide ();
         }
diff --git a/src/minefield.vala b/src/minefield.vala
index edf5396..1fb0fbb 100644
--- a/src/minefield.vala
+++ b/src/minefield.vala
@@ -89,11 +89,6 @@ public class Minefield
     private Timer? clock;
     private uint clock_timeout;
 
-    /* Time penalty for a hint increases the more you use it */
-    private static const uint HINT_TIME_PENALTY_MAX = 90;
-    private static const uint HINT_TIME_PENALTY_INCREASE = 10;
-    private uint hint_time_penalty_seconds = 10;
-
     public double elapsed
     {
         get
@@ -265,78 +260,6 @@ public class Minefield
         return locations[x, y].flag;
     }
 
-    public void hint ()
-    {
-        /* We search for three cases:
-         *
-         * Case 1: we look for squares adjacent to both a mine and a revealed
-         * square since these are most likely to help the player and resolve
-         * ambiguous situations.
-         *
-         * Case 2: we look for squares that are adjacent to a mine
-         * (this will only occur in the rare case that a square is completely
-         * encircled by mines, but at that point this case is probably
-         * useful).
-         *
-         * Case 3: we look for any unrevealed square without a mine (as a
-         * consequence of the previous cases this won't be adjacent to a
-         * mine).
-         */
-
-        List<uint> case1list = null;
-        List<uint> case2list = null;
-        List<uint> case3list = null;
-
-        for (var mx = 0; mx < width; mx++)
-        {
-            for (var my = 0; my < height; my++)
-            {
-                var m = locations[mx, my];
-                if (!m.has_mine && !m.cleared)
-                {
-                    case3list.append (mx * width + my);
-                    if (m.flag != FlagType.FLAG && get_n_adjacent_mines (mx, my) > 0)
-                    {
-                        case2list.append (mx * width + my);
-                        foreach (var neighbour in neighbour_map)
-                        {
-                            if (!is_location (mx + neighbour.x, my + neighbour.y))
-                                 continue;
-                            if (locations[mx + neighbour.x, my + neighbour.y].cleared)
-                            {
-                                case1list.append (mx * width + my);
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        uint hint_location = 0;
-        if (case1list.length () > 0)
-            hint_location = case1list.nth_data (Random.int_range (0, (int32) case1list.length ()));
-        else if (case2list.length () > 0)
-            hint_location = case2list.nth_data (Random.int_range (0, (int32) case2list.length ()));
-        else if (case3list.length () > 0)
-            hint_location = case3list.nth_data (Random.int_range (0, (int32) case3list.length ()));
-
-        /* Makes sure that the program knows about the successful
-         * hint before a possible win. */
-        var x = hint_location / width;
-        var y = hint_location % width;
-
-        if (locations[x, y].flag == FlagType.FLAG)
-            locations[x, y].flag = FlagType.NONE;
-
-        /* There is a ten second penalty for accepting a hint_action. */
-        clear_mine (x, y);
-        clock_elapsed += hint_time_penalty_seconds;
-        if (hint_time_penalty_seconds < HINT_TIME_PENALTY_MAX)
-            hint_time_penalty_seconds += HINT_TIME_PENALTY_INCREASE;
-        tick ();
-    }
-
     public uint get_n_adjacent_mines (uint x, uint y)
     {
         uint n = 0;


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