[gbrainy] Use GetMultiOptionsPossibleAnswers for Xml games + move it to gameanswer class



commit e7f37d2c6de3142c21eb362dfa6634e7e36d79d5
Author: Jordi Mas <jmas softcatala org>
Date:   Sun May 8 16:15:12 2011 +0200

    Use GetMultiOptionsPossibleAnswers for Xml games + move it to gameanswer class

 src/Core/Main/GameAnswer.cs                        |   24 ++++++++++++++++++++
 src/Core/Main/Verbal/Analogies.cs                  |   23 -------------------
 src/Core/Main/Verbal/AnalogiesMultipleOptions.cs   |    2 +-
 .../Main/Verbal/AnalogiesPairOfWordsOptions.cs     |    2 +-
 src/Core/Main/Xml/GameXml.cs                       |   10 +------
 5 files changed, 28 insertions(+), 33 deletions(-)
---
diff --git a/src/Core/Main/GameAnswer.cs b/src/Core/Main/GameAnswer.cs
index 722e2fa..dacf19a 100644
--- a/src/Core/Main/GameAnswer.cs
+++ b/src/Core/Main/GameAnswer.cs
@@ -129,6 +129,30 @@ namespace gbrainy.Core.Main
 			}
 		}
 
+		// A string of for format "A, B or C
+		public string GetMultiOptionsPossibleAnswers (int num_answers)
+		{
+			switch (num_answers) {
+			case 0:
+			case 1:
+				throw new InvalidOperationException ("You need more than 1 answer to select from");
+			case 2:
+				// Translators. This is the list of valid answers, like A or B.
+				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0} or {1}"),
+					GetMultiOption (0), GetMultiOption (1));
+			case 3:
+				// Translators. This is the list of valid answers, like A, B or C.
+				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}, {1} or {2}"),
+					GetMultiOption (0), GetMultiOption (1), GetMultiOption (2));
+			case 4:
+				// Translators. This is the list of valid answers, like A, B, C or D.
+				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}, {1}, {2} or {3}"),
+					GetMultiOption (0), GetMultiOption (1), GetMultiOption (2), GetMultiOption (3));
+			default:
+				throw new InvalidOperationException ("Number of multiple options not supported");
+			}
+		}
+
 		public string GetFigureName (int answer)
 		{
 			return String.Format (ServiceLocator.Instance.GetService <ITranslations> ()
diff --git a/src/Core/Main/Verbal/Analogies.cs b/src/Core/Main/Verbal/Analogies.cs
index f9b12ea..7ea5994 100644
--- a/src/Core/Main/Verbal/Analogies.cs
+++ b/src/Core/Main/Verbal/Analogies.cs
@@ -66,29 +66,6 @@ namespace gbrainy.Core.Main.Verbal
 			}
 		}
 
-		protected string GetMultiOptionsPossibleAnswers ()
-		{
-			switch (Current.answers.Length) {
-			case 0:
-			case 1:
-				throw new InvalidOperationException ("You need more than 1 answer to select from");
-			case 2:
-				// Translators. This is the list of valid answers, like A or B.
-				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0} or {1}"),
-					Answer.GetMultiOption (0), Answer.GetMultiOption (1));
-			case 3:
-				// Translators. This is the list of valid answers, like A, B or C.
-				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}, {1} or {2}"),
-					Answer.GetMultiOption (0), Answer.GetMultiOption (1), Answer.GetMultiOption (2));
-			case 4:
-				// Translators. This is the list of valid answers, like A, B, C or D.
-				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}, {1}, {2} or {3}"),
-					Answer.GetMultiOption (0), Answer.GetMultiOption (1), Answer.GetMultiOption (2), Answer.GetMultiOption (3));
-			default:
-				throw new InvalidOperationException ("Number of multiple options not supported");
-			}
-		}
-
 		protected void SetAnswerCorrectShow ()
 		{
 			if (Current == null || 
diff --git a/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs b/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
index 14fa87b..915744d 100644
--- a/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
+++ b/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
@@ -54,7 +54,7 @@ namespace gbrainy.Core.Main.Verbal
 				// Translators: {0} is replaced by a question and {1} by the possible valid answers
 				// E.g.: What is the correct option? Answer A, B, C or D.
 				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0} Answer {1}."),
-					Current.question, GetMultiOptionsPossibleAnswers ());
+					Current.question, Answer.GetMultiOptionsPossibleAnswers (Current.answers.Length));
 			}
 		}
 
diff --git a/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs b/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
index 6ec331a..807fcab 100644
--- a/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
+++ b/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
@@ -59,7 +59,7 @@ namespace gbrainy.Core.Main.Verbal
 				// Translators: {0} is replaced by a question and {1} by the possible valid answers
 				// E.g.: What is the correct option? Answer A, B, C or D.
 				return String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0} Answer {1}."),
-					ques, GetMultiOptionsPossibleAnswers ());
+					ques, Answer.GetMultiOptionsPossibleAnswers (Current.answers.Length));
 			}
 		}
 
diff --git a/src/Core/Main/Xml/GameXml.cs b/src/Core/Main/Xml/GameXml.cs
index d038f32..f003cf9 100644
--- a/src/Core/Main/Xml/GameXml.cs
+++ b/src/Core/Main/Xml/GameXml.cs
@@ -205,8 +205,6 @@ namespace gbrainy.Core.Main.Xml
 
 			if (options != null && options.Count > 0)
 			{
-				string answers = string.Empty;
-
 				for (int i = 0; i < options.Count; i++)
 				{
 					OptionDrawingObject option = options [i];
@@ -216,14 +214,10 @@ namespace gbrainy.Core.Main.Xml
 						break;
 					}
 				}
-	
-				for (int i = 0; i < options.Count - 1; i++)
-					answers += String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}, "), Answer.GetMultiOption (i));
-
-				answers += String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}."), Answer.GetMultiOption (options.Count - 1));
 
 				// Translators {0}: list of options (A, B, C)
-				answers = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Answer {0}"), answers);
+				string answers = String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Answer {0}."), 
+					Answer.GetMultiOptionsPossibleAnswers (options.Count));
 				question = question.Replace (option_answers, answers);					
 			}
 			else



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