[four-in-a-row] Add --level command-line support.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row] Add --level command-line support.
- Date: Fri, 27 Dec 2019 16:10:47 +0000 (UTC)
commit 3fedbd5d94b2e2eb878e9e3603e026394657ba6b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Dec 26 22:56:29 2019 +0100
Add --level command-line support.
src/four-in-a-row.vala | 41 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index f90e0d6..5db1c40 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -89,10 +89,17 @@ private class FourInARow : Gtk.Application
[CCode (notify = false)] internal bool sound_on { private get; internal set; }
private uint8 theme_id;
+ private static string? level = null;
private static bool? sound = null;
private const OptionEntry [] option_entries =
{
+ /* Translators: command-line option description, see 'four-in-a-row --help' */
+ { "level", 'l', OptionFlags.NONE, OptionArg.STRING, ref level, N_("Set the level of the
computer’s AI"),
+
+ /* Translators: in the command-line options description, text to indicate the user should specify a
level, see 'four-in-a-row --help' */
+ N_("LEVEL") },
+
/* Translators: command-line option description, see 'four-in-a-row --help' */
{ "mute", 0, OptionFlags.NONE, OptionArg.NONE, null, N_("Turn off the sound"),
null },
@@ -162,8 +169,38 @@ private class FourInARow : Gtk.Application
{
base.startup ();
- if (sound != null)
- settings.set_boolean ("sound", (!) sound);
+ if ((sound != null) || (level != null))
+ {
+ settings.delay ();
+
+ if (sound != null)
+ settings.set_boolean ("sound", (!) sound);
+
+ if (level != null)
+ {
+ // TODO add a localized text option?
+ switch ((!) level)
+ {
+ case "1":
+ case "easy":
+ case "one": settings.set_int ("opponent", 1); break;
+
+ case "2":
+ case "medium":
+ case "two": settings.set_int ("opponent", 2); break;
+
+ case "3":
+ case "hard":
+ case "three": settings.set_int ("opponent", 3); break;
+
+ default:
+ /* Translators: command-line error message, displayed for an incorrect level
request; try 'four-in-a-row -l 5' */
+ stderr.printf ("%s\n", _("Level should be 1 (easy), 2 (medium) or 3 (hard). Settings
unchanged."));
+ break;
+ }
+ }
+ settings.apply ();
+ }
if (settings.get_boolean ("sound"))
init_sound ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]