[iagno] Add --level command-line option.



commit f105c7596b850d1585ae65f221bd7a051eb63f76
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Jul 20 20:38:14 2014 +0200

    Add --level command-line option.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733415

 data/iagno.6   |   10 ++++++++--
 src/iagno.vala |   11 +++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/data/iagno.6 b/data/iagno.6
index 43d6133..200aa31 100644
--- a/data/iagno.6
+++ b/data/iagno.6
@@ -34,16 +34,22 @@ Play with reduced delay before the computer moves.
 .B \-h, \-\-help
 Prints the command line options and exits.
 .TP
-.B \-v, \-\-version
-Prints the program version and exits.
+.B \-l, \-\-level=<level>
+Changes the computer's AI level (1-3).
+.br
+1 is the easiest, 2 is good, 3 is the hardest.
 .PP
 .B \-\-mute
 .br
 .B \-\-unmute
 .RS 7
 Turn off/on the sound, when launched or during a play.
+.br
 If the two options are given, the game is muted.
 .RE
+.TP
+.B \-v, \-\-version
+Prints the program version and exits.
 .P
 This program also accepts the standard GTK+ options.
 .SH AUTHORS
diff --git a/src/iagno.vala b/src/iagno.vala
index 24efea4..31872b1 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -16,6 +16,7 @@ public class Iagno : Gtk.Application
     private bool is_fullscreen;
     private bool is_maximized;
     private static bool fast_mode;
+    private static int computer_level = 0;
 
     /* Widgets */
     private Gtk.Window window;
@@ -44,6 +45,7 @@ public class Iagno : Gtk.Application
     private static const OptionEntry[] option_entries =
     {
         { "fast-mode", 'f', 0, OptionArg.NONE, ref fast_mode, N_("Reduce delay before AI moves"), null},
+        { "level", 'l', 0, OptionArg.INT, ref computer_level, N_("Set the level of the computer's AI"), 
null},
         { "mute", 0, 0, OptionArg.NONE, null, N_("Turn off the sound"), null},
         { "unmute", 0, 0, OptionArg.NONE, null, N_("Turn on the sound"), null},
         { "version", 'v', 0, OptionArg.NONE, null, N_("Print release version and exit"), null},
@@ -194,6 +196,15 @@ public class Iagno : Gtk.Application
         if (options.contains ("mute"))
             settings.set_boolean ("sound", false);
 
+        /* The computer's AI level is set for the next game. */
+        if (computer_level > 0)
+        {
+            if (computer_level <= 3)
+                settings.set_int ("computer-level", computer_level);
+            else
+                stderr.printf ("%1$s\n", _("Level should be between 1 (easy) and 3 (hard). Settings 
unchanged."));
+        }
+
         /* Activate */
         return -1;
     }


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