[gbrainy] Separate GameTip & CountDown classes and some refactoring
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Separate GameTip & CountDown classes and some refactoring
- Date: Sun, 18 Oct 2009 07:49:53 +0000 (UTC)
commit 360f068f5952c4152c716b72174902fe17b7a6d1
Author: Jordi Mas <jmas softcatala org>
Date: Sun Oct 18 09:49:43 2009 +0200
Separate GameTip & CountDown classes and some refactoring
po/POTFILES.in | 10 +-
src/CountDown.cs | 93 ++++++++++++++
src/GameDrawingArea.cs | 107 ----------------
src/GameTips.cs | 60 +++++++++
src/Makefile.am | 2 +
src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs | 2 +-
src/gbrainy.cs | 128 ++++++++++----------
7 files changed, 228 insertions(+), 174 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b3ec66d..4fa4511 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,21 +1,25 @@
+data/verbal_analogies.xml
gbrainy.desktop.in
-src/Dialogs/AboutDialog.cs
src/CalculationGames/CalculationArithmetical.cs
src/CalculationGames/CalculationAverage.cs
src/CalculationGames/CalculationCloserFraction.cs
src/CalculationGames/CalculationFractions.cs
src/CalculationGames/CalculationGreatestDivisor.cs
src/CalculationGames/CalculationOperator.cs
+src/CalculationGames/CalculationPrimes.cs
src/CalculationGames/CalculationProportions.cs
src/CalculationGames/CalculationRatio.cs
-src/CalculationGames/CalculationPrimes.cs
src/CalculationGames/CalculationTwoNumbers.cs
src/ColorPalette.cs
+src/CountDown.cs
+src/Dialogs/AboutDialog.cs
src/Dialogs/CustomGameDialog.cs
+src/Dialogs/PlayerHistoryDialog.cs
src/Game.cs
src/GameDrawingArea.cs
src/GameManager.cs
src/GameSession.cs
+src/GameTips.cs
src/gbrainy.cs
src/gbrainy.glade
src/Memory.cs
@@ -29,7 +33,6 @@ src/MemoryGames/MemoryIndications.cs
src/MemoryGames/MemoryNumbers.cs
src/MemoryGames/MemoryWords.cs
src/mono-addins-strings.xml
-src/Dialogs/PlayerHistoryDialog.cs
src/PuzzleGames/PuzzleBalance.cs
src/PuzzleGames/PuzzleBuildTriangle.cs
src/PuzzleGames/PuzzleCirclesRectangle.cs
@@ -76,4 +79,3 @@ src/VerbalAnalogies/AnalogiesMultipleOptions.cs
src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs
src/VerbalAnalogies/AnalogiesQuestionAnswer.cs
-data/verbal_analogies.xml
diff --git a/src/CountDown.cs b/src/CountDown.cs
new file mode 100644
index 0000000..07ab39b
--- /dev/null
+++ b/src/CountDown.cs
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2007-2008 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+using System;
+using Cairo;
+using Mono.Unix;
+using Gtk;
+using System.Timers;
+
+public class CountDown
+{
+ static int countdown_time;
+ System.Timers.Timer timer;
+ EventHandler finish;
+ GameDrawingArea area;
+
+ public CountDown (GameDrawingArea area, EventHandler OnFinish)
+ {
+ countdown_time = 3;
+ timer = new System.Timers.Timer ();
+ timer.Elapsed += TimerUpdater;
+ timer.Interval = (1 * 1000); // 1 second
+ timer.Enabled = true;
+ finish = OnFinish;
+ this.area = area;
+ }
+
+ public void EndDrawCountDown ()
+ {
+ if (timer == null)
+ return;
+
+ timer.Enabled = false;
+ timer.Dispose ();
+ timer = null;
+ }
+
+ static public void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ gr.Scale (area_width, area_height);
+
+ gr.Color = new Cairo.Color (0.8, 0.8, 0.8);
+ gr.Paint ();
+
+ gr.LineWidth = 0.01;
+ gr.Color = new Cairo.Color (0, 0, 0, 1);
+
+ gr.SetPangoLargeFontSize ();
+ gr.DrawTextCentered (0.5, 0.1, Catalog.GetString ("Get ready to memorize the next objects..."));
+ gr.Stroke ();
+
+ gr.SetPangoFontSize (0.35);
+ gr.MoveTo (0.37, 0.22);
+ gr.ShowPangoText (countdown_time.ToString ());
+ gr.Stroke ();
+
+ gr.Arc (0.5, 0.5, 0.25, 0, 2 * Math.PI);
+ gr.Stroke ();
+ gr.Arc (0.5, 0.5, 0.28, 0, 2 * Math.PI);
+ gr.Stroke ();
+ }
+
+ void TimerUpdater (object source, ElapsedEventArgs e)
+ {
+ lock (this) {
+ if (countdown_time == 1) {
+ EndDrawCountDown ();
+ Application.Invoke ( delegate {
+ finish (this, EventArgs.Empty);
+ });
+ }
+ countdown_time--;
+ Application.Invoke ( delegate { area.QueueDraw (); });
+ }
+ }
+}
diff --git a/src/GameDrawingArea.cs b/src/GameDrawingArea.cs
index 34f1a79..96b8271 100644
--- a/src/GameDrawingArea.cs
+++ b/src/GameDrawingArea.cs
@@ -309,110 +309,3 @@ public class GameDrawingArea : DrawingArea
return base.OnExposeEvent(args);
}
}
-
-public class CountDown
-{
- static int countdown_time;
- System.Timers.Timer timer;
- EventHandler finish;
- GameDrawingArea area;
-
- public CountDown (GameDrawingArea area, EventHandler OnFinish)
- {
- countdown_time = 3;
- timer = new System.Timers.Timer ();
- timer.Elapsed += TimerUpdater;
- timer.Interval = (1 * 1000); // 1 second
- timer.Enabled = true;
- finish = OnFinish;
- this.area = area;
- }
-
- public void EndDrawCountDown ()
- {
- if (timer == null)
- return;
-
- timer.Enabled = false;
- timer.Dispose ();
- timer = null;
- }
-
- static public void Draw (CairoContextEx gr, int area_width, int area_height)
- {
- gr.Scale (area_width, area_height);
-
- gr.Color = new Cairo.Color (0.8, 0.8, 0.8);
- gr.Paint ();
-
- gr.LineWidth = 0.01;
- gr.Color = new Cairo.Color (0, 0, 0, 1);
-
- gr.SetPangoLargeFontSize ();
- gr.DrawTextCentered (0.5, 0.1, Catalog.GetString ("Get ready to memorize the next objects..."));
- gr.Stroke ();
-
- gr.SetPangoFontSize (0.35);
- gr.MoveTo (0.37, 0.22);
- gr.ShowPangoText (countdown_time.ToString ());
- gr.Stroke ();
-
- gr.Arc (0.5, 0.5, 0.25, 0, 2 * Math.PI);
- gr.Stroke ();
- gr.Arc (0.5, 0.5, 0.28, 0, 2 * Math.PI);
- gr.Stroke ();
- }
-
- void TimerUpdater (object source, ElapsedEventArgs e)
- {
- lock (this) {
- if (countdown_time == 1) {
- EndDrawCountDown ();
- Application.Invoke ( delegate {
- finish (this, EventArgs.Empty);
- });
- }
- countdown_time--;
- Application.Invoke ( delegate { area.QueueDraw (); });
- }
- }
-}
-
-
-class GameTips
-{
- static public int Count {
- get { return 11; }
- }
-
- static public String GetTip (int tip)
- {
- switch (tip) {
- case 0:
- return Catalog.GetString ("Read the instructions carefully and identify the data and given clues.");
- case 1:
- return Catalog.GetString ("To score the player gbrainy uses the time and tips needed to complete each game.");
- case 2:
- return Catalog.GetString ("In logic games, elements that may seem irrelevant can be very important.");
- case 3:
- return Catalog.GetString ("Break the mental blocks and look into the boundaries of problems.");
- case 4:
- return Catalog.GetString ("Enjoy making mistakes, they are part of the learning process.");
- case 5:
- return Catalog.GetString ("Do all the problems, even the difficult ones. Improvement comes from practising.");
- case 6:
- return Catalog.GetString ("Play on a daily basis, you will notice progress soon.");
- case 7: // Translators: Custom Game Selection is a menu option
- return Catalog.GetString ("Use the 'Custom Game Selection' to choose exactly which games you want to play.");
- case 8:
- return Catalog.GetString ("Use the Settings to adjust the difficulty level of the game.");
- case 9:
- return Catalog.GetString ("Association of elements is a common technique for remembering things.");
- case 10:
- return Catalog.GetString ("Grouping elements into categories is a common technique for remembering things.");
- }
-
- return string.Empty;
- }
-}
-
diff --git a/src/GameTips.cs b/src/GameTips.cs
new file mode 100644
index 0000000..625e9d2
--- /dev/null
+++ b/src/GameTips.cs
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007-2008 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+using System;
+using Mono.Unix;
+
+static class GameTips
+{
+ static public int Count {
+ get { return 11; }
+ }
+
+ static public String GetTip (int tip)
+ {
+ switch (tip) {
+ case 0:
+ return Catalog.GetString ("Read the instructions carefully and identify the data and given clues.");
+ case 1:
+ return Catalog.GetString ("To score the player gbrainy uses the time and tips needed to complete each game.");
+ case 2:
+ return Catalog.GetString ("In logic games, elements that may seem irrelevant can be very important.");
+ case 3:
+ return Catalog.GetString ("Break the mental blocks and look into the boundaries of problems.");
+ case 4:
+ return Catalog.GetString ("Enjoy making mistakes, they are part of the learning process.");
+ case 5:
+ return Catalog.GetString ("Do all the problems, even the difficult ones. Improvement comes from practising.");
+ case 6:
+ return Catalog.GetString ("Play on a daily basis, you will notice progress soon.");
+ case 7: // Translators: Custom Game Selection is a menu option
+ return Catalog.GetString ("Use the 'Custom Game Selection' to choose exactly which games you want to play.");
+ case 8:
+ return Catalog.GetString ("Use the Settings to adjust the difficulty level of the game.");
+ case 9:
+ return Catalog.GetString ("Association of elements is a common technique for remembering things.");
+ case 10:
+ return Catalog.GetString ("Grouping elements into categories is a common technique for remembering things.");
+ }
+
+ return string.Empty;
+ }
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
index fd08081..e6e1c8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,6 +87,8 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/PuzzleGames/PuzzlePercentage.cs \
$(srcdir)/SimpleLabel.cs \
$(srcdir)/Unix.cs \
+ $(srcdir)/GameTips.cs \
+ $(srcdir)/CountDown.cs \
$(srcdir)/gbrainy.cs
diff --git a/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs b/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
index e1d83f0..bba1bcc 100644
--- a/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
+++ b/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
@@ -93,7 +93,7 @@ public class AnalogiesPairOfWordsCompare : Analogies
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
- double x = DrawAreaX, y = DrawAreaY + 0.1;
+ double y = DrawAreaY + 0.1;
base.Draw (gr, area_width, area_height);
diff --git a/src/gbrainy.cs b/src/gbrainy.cs
index d7621c3..82514b2 100644
--- a/src/gbrainy.cs
+++ b/src/gbrainy.cs
@@ -72,66 +72,10 @@ public class gbrainy: Program
Catalog.Init ("gbrainy", Defines.GNOME_LOCALE_DIR);
Unix.FixLocaleInfo ();
- IconFactory icon_factory = new IconFactory ();
- AddIcon (icon_factory, "logic-games", "logic-games-32.png");
- AddIcon (icon_factory, "math-games", "math-games-32.png");
- AddIcon (icon_factory, "memory-games", "memory-games-32.png");
- AddIcon (icon_factory, "verbal-games", "verbal-games-32.png");
- AddIcon (icon_factory, "pause", "pause-32.png");
- AddIcon (icon_factory, "resume", "resume-32.png");
- AddIcon (icon_factory, "endgame", "endgame-32.png");
- AddIcon (icon_factory, "allgames", "allgames-32.png");
- icon_factory.AddDefault ();
-
Glade.XML gXML = new Glade.XML (null, "gbrainy.glade", "gbrainy", null);
gXML.Autoconnect (this);
- toolbar.IconSize = Gtk.IconSize.Dnd;
- toolbar.ShowArrow = false;
-
- Tooltips tooltips = new Tooltips ();
- all_tbbutton = new ToolButton ("allgames");
- all_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play all the games"), null);
- all_tbbutton.Label = Catalog.GetString ("All");
- all_tbbutton.Clicked += OnAllGames;
- toolbar.Insert (all_tbbutton, -1);
-
- logic_tbbutton = new ToolButton ("logic-games");
- logic_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your reasoning and thinking"), null);
- logic_tbbutton.Label = Catalog.GetString ("Logic");
- logic_tbbutton.Clicked += OnLogicOnly;
- toolbar.Insert (logic_tbbutton, -1);
-
- calculation_tbbutton = new ToolButton ("math-games");
- calculation_tbbutton.Label = Catalog.GetString ("Calculation");
- calculation_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your mental calculation skills"), null);
- calculation_tbbutton.Clicked += OnMathOnly;
- toolbar.Insert (calculation_tbbutton, -1);
-
- memory_tbbutton = new ToolButton ("memory-games");
- memory_tbbutton.Label = Catalog.GetString ("Memory");
- memory_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your short term memory"), null);
- memory_tbbutton.Clicked += OnMemoryOnly;
- toolbar.Insert (memory_tbbutton, -1);
-
- verbal_tbbutton = new ToolButton ("verbal-games");
- verbal_tbbutton.Label = Catalog.GetString ("Verbal");
- verbal_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your verbal aptitude"), null);
- verbal_tbbutton.Clicked += OnVerbalOnly;
- toolbar.Insert (verbal_tbbutton, -1);
-
- pause_tbbutton = new ToolButton ("pause");
- pause_tbbutton.Label = Catalog.GetString ("Pause");
- pause_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Pause or resume the game"), null);
- pause_tbbutton.Clicked += OnPauseGame;
- toolbar.Insert (pause_tbbutton, -1);
-
- finish_tbbutton = new ToolButton ("endgame");
- finish_tbbutton.SetTooltip (tooltips, Catalog.GetString ("End the game and show score"), null);
- finish_tbbutton.Label = Catalog.GetString ("Finish");
- finish_tbbutton.Clicked += OnEndGame;
- toolbar.Insert (finish_tbbutton, -1);
-
+ BuildToolBar ();
session = new GameSession (this);
if (history == null)
@@ -226,11 +170,6 @@ public class gbrainy: Program
question_label.Text = question;
}
- private void UpdateSolution (string solution)
- {
- solution_label.Text = solution;
- }
-
public void QueueDraw ()
{
drawing_area.QueueDraw ();
@@ -242,6 +181,71 @@ public class gbrainy: Program
solution_label.WidthMargin = margin;
}
+ void UpdateSolution (string solution)
+ {
+ solution_label.Text = solution;
+ }
+
+ void BuildToolBar ()
+ {
+ IconFactory icon_factory = new IconFactory ();
+ AddIcon (icon_factory, "logic-games", "logic-games-32.png");
+ AddIcon (icon_factory, "math-games", "math-games-32.png");
+ AddIcon (icon_factory, "memory-games", "memory-games-32.png");
+ AddIcon (icon_factory, "verbal-games", "verbal-games-32.png");
+ AddIcon (icon_factory, "pause", "pause-32.png");
+ AddIcon (icon_factory, "resume", "resume-32.png");
+ AddIcon (icon_factory, "endgame", "endgame-32.png");
+ AddIcon (icon_factory, "allgames", "allgames-32.png");
+ icon_factory.AddDefault ();
+
+ toolbar.IconSize = Gtk.IconSize.Dnd;
+ toolbar.ShowArrow = false;
+
+ Tooltips tooltips = new Tooltips ();
+ all_tbbutton = new ToolButton ("allgames");
+ all_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play all the games"), null);
+ all_tbbutton.Label = Catalog.GetString ("All");
+ all_tbbutton.Clicked += OnAllGames;
+ toolbar.Insert (all_tbbutton, -1);
+
+ logic_tbbutton = new ToolButton ("logic-games");
+ logic_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your reasoning and thinking"), null);
+ logic_tbbutton.Label = Catalog.GetString ("Logic");
+ logic_tbbutton.Clicked += OnLogicOnly;
+ toolbar.Insert (logic_tbbutton, -1);
+
+ calculation_tbbutton = new ToolButton ("math-games");
+ calculation_tbbutton.Label = Catalog.GetString ("Calculation");
+ calculation_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your mental calculation skills"), null);
+ calculation_tbbutton.Clicked += OnMathOnly;
+ toolbar.Insert (calculation_tbbutton, -1);
+
+ memory_tbbutton = new ToolButton ("memory-games");
+ memory_tbbutton.Label = Catalog.GetString ("Memory");
+ memory_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your short term memory"), null);
+ memory_tbbutton.Clicked += OnMemoryOnly;
+ toolbar.Insert (memory_tbbutton, -1);
+
+ verbal_tbbutton = new ToolButton ("verbal-games");
+ verbal_tbbutton.Label = Catalog.GetString ("Verbal");
+ verbal_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Play games that challenge your verbal aptitude"), null);
+ verbal_tbbutton.Clicked += OnVerbalOnly;
+ toolbar.Insert (verbal_tbbutton, -1);
+
+ pause_tbbutton = new ToolButton ("pause");
+ pause_tbbutton.Label = Catalog.GetString ("Pause");
+ pause_tbbutton.SetTooltip (tooltips, Catalog.GetString ("Pause or resume the game"), null);
+ pause_tbbutton.Clicked += OnPauseGame;
+ toolbar.Insert (pause_tbbutton, -1);
+
+ finish_tbbutton = new ToolButton ("endgame");
+ finish_tbbutton.SetTooltip (tooltips, Catalog.GetString ("End the game and show score"), null);
+ finish_tbbutton.Label = Catalog.GetString ("Finish");
+ finish_tbbutton.Clicked += OnEndGame;
+ toolbar.Insert (finish_tbbutton, -1);
+ }
+
void GameSensitiveUI ()
{
//Toolbar buttons and menu items that are sensitive when the user is playing
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]