[gbrainy] Game types that can be played are the ones that are availble for the game engine. Better usability.
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Game types that can be played are the ones that are availble for the game engine. Better usability.
- Date: Fri, 19 Feb 2010 21:13:53 +0000 (UTC)
commit 3dfe8509408db7690a915932caa44bfb9bceb44d
Author: Jordi Mas <jmas softcatala org>
Date: Fri Feb 19 22:14:27 2010 +0100
Game types that can be played are the ones that are availble for the game engine. Better usability.
src/Clients/Classical/gbrainy.cs | 36 ++++++++++++++++++-
src/Clients/Classical/gbrainy.ui | 38 ++++++++------------
src/Core/Main/GameManager.cs | 56 ++++++++++++++++++++++++++----
src/Core/Main/GameSession.cs | 4 ++
src/Core/Main/Verbal/AnalogiesFactory.cs | 23 ------------
5 files changed, 102 insertions(+), 55 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 1738e45..445e39e 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -54,6 +54,11 @@ namespace gbrainy.Clients.Classical
[GtkBeans.Builder.Object] Gtk.Action pause_menuitem;
[GtkBeans.Builder.Object] Gtk.Action finish_menuitem;
[GtkBeans.Builder.Object] Gtk.Action newgame_menuitem;
+ [GtkBeans.Builder.Object] Gtk.Action allgames_menuitem;
+ [GtkBeans.Builder.Object] Gtk.Action logic_menuitem;
+ [GtkBeans.Builder.Object] Gtk.Action verbal_menuitem;
+ [GtkBeans.Builder.Object] Gtk.Action memory_menuitem;
+ [GtkBeans.Builder.Object] Gtk.Action calculation_menuitem;
[GtkBeans.Builder.Object] Gtk.UIManager uimanager;
DrawingArea drawing_area;
GameSession session;
@@ -338,11 +343,38 @@ namespace gbrainy.Clients.Classical
{
//Toolbar buttons and menu items that are sensitive when the user is playing
bool playing;
+ Game.Types available;
playing = (session.Status == GameSession.SessionStatus.Playing);
-
finish_tbbutton.Sensitive = pause_tbbutton.Sensitive = playing;
- all_tbbutton.Sensitive = calculation_tbbutton.Sensitive = memory_tbbutton.Sensitive = logic_tbbutton.Sensitive = verbal_tbbutton.Sensitive = !playing;
+
+ available = session.AvailableGames;
+
+ if (playing == false && ((available & Game.Types.LogicPuzzle) == Game.Types.LogicPuzzle))
+ logic_menuitem.Sensitive = logic_tbbutton.Sensitive = true;
+ else
+ logic_menuitem.Sensitive = logic_tbbutton.Sensitive = false;
+
+ if (playing == false && ((available & Game.Types.MemoryTrainer) == Game.Types.MemoryTrainer))
+ memory_menuitem.Sensitive = memory_tbbutton.Sensitive = true;
+ else
+ memory_menuitem.Sensitive = memory_tbbutton.Sensitive = false;
+
+ if (playing == false && ((available & Game.Types.MathTrainer) == Game.Types.MathTrainer))
+ calculation_menuitem.Sensitive = calculation_tbbutton.Sensitive = true;
+ else
+ calculation_menuitem.Sensitive = calculation_tbbutton.Sensitive = false;
+
+ if (playing == false && ((available & Game.Types.VerbalAnalogy) == Game.Types.VerbalAnalogy))
+ verbal_menuitem.Sensitive = verbal_tbbutton.Sensitive = true;
+ else
+ verbal_menuitem.Sensitive = verbal_tbbutton.Sensitive = false;
+
+ if (playing == false && (available != Game.Types.None))
+ allgames_menuitem.Sensitive = all_tbbutton.Sensitive = true;
+ else
+ allgames_menuitem.Sensitive = all_tbbutton.Sensitive = false;
+
pause_menuitem.Sensitive = finish_menuitem.Sensitive = playing;
newgame_menuitem.Sensitive = !playing;
}
diff --git a/src/Clients/Classical/gbrainy.ui b/src/Clients/Classical/gbrainy.ui
index e85db9b..3b42b73 100644
--- a/src/Clients/Classical/gbrainy.ui
+++ b/src/Clients/Classical/gbrainy.ui
@@ -40,43 +40,36 @@
</object>
</child>
<child>
- <object class="GtkAction" id="menuitem3">
- <property name="name">menuitem3</property>
+ <object class="GtkAction" id="allgames_menuitem">
+ <property name="name">allgames_menuitem</property>
<property name="label" translatable="yes">All Games (Logic, Mental Calculation, Memory and Verbal Analogies)</property>
<signal handler="OnAllGames" name="activate"/>
</object>
</child>
<child>
- <object class="GtkAction" id="menuitem4">
- <property name="name">menuitem4</property>
- <property name="label" translatable="yes">Trainers Only (Mental Calculation and Memory)</property>
- <signal handler="OnTrainersOnly" name="activate"/>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="menuitem5">
- <property name="name">menuitem5</property>
+ <object class="GtkAction" id="logic_menuitem">
+ <property name="name">logic_menuitem</property>
<property name="label" translatable="yes">Logic Puzzles Only</property>
<signal handler="OnLogicOnly" name="activate"/>
</object>
</child>
<child>
- <object class="GtkAction" id="menuitem6">
- <property name="name">menuitem6</property>
+ <object class="GtkAction" id="calculation_menuitem">
+ <property name="name">calculation_menuitem</property>
<property name="label" translatable="yes">Mental Calculation Trainers Only</property>
<signal handler="OnMathOnly" name="activate"/>
</object>
</child>
<child>
- <object class="GtkAction" id="menuitem7">
- <property name="name">menuitem7</property>
+ <object class="GtkAction" id="memory_menuitem">
+ <property name="name">memory_menuitem</property>
<property name="label" translatable="yes">Memory Trainers Only</property>
<signal handler="OnMemoryOnly" name="activate"/>
</object>
</child>
<child>
- <object class="GtkAction" id="menuitem8">
- <property name="name">menuitem8</property>
+ <object class="GtkAction" id="verbal_menuitem">
+ <property name="name">verbal_menuitem</property>
<property name="label" translatable="yes">Verbal Analogies Only</property>
<signal handler="OnVerbalOnly" name="activate"/>
</object>
@@ -193,12 +186,11 @@
<menubar name="menubar">
<menu action="game_topmenu">
<menu action="newgame_menuitem">
- <menuitem action="menuitem3"/>
- <menuitem action="menuitem4"/>
- <menuitem action="menuitem5"/>
- <menuitem action="menuitem6"/>
- <menuitem action="menuitem7"/>
- <menuitem action="menuitem8"/>
+ <menuitem action="allgames_menuitem"/>
+ <menuitem action="logic_menuitem"/>
+ <menuitem action="calculation_menuitem"/>
+ <menuitem action="memory_menuitem"/>
+ <menuitem action="verbal_menuitem"/>
<menuitem action="custom_game"/>
</menu>
<menuitem action="pause_menuitem"/>
diff --git a/src/Core/Main/GameManager.cs b/src/Core/Main/GameManager.cs
index d4497f5..5cf3455 100644
--- a/src/Core/Main/GameManager.cs
+++ b/src/Core/Main/GameManager.cs
@@ -60,6 +60,20 @@ namespace gbrainy.Core.Main
analogy.CurrentIndex = 0;
}
+ public Type [] AvailableTypes {
+ get {
+ List <Type> types = new List <Type> ();
+
+ foreach (Analogies analogy in analogies)
+ {
+ if (analogy.List.Count > 0)
+ types.Add (analogy.GetType ());
+ }
+
+ return types.ToArray ();
+ }
+ }
+
public bool IsExhausted {
get {
foreach (Analogies analogy in analogies)
@@ -97,7 +111,11 @@ namespace gbrainy.Core.Main
game_type = GameSession.Types.None;
difficulty = Game.Difficulty.Medium;
games = new List <Type> ();
- VerbalAnalogies = new List <Type> (VerbalAnalogiesInternal);
+ VerbalAnalogies = new List <Type> ();
+ analogies_manager = new AnalogiesManager (VerbalAnalogiesInternal);
+
+ foreach (Type type in analogies_manager.AvailableTypes)
+ VerbalAnalogies.Add (type);
LoadAssemblyGame ();
@@ -119,9 +137,28 @@ namespace gbrainy.Core.Main
LogicPuzzles.Count, CalculationTrainers.Count, MemoryTrainers.Count, VerbalAnalogies.Count);
}
- analogies_manager = new AnalogiesManager (VerbalAnalogiesInternal);
//GeneratePDF ();
}
+
+ public Game.Types AvailableGames {
+ get {
+ Game.Types types = Game.Types.None;
+
+ if (LogicPuzzles.Count > 0)
+ types |= Game.Types.LogicPuzzle;
+
+ if (CalculationTrainers.Count > 0)
+ types |= Game.Types.MathTrainer;
+
+ if (MemoryTrainers.Count > 0)
+ types |= Game.Types.MemoryTrainer;
+
+ if (analogies_manager.AvailableTypes.Length > 0)
+ types |= Game.Types.VerbalAnalogy;
+
+ return types;
+ }
+ }
public GameSession.Types GameType {
get {return game_type; }
@@ -208,13 +245,16 @@ namespace gbrainy.Core.Main
obj = Activator.CreateInstance (type);
prop = type.GetProperty (LOGIC_METHOD);
- LogicPuzzles = new List <Type> ((Type []) prop.GetValue (obj, null));
+ if (prop != null)
+ LogicPuzzles = new List <Type> ((Type []) prop.GetValue (obj, null));
prop = type.GetProperty (MEMORY_METHOD);
- MemoryTrainers = new List <Type> ((Type []) prop.GetValue (obj, null));
+ if (prop != null)
+ MemoryTrainers = new List <Type> ((Type []) prop.GetValue (obj, null));
prop = type.GetProperty (CALCULATION_METHOD);
- CalculationTrainers = new List <Type> ((Type []) prop.GetValue (obj, null));
+ if (prop != null)
+ CalculationTrainers = new List <Type> ((Type []) prop.GetValue (obj, null));
}
catch (Exception e)
@@ -278,12 +318,14 @@ namespace gbrainy.Core.Main
if (GameType == GameSession.Types.Custom)
return;
-
+
games.Clear ();
Random random = new Random ();
// For all games, 1/4 of the total are logic, 1/4 Memory, 1/4 calculation, 1/4 verbal analogies
- if ((game_type & GameSession.Types.AllGames) == GameSession.Types.AllGames) {
+ if (((game_type & GameSession.Types.AllGames) == GameSession.Types.AllGames) &&
+ LogicPuzzles.Count > 0 && MemoryTrainers.Count > 0 &&
+ CalculationTrainers.Count > 0 && VerbalAnalogies.Count > 0) {
int idx_cal = 0, idx_mem = 0, idx_verb = 0;
ArrayListIndicesRandom idx_logic = new ArrayListIndicesRandom (LogicPuzzles.Count);
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 42601d5..aa8402a 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -112,6 +112,10 @@ namespace gbrainy.Core.Main
get {return id;}
}
+ public Game.Types AvailableGames {
+ get { return game_manager.AvailableGames; }
+ }
+
public PlayerHistory PlayerHistory {
set { history = value; }
get { return history; }
diff --git a/src/Core/Main/Verbal/AnalogiesFactory.cs b/src/Core/Main/Verbal/AnalogiesFactory.cs
index bdd9d1f..98f1f7e 100644
--- a/src/Core/Main/Verbal/AnalogiesFactory.cs
+++ b/src/Core/Main/Verbal/AnalogiesFactory.cs
@@ -152,29 +152,6 @@ namespace gbrainy.Core.Main.Verbal
{
Console.WriteLine ("Error loading {0}. Exception {1}", Defines.DATA_DIR + Defines.VERBAL_ANALOGIES, e.Message);
}
-
- finally
- {
- CheckEmpty ();
- }
- }
-
- static void CheckEmpty ()
- {
- Analogy empty = new Analogy ();
- empty.question = Catalog.GetString ("There are no verbal analogies available.");
- bool all_empty = true;
-
- for (int i = 0; i < (int) Analogy.Type.Last; i++)
- {
- if (analogies_arrays[i].Count > 0) {
- all_empty = false;
- break;
- }
- }
-
- if (all_empty == true)
- analogies_arrays[0].Add (0, empty);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]