[gbrainy] Random verbal analogies better
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Random verbal analogies better
- Date: Fri, 30 Oct 2009 19:04:30 +0000 (UTC)
commit 2564e99b4e462055ff4a05c8893f9429b6dd422c
Author: Jordi Mas <jmas softcatala org>
Date: Fri Oct 30 20:04:53 2009 +0100
Random verbal analogies better
src/GameManager.cs | 50 +++++++++++++++++++++++++++++++++++++-
src/VerbalAnalogies/Analogies.cs | 5 ++++
2 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/src/GameManager.cs b/src/GameManager.cs
index 33bf8d6..2653635 100644
--- a/src/GameManager.cs
+++ b/src/GameManager.cs
@@ -30,6 +30,43 @@ using Mono.Addins.Setup;
public class GameManager
{
+ // Serves analogies as their container class is still not exhausted
+ // This is used to make sure that the analogies are not repeated within a game session
+ public class AnalogiesManager
+ {
+ List <Analogies> analogies;
+
+ public AnalogiesManager (Type [] types)
+ {
+ analogies = new List <Analogies> ();
+
+ foreach (Type type in types)
+ {
+ Analogies analogy;
+
+ analogy = (Analogies) Activator.CreateInstance (type, true);
+ analogies.Add (analogy);
+ }
+ }
+
+ public void Initialize ()
+ {
+ foreach (Analogies analogy in analogies)
+ analogy.CurrentIndex = 0;
+ }
+
+ public bool IsExhausted {
+ get {
+ foreach (Analogies analogy in analogies)
+ {
+ if (analogy.IsExhausted == false)
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+
static Type[] LogicPuzzlesInternal = new Type[]
{
typeof (PuzzleMatrixNumbers),
@@ -121,6 +158,7 @@ public class GameManager
List <Type> CalculationTrainers;
List <Type> MemoryTrainers;
List <Type> VerbalAnalogies;
+ AnalogiesManager analogies_manager;
public GameManager ()
{
@@ -139,6 +177,8 @@ public class GameManager
LogicPuzzles.Count + CalculationTrainers.Count + MemoryTrainers.Count + VerbalAnalogies.Count,
LogicPuzzles.Count, CalculationTrainers.Count, MemoryTrainers.Count, VerbalAnalogies.Count);
}
+
+ analogies_manager = new AnalogiesManager (VerbalAnalogiesInternal);
//GeneratePDF ();
}
@@ -242,9 +282,10 @@ public class GameManager
#endif
}
-
void BuildGameList ()
{
+ analogies_manager.Initialize ();
+
if (GameType == GameSession.Types.Custom)
return;
@@ -352,6 +393,9 @@ public class GameManager
if (enumerator.MoveNext () == false) { // All the games have been played, restart again
Initialize ();
enumerator.MoveNext ();
+
+ if (analogies_manager.IsExhausted == true)
+ analogies_manager.Initialize ();
}
puzzle = (Game) Activator.CreateInstance ((Type) games [(int) enumerator.Current], true);
@@ -361,6 +405,10 @@ public class GameManager
if (puzzle.IsPlayable == false)
continue;
+
+ Analogies analogy = puzzle as Analogies;
+ if (analogy != null && analogy.IsExhausted == true)
+ continue;
if (first == null)
first = puzzle;
diff --git a/src/VerbalAnalogies/Analogies.cs b/src/VerbalAnalogies/Analogies.cs
index 647e676..4b38cba 100644
--- a/src/VerbalAnalogies/Analogies.cs
+++ b/src/VerbalAnalogies/Analogies.cs
@@ -99,6 +99,11 @@ public abstract class Analogies : Game
set;
}
+ // Returns true when this game manager has no more games to server
+ public bool IsExhausted {
+ get { return CurrentIndex + 1 >= List.Count;}
+ }
+
public abstract Dictionary <int, Analogy> List {
get;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]