gbrainy r166 - trunk/src



Author: jmas
Date: Sun Jan  6 21:52:28 2008
New Revision: 166
URL: http://svn.gnome.org/viewvc/gbrainy?rev=166&view=rev

Log:
2008-01-06 Jordi Mas <jmas softcatala org>

	* PuzzleSquareDots.cs: Random right answer



Modified:
   trunk/src/ChangeLog
   trunk/src/PuzzleSquareDots.cs

Modified: trunk/src/ChangeLog
==============================================================================
--- trunk/src/ChangeLog	(original)
+++ trunk/src/ChangeLog	Sun Jan  6 21:52:28 2008
@@ -1,3 +1,7 @@
+2008-01-06 Jordi Mas <jmas softcatala org>
+
+	* PuzzleSquareDots.cs: Random right answer
+
 2008-01-05 Jordi Mas <jmas softcatala org>
 
 	* gbrainy.glade: More clear text

Modified: trunk/src/PuzzleSquareDots.cs
==============================================================================
--- trunk/src/PuzzleSquareDots.cs	(original)
+++ trunk/src/PuzzleSquareDots.cs	Sun Jan  6 21:52:28 2008
@@ -29,6 +29,8 @@
 	private const int figures = 6;
 	private static bool X = true;
 	private static bool O = false;
+	private const double space_figures = 0.05;
+	private ArrayListIndicesRandom possible_answers;
 
 	private bool [] puzzle_A  = new bool []
 	{
@@ -74,12 +76,11 @@
 
 		// Wrong answer 2
 		O, O, O, O, O, O,
-		O, O, X, O, O, O,
+		O, X, X, O, O, O,
+		O, O, O, O, O, O,
 		O, O, O, O, O, O,
-		X, O, O, O, O, O,
 		O, O, O, O, O, O,
 		O, X, X, O, O, O,
-
 	};
 
 	public override string Name {
@@ -92,7 +93,15 @@
 
 	public override void Initialize ()
 	{
-		right_answer = "B";
+		possible_answers = new ArrayListIndicesRandom (3);
+		possible_answers.Initialize ();
+
+		for (int i = 0; i < possible_answers.Count; i++) {
+			if ((int) possible_answers[i] == 0) {
+				right_answer += (char) (65 + (int) i);
+				break;
+			}
+		}
 	}
 
 	public void DrawFigure (Cairo.Context gr, double x, double y, bool [] puzzle, int index)
@@ -138,10 +147,25 @@
 			pos_y += square_size;
 		}
 	}
+
+	public void DrawPossibleAnswer (Cairo.Context gr, double x, double y, int figure)
+	{
+		switch (figure) {
+		case 0: // Good answer
+			DrawFigure (gr, x, y, puzzle_A, columns * lines * 4);
+			break;
+		case 1:
+			DrawFigure (gr, x, y, puzzle_A,  columns * lines * 3);
+			break;
+		case 2:
+			DrawFigure (gr, x, y, puzzle_A, columns * lines * 5);
+			break;
+		}
+	}
 	
 	public override void Draw (Cairo.Context gr, int area_width, int area_height)
 	{
-		double x = DrawAreaX, y = DrawAreaY, space_figures = 0.05;
+		double x = DrawAreaX, y = DrawAreaY;
 
 		gr.Scale (area_width, area_height);
 
@@ -156,24 +180,15 @@
 		gr.ShowText (Catalog.GetString ("Possible answers are:"));
 		gr.Stroke ();
 		y += 0.05;
-		
-		DrawFigure (gr, x, y, puzzle_A, columns * lines * 3);
-		gr.MoveTo (x, y + figure_size + 0.05);
-		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), "A"));
-		gr.Stroke ();
-
-		DrawFigure (gr, x + figure_size + space_figures, y, puzzle_A, columns * lines * 4);
-		gr.MoveTo (x + figure_size + space_figures, y + figure_size + 0.05);
-		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), "B"));
-		gr.Stroke ();
-
-		DrawFigure (gr, x + (figure_size + space_figures) * 2, y, puzzle_A, columns * lines * 5);
-		gr.MoveTo (x + (figure_size + space_figures) * 2, y + figure_size + 0.05);
-		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), "C"));
-		gr.Stroke ();
 
+		for (int i = 0; i < possible_answers.Count; i++) {
+			DrawPossibleAnswer (gr, x, y, (int) possible_answers[i]);
+			gr.MoveTo (x, y + figure_size + 0.05);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+			gr.Stroke ();
+			x+= figure_size + space_figures;
+		}
 	}
-
 }
 
 



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