gbrainy r391 - in trunk/src: . CalculationGames MemoryGames PuzzleGames



Author: jmas
Date: Mon Jul 21 16:37:04 2008
New Revision: 391
URL: http://svn.gnome.org/viewvc/gbrainy?rev=391&view=rev

Log:
2008-07-21 Jordi Mas <jmas softcatala org>

	* Moved the games classes into CalculationGames, MemoryGames and
	 PuzzleGames to organize better the directories.
	* Makefile.am: New location for source files



Added:
   trunk/src/CalculationGames/
   trunk/src/CalculationGames/CalculationArithmetical.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationArithmetical.cs
   trunk/src/CalculationGames/CalculationFractions.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationFractions.cs
   trunk/src/CalculationGames/CalculationGreatestDivisor.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationGreatestDivisor.cs
   trunk/src/CalculationGames/CalculationOperator.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationOperator.cs
   trunk/src/CalculationGames/CalculationTwoNumbers.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationTwoNumbers.cs
   trunk/src/CalculationGames/CalculationWhichNumber.cs   (props changed)
      - copied unchanged from r390, /trunk/src/CalculationWhichNumber.cs
   trunk/src/MemoryGames/
   trunk/src/MemoryGames/MemoryColouredFigures.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryColouredFigures.cs
   trunk/src/MemoryGames/MemoryColouredText.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryColouredText.cs
   trunk/src/MemoryGames/MemoryCountDots.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryCountDots.cs
   trunk/src/MemoryGames/MemoryFigures.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryFigures.cs
   trunk/src/MemoryGames/MemoryIndications.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryIndications.cs
   trunk/src/MemoryGames/MemoryNumbers.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryNumbers.cs
   trunk/src/MemoryGames/MemoryWords.cs   (props changed)
      - copied unchanged from r390, /trunk/src/MemoryWords.cs
   trunk/src/PuzzleGames/   (props changed)
   trunk/src/PuzzleGames/PuzzleBalance.cs
   trunk/src/PuzzleGames/PuzzleBuildTriangle.cs
   trunk/src/PuzzleGames/PuzzleCirclesRectangle.cs
   trunk/src/PuzzleGames/PuzzleClocks.cs
   trunk/src/PuzzleGames/PuzzleCountCircles.cs
   trunk/src/PuzzleGames/PuzzleCountSeries.cs
   trunk/src/PuzzleGames/PuzzleCoverPercentage.cs
   trunk/src/PuzzleGames/PuzzleCube.cs
   trunk/src/PuzzleGames/PuzzleDivideCircle.cs
   trunk/src/PuzzleGames/PuzzleEquation.cs
   trunk/src/PuzzleGames/PuzzleExtraCircle.cs
   trunk/src/PuzzleGames/PuzzleFigureLetter.cs
   trunk/src/PuzzleGames/PuzzleFigurePattern.cs
   trunk/src/PuzzleGames/PuzzleFigures.cs
   trunk/src/PuzzleGames/PuzzleFourSided.cs
   trunk/src/PuzzleGames/PuzzleLines.cs
   trunk/src/PuzzleGames/PuzzleMatrixGroups.cs
   trunk/src/PuzzleGames/PuzzleMatrixNumbers.cs
   trunk/src/PuzzleGames/PuzzleMissingPiece.cs
   trunk/src/PuzzleGames/PuzzleMissingSlice.cs
   trunk/src/PuzzleGames/PuzzleMostInCommon.cs
   trunk/src/PuzzleGames/PuzzleMoveFigure.cs
   trunk/src/PuzzleGames/PuzzleNextFigure.cs
   trunk/src/PuzzleGames/PuzzleNumericRelation.cs
   trunk/src/PuzzleGames/PuzzleNumericSequence.cs
   trunk/src/PuzzleGames/PuzzleOstracism.cs
   trunk/src/PuzzleGames/PuzzlePencil.cs
   trunk/src/PuzzleGames/PuzzlePeopleTable.cs
   trunk/src/PuzzleGames/PuzzleQuadrilaterals.cs
   trunk/src/PuzzleGames/PuzzleSquareDots.cs
   trunk/src/PuzzleGames/PuzzleSquareSheets.cs
   trunk/src/PuzzleGames/PuzzleSquares.cs
   trunk/src/PuzzleGames/PuzzleSquaresAndLetters.cs
   trunk/src/PuzzleGames/PuzzleTetris.cs
   trunk/src/PuzzleGames/PuzzleTriangles.cs
   trunk/src/PuzzleGames/PuzzleTrianglesWithNumbers.cs
Removed:
   trunk/src/CalculationArithmetical.cs
   trunk/src/CalculationFractions.cs
   trunk/src/CalculationGreatestDivisor.cs
   trunk/src/CalculationOperator.cs
   trunk/src/CalculationTwoNumbers.cs
   trunk/src/CalculationWhichNumber.cs
   trunk/src/MemoryColouredFigures.cs
   trunk/src/MemoryColouredText.cs
   trunk/src/MemoryCountDots.cs
   trunk/src/MemoryFigures.cs
   trunk/src/MemoryIndications.cs
   trunk/src/MemoryNumbers.cs
   trunk/src/MemoryWords.cs
   trunk/src/PuzzleBalance.cs
   trunk/src/PuzzleBuildTriangle.cs
   trunk/src/PuzzleCirclesRectangle.cs
   trunk/src/PuzzleClocks.cs
   trunk/src/PuzzleCountCircles.cs
   trunk/src/PuzzleCountSeries.cs
   trunk/src/PuzzleCoverPercentage.cs
   trunk/src/PuzzleCube.cs
   trunk/src/PuzzleDivideCircle.cs
   trunk/src/PuzzleEquation.cs
   trunk/src/PuzzleExtraCircle.cs
   trunk/src/PuzzleFigureLetter.cs
   trunk/src/PuzzleFigurePattern.cs
   trunk/src/PuzzleFigures.cs
   trunk/src/PuzzleFourSided.cs
   trunk/src/PuzzleLines.cs
   trunk/src/PuzzleMatrixGroups.cs
   trunk/src/PuzzleMatrixNumbers.cs
   trunk/src/PuzzleMissingPiece.cs
   trunk/src/PuzzleMissingSlice.cs
   trunk/src/PuzzleMostInCommon.cs
   trunk/src/PuzzleMoveFigure.cs
   trunk/src/PuzzleNextFigure.cs
   trunk/src/PuzzleNumericRelation.cs
   trunk/src/PuzzleNumericSequence.cs
   trunk/src/PuzzleOstracism.cs
   trunk/src/PuzzlePencil.cs
   trunk/src/PuzzlePeopleTable.cs
   trunk/src/PuzzleQuadrilaterals.cs
   trunk/src/PuzzleSquareDots.cs
   trunk/src/PuzzleSquareSheets.cs
   trunk/src/PuzzleSquares.cs
   trunk/src/PuzzleSquaresAndLetters.cs
   trunk/src/PuzzleTetris.cs
   trunk/src/PuzzleTriangles.cs
   trunk/src/PuzzleTrianglesWithNumbers.cs
Modified:
   trunk/src/ChangeLog
   trunk/src/Makefile.am

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Jul 21 16:37:04 2008
@@ -5,67 +5,67 @@
 GBRAINY_CSDISTFILES =				\
 	$(srcdir)/ArrayListIndicesRandom.cs	\
 	$(srcdir)/GameManager.cs		\
-	$(srcdir)/PuzzleCirclesRectangle.cs	\
+	$(srcdir)/PuzzleGames/PuzzleCirclesRectangle.cs	\
 	$(srcdir)/Game.cs			\
-	$(srcdir)/PuzzleFigures.cs		\
-	$(srcdir)/PuzzleMatrixNumbers.cs	\
-	$(srcdir)/PuzzleMoveFigure.cs		\
-	$(srcdir)/PuzzlePencil.cs		\
-	$(srcdir)/PuzzleSquares.cs		\
-	$(srcdir)/PuzzleTriangles.cs		\
-	$(srcdir)/PuzzleCoverPercentage.cs	\
-	$(srcdir)/PuzzleNumericSequence.cs	\
-	$(srcdir)/PuzzleSquaresAndLetters.cs	\
-	$(srcdir)/PuzzleSquareDots.cs		\
-	$(srcdir)/PuzzleNumericRelation.cs	\
-	$(srcdir)/PuzzleNextFigure.cs		\
-	$(srcdir)/PuzzleSquareSheets.cs		\
-	$(srcdir)/CalculationArithmetical.cs	\
-	$(srcdir)/MemoryColouredFigures.cs	\
+	$(srcdir)/PuzzleGames/PuzzleFigures.cs		\
+	$(srcdir)/PuzzleGames/PuzzleMatrixNumbers.cs	\
+	$(srcdir)/PuzzleGames/PuzzleMoveFigure.cs		\
+	$(srcdir)/PuzzleGames/PuzzlePencil.cs		\
+	$(srcdir)/PuzzleGames/PuzzleSquares.cs		\
+	$(srcdir)/PuzzleGames/PuzzleTriangles.cs		\
+	$(srcdir)/PuzzleGames/PuzzleCoverPercentage.cs	\
+	$(srcdir)/PuzzleGames/PuzzleNumericSequence.cs	\
+	$(srcdir)/PuzzleGames/PuzzleSquaresAndLetters.cs	\
+	$(srcdir)/PuzzleGames/PuzzleSquareDots.cs		\
+	$(srcdir)/PuzzleGames/PuzzleNumericRelation.cs	\
+	$(srcdir)/PuzzleGames/PuzzleNextFigure.cs		\
+	$(srcdir)/PuzzleGames/PuzzleSquareSheets.cs		\
+	$(srcdir)/CalculationGames/CalculationArithmetical.cs	\
+	$(srcdir)/MemoryGames/MemoryColouredFigures.cs	\
 	$(srcdir)/GameSession.cs		\
-	$(srcdir)/MemoryNumbers.cs		\
+	$(srcdir)/MemoryGames/MemoryNumbers.cs		\
 	$(srcdir)/Memory.cs			\
-	$(srcdir)/MemoryColouredText.cs		\
-	$(srcdir)/PuzzleCube.cs			\
-	$(srcdir)/MemoryWords.cs		\
-	$(srcdir)/PuzzleFigureLetter.cs		\
+	$(srcdir)/MemoryGames/MemoryColouredText.cs		\
+	$(srcdir)/PuzzleGames/PuzzleCube.cs			\
+	$(srcdir)/MemoryGames/MemoryWords.cs		\
+	$(srcdir)/PuzzleGames/PuzzleFigureLetter.cs		\
 	$(srcdir)/CustomGameDialog.cs		\
-	$(srcdir)/PuzzleDivideCircle.cs		\
-	$(srcdir)/CalculationGreatestDivisor.cs	\
-	$(srcdir)/CalculationTwoNumbers.cs	\
-	$(srcdir)/CalculationWhichNumber.cs	\
-	$(srcdir)/PuzzleMatrixGroups.cs		\
-	$(srcdir)/PuzzleBalance.cs		\
-	$(srcdir)/PuzzleTrianglesWithNumbers.cs	\
-	$(srcdir)/PuzzleOstracism.cs		\
-	$(srcdir)/MemoryCountDots.cs		\
-	$(srcdir)/CalculationOperator.cs	\
-	$(srcdir)/PuzzleFigurePattern.cs	\
+	$(srcdir)/PuzzleGames/PuzzleDivideCircle.cs		\
+	$(srcdir)/CalculationGames/CalculationGreatestDivisor.cs	\
+	$(srcdir)/CalculationGames/CalculationTwoNumbers.cs	\
+	$(srcdir)/CalculationGames/CalculationWhichNumber.cs	\
+	$(srcdir)/PuzzleGames/PuzzleMatrixGroups.cs		\
+	$(srcdir)/PuzzleGames/PuzzleBalance.cs		\
+	$(srcdir)/PuzzleGames/PuzzleTrianglesWithNumbers.cs	\
+	$(srcdir)/PuzzleGames/PuzzleOstracism.cs		\
+	$(srcdir)/MemoryGames/MemoryCountDots.cs		\
+	$(srcdir)/CalculationGames/CalculationOperator.cs	\
+	$(srcdir)/PuzzleGames/PuzzleFigurePattern.cs	\
 	$(srcdir)/ColorPalette.cs		\
-	$(srcdir)/PuzzlePeopleTable.cs		\
+	$(srcdir)/PuzzleGames/PuzzlePeopleTable.cs		\
 	$(srcdir)/GameDrawingArea.cs		\
-	$(srcdir)/MemoryFigures.cs		\
-	$(srcdir)/PuzzleMissingSlice.cs		\
-	$(srcdir)/PuzzleLines.cs		\
-	$(srcdir)/PuzzleTetris.cs		\
+	$(srcdir)/MemoryGames/MemoryFigures.cs		\
+	$(srcdir)/PuzzleGames/PuzzleMissingSlice.cs		\
+	$(srcdir)/PuzzleGames/PuzzleLines.cs		\
+	$(srcdir)/PuzzleGames/PuzzleTetris.cs		\
 	$(srcdir)/PreferencesDialog.cs		\
-	$(srcdir)/PuzzleMissingPiece.cs		\
-	$(srcdir)/MemoryIndications.cs		\
-	$(srcdir)/PuzzleMostInCommon.cs		\
-	$(srcdir)/PuzzleBuildTriangle.cs	\
+	$(srcdir)/PuzzleGames/PuzzleMissingPiece.cs		\
+	$(srcdir)/MemoryGames/MemoryIndications.cs		\
+	$(srcdir)/PuzzleGames/PuzzleMostInCommon.cs		\
+	$(srcdir)/PuzzleGames/PuzzleBuildTriangle.cs	\
 	$(srcdir)/CairoContextEx.cs		\
-	$(srcdir)/PuzzleClocks.cs		\
-	$(srcdir)/PuzzleCountCircles.cs		\
-	$(srcdir)/PuzzleEquation.cs		\
-	$(srcdir)/PuzzleQuadrilaterals.cs	\
-	$(srcdir)/CalculationFractions.cs	\
-	$(srcdir)/PuzzleExtraCircle.cs		\
-	$(srcdir)/PuzzleCountSeries.cs		\
+	$(srcdir)/PuzzleGames/PuzzleClocks.cs		\
+	$(srcdir)/PuzzleGames/PuzzleCountCircles.cs		\
+	$(srcdir)/PuzzleGames/PuzzleEquation.cs		\
+	$(srcdir)/PuzzleGames/PuzzleQuadrilaterals.cs	\
+	$(srcdir)/CalculationGames/CalculationFractions.cs	\
+	$(srcdir)/PuzzleGames/PuzzleExtraCircle.cs		\
+	$(srcdir)/PuzzleGames/PuzzleCountSeries.cs		\
 	$(srcdir)/PlayerHistory.cs		\
 	$(srcdir)/PlayerHistoryDialog.cs	\
 	$(srcdir)/GtkDialog.cs			\
 	$(srcdir)/Preferences.cs		\
-	$(srcdir)/PuzzleFourSided.cs		\
+	$(srcdir)/PuzzleGames/PuzzleFourSided.cs		\
 	$(srcdir)/SVGImage.cs			\
 	$(srcdir)/gbrainy.cs			
 

Added: trunk/src/PuzzleGames/PuzzleBalance.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleBalance.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleBalance : Game
+{
+	private const int elements = 5;
+	private int group;
+	private int [] balances = new int []
+	{
+		2,3,2,0,0,	1,3,1,1,1,
+		3,3,1,0,0,	2,2,2,1,0,
+		3,2,2,0,0,	0,0,0,0,0,
+
+		2,2,3,0,0,	3,2,1,1,0,
+		1,2,2,0,0,	3,1,1,0,0,
+		3,3,1,0,0,	0,0,0,0,0,
+
+		2,2,0,0,0,	2,1,1,0,0,
+		3,2,0,0,0,	1,1,1,2,0,
+		2,2,3,0,0,	0,0,0,0,0,
+	};
+
+	private const double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0;
+
+	public override string Name {
+		get {return Catalog.GetString ("Balance");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many triangles are needed in the right part of the last figure to keep it balanced?");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("Every triangle counts as 1, each diamond as 2 and each square as 3.");
+			return answer;
+		}
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Every diamond counts as two triangles.");}
+	}
+
+	public override void Initialize ()
+	{
+		int ans = 0;
+		group = random.Next (3);
+
+		for (int i = 0; i < elements; i++)	
+			ans += balances [(group * elements * 6) + (4 * elements) + i];
+
+		right_answer = ans.ToString ();
+	}
+
+	public void DrawBalance (CairoContextEx gr, double x, double y, int index, bool full)
+	{
+		double width = 0.5;
+		double fig_x = x + 0.1, fig_y = y - 0.11;
+		int total = (full == true) ? (elements * 2) : elements; 
+
+		gr.Rectangle (x + 0.05, y - 0.12, 0.38, 0.08);
+		gr.Stroke ();
+
+		gr.Rectangle (x + 0.5, y - 0.12, 0.38, 0.08);
+		gr.Stroke ();
+
+		for (int i = 0; i < total; i++) {
+			switch (balances[i + index]) {
+			case 1:
+				gr.DrawEquilateralTriangle (fig_x, fig_y, 0.05);
+				break;
+			case 2:
+				gr.DrawDiamond (fig_x, fig_y, 0.05);
+				break;
+			case 3:
+				gr.Rectangle (fig_x, fig_y + 0.005, 0.045, 0.045);
+				break;
+			}
+			
+			if (i == elements - 1)
+				fig_x = x + 0.54;
+			else
+				fig_x += 0.07;
+		}
+
+		x += 0.2;
+		y += 0.01;
+		gr.MoveTo (x, y);
+		gr.LineTo (x + width, y);
+		gr.LineTo (x + width, y - 0.05);
+		gr.Stroke ();
+		
+		gr.MoveTo (x , y);
+		gr.LineTo (x , y - 0.05);
+		gr.Stroke ();
+		
+		gr.DrawEquilateralTriangle (x + (width / 2) - 0.04, y, 0.08);
+		gr.Stroke ();
+
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{		
+		double x = 0.05, y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+
+		DrawBalance (gr, x, y, group * elements * 6, true);
+		y += 0.3;
+		
+		DrawBalance (gr, x, y, (group * elements * 6) + 1 * elements * 2, true);
+		y += 0.3;
+
+		DrawBalance (gr, x, y, (group * elements * 6) + 2 * elements * 2, false);
+	}
+
+}
+

Added: trunk/src/PuzzleGames/PuzzleBuildTriangle.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleBuildTriangle.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 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;
+
+public class PuzzleBuildTriangle : Game
+{
+	public enum Figures
+	{
+		TriangleA,
+		TriangleB,
+		TriangleC,
+		Square,
+		Diamon,
+		LongRectangle,
+		LongRectangleUp,
+		TriangleD,
+	}
+
+	private const double figure_size = 0.1;
+	private ArrayListIndicesRandom random_indices_answers;
+	private char [] answers;
+	private const int answer_num = 3;
+	private int total_figures;
+	private double space_figures;
+	private double radian = Math.PI / 180;
+
+	public override string Name {
+		get {return Catalog.GetString ("Build a triangle");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which three pieces can you use together to build a triangle? Answer using the three figure names, e.g.: ABE.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The resulting triangle is isosceles.");}
+	}
+
+	public override void Initialize ()
+	{
+		switch (CurrentDifficulty) {
+		case Difficulty.Easy:
+			total_figures = 6;
+			space_figures = 0.26;
+			break;
+		case Difficulty.Medium:
+		case Difficulty.Master:
+			total_figures = 8;
+			space_figures = 0.2;
+			break;
+		}
+
+		random_indices_answers = new ArrayListIndicesRandom (total_figures);
+		random_indices_answers.Initialize ();
+		answers = new char[answer_num];
+
+		for (int i = 0; i < random_indices_answers.Count; i++)
+		{
+			switch ((Figures) random_indices_answers[i]) {
+			case Figures.TriangleB:
+				answers[0] =  (char) (65 + i);
+				break;
+			case Figures.TriangleC:
+				answers[1] =  (char) (65 + i);
+				break;
+			case Figures.Square:
+				answers[2] =  (char) (65 + i);
+				break;
+			}
+		}
+
+		right_answer = answers[0].ToString () + answers[1].ToString () + answers[2].ToString ();		
+	}
+
+	private void DrawFigure (CairoContextEx gr, double x, double y, Figures figure)
+	{
+		switch (figure) {
+		case Figures.TriangleA:
+			gr.DrawEquilateralTriangle (x, y, figure_size);
+			break;
+		case Figures.TriangleB:
+			gr.MoveTo (x, y);
+			gr.LineTo (x, y + figure_size);
+			gr.LineTo (x + figure_size, y);
+			gr.LineTo (x, y);
+			gr.Stroke ();
+			break;
+		case Figures.TriangleC:
+			gr.MoveTo (x, y);
+			gr.LineTo (x, y + figure_size);
+			gr.LineTo (x + figure_size, y + figure_size);
+			gr.LineTo (x, y);
+			gr.Stroke ();
+			break;
+		case Figures.Square:
+			gr.Rectangle (x, y, figure_size, figure_size);
+			gr.Stroke ();
+			break;
+		case Figures.LongRectangle:
+			gr.Rectangle (x, y + figure_size / 2, figure_size, figure_size / 2);
+			gr.Stroke ();
+			break;
+		case Figures.LongRectangleUp:
+			gr.Rectangle (x, y, figure_size, figure_size / 2);
+			gr.Stroke ();
+			break;
+		case Figures.Diamon:
+			gr.DrawDiamond (x, y, figure_size);
+			break;
+		case Figures.TriangleD:
+			gr.MoveTo (x, y);
+			gr.LineTo (x, y + figure_size * 0.7);
+			gr.LineTo (x + figure_size * 0.7, y + figure_size * 0.7);
+			gr.LineTo (x, y);
+			gr.Stroke ();
+			break;
+		}
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.05, y = DrawAreaY + 0.05;
+		double degrees, x1, x2, dist;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int i = 0; i < random_indices_answers.Count; i++)	
+		{
+			DrawFigure (gr, x, y, (Figures) random_indices_answers[i]);
+			gr.MoveTo (x, y + 0.15);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+
+			if (i  == (total_figures / 2) - 1) {
+				y+= 0.25;
+				x= DrawAreaX + 0.05;
+			}
+			else
+				x+= space_figures;
+		}
+
+		if (DrawAnswer == false)
+			return;
+
+		gr.MoveTo (DrawAreaX, y + 0.28);
+		gr.ShowText (Catalog.GetString ("The triangle is:"));
+		gr.Stroke ();
+		
+		x = DrawAreaX + 0.35;
+		y += 0.35;
+
+		degrees = radian * 45;	// First triangle
+		gr.MoveTo (x, y);
+		x1 = x + figure_size * Math.Cos (degrees);
+		gr.LineTo (x1, y + figure_size * Math.Sin (degrees));
+
+		degrees = radian * (135);
+		x2 = x + figure_size * Math.Cos (degrees);
+		gr.MoveTo (x, y);
+		gr.LineTo (x2, y + figure_size * Math.Sin (degrees));
+		gr.LineTo (x1, y + figure_size * Math.Sin (degrees));
+		dist = (x1 - x2);
+		x += dist;
+
+		degrees = radian * 45; // Second triangle
+		gr.MoveTo (x, y);
+		x1 = x + figure_size * Math.Cos (degrees);
+		gr.LineTo (x1, y + figure_size * Math.Sin (degrees));
+
+		degrees = radian * (135);
+		x2 = x + figure_size * Math.Cos (degrees);
+		gr.MoveTo (x, y);
+		gr.LineTo (x2, y + figure_size * Math.Sin (degrees));
+		gr.LineTo (x1, y + figure_size * Math.Sin (degrees));
+
+		degrees = radian * (-45); // Bottom
+		x =  DrawAreaX + 0.35;
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size * Math.Cos (degrees), y + figure_size * Math.Sin (degrees));
+
+		x += dist;
+		degrees = radian * (-135);
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size * Math.Cos (degrees), y + figure_size * Math.Sin (degrees));
+		gr.Stroke ();	
+	}
+
+	private bool IndexOf (char c, char [] chars)
+	{
+		for (int i = 0; i < chars.Length; i++)
+			if (c == chars [i]) return true;
+
+		return false;
+	}
+
+	public override bool CheckAnswer (string a)
+	{	
+		char fig1 = '\0', fig2 = '\0', fig3 = '\0';
+		char [] ans = new char [answer_num];
+		int c = 0, matches = 0;
+		char[] opers = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
+		string answer;
+
+		a = TrimAnswer (a);
+		answer = a.ToUpper ();
+
+		for (int i = 0; i < answer_num; i++)
+			ans[i] = answers[i];
+		
+		for (c = 0; c < answer.Length; c++)
+		{
+			if (IndexOf (answer[c], opers)) {
+				fig1 = answer[c];
+				break;
+			}			
+		}
+
+		for (c++; c < answer.Length; c++)
+		{
+			if (IndexOf (answer[c], opers)) {
+				fig2 = answer[c];
+				break;
+			}
+		}
+
+		for (c++; c < answer.Length; c++)
+		{
+			if (IndexOf (answer[c], opers)) {
+				fig3 = answer[c];
+				break;
+			}
+		}
+
+		if (fig1 == '\0' || fig2 == '\0' || fig3 == '\0')
+			return false;
+	
+		for (int i = 0; i < answer_num; i++)
+		{
+			if (fig1 != ans[i] || ans[i] == '\0')
+				continue;
+
+			matches++;
+			ans[i] = '\0';
+			break;			
+		}
+
+		for (int i = 0; i < answer_num; i++)
+		{
+			if (fig2 != ans[i] || ans[i] == '\0')
+				continue;
+
+			matches++;
+			ans[i] = '\0';
+			break;			
+		}
+
+		for (int i = 0; i < answer_num; i++)
+		{
+			if (fig3 != ans[i] || ans[i] == '\0')
+				continue;
+
+			matches++;
+			ans[i] = '\0';
+			break;			
+		}
+
+		if (matches == answer_num)
+			return true;
+
+		return false;
+	}	
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleCirclesRectangle.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleCirclesRectangle.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleCirclesRectangle : Game
+{
+	public override string Name {
+		get {return Catalog.GetString ("Circles in a rectangle");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the maximum number of circles (as shown) that fit in the square below?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("You can fit more than 64 circles.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("In the layout shown {0} units of height are gained in each row. This allows using an additional row."), 0.1340);
+			return answer;
+		}
+	}
+
+	public override Difficulty GameDifficulty {
+		get {
+			return Difficulty.Master;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		right_answer = "68";
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double first_x = DrawAreaX + 0.05;
+		double first_y = DrawAreaY + 0.1;
+		double space_fromrect = 0.02, space_fromcircle = 0.01;
+		int circles = 8;
+		double unit = 0.0625;
+
+		base.Draw (gr, area_width, area_height);
+
+		gr.Rectangle (first_x, first_y, unit * 8, unit * 8);
+		gr.Stroke ();
+
+		// |-------|
+		gr.MoveTo (first_x, first_y - 0.04 - space_fromrect);
+		gr.LineTo (first_x, first_y - space_fromrect);
+		gr.Stroke ();
+		gr.MoveTo (first_x, first_y - 0.02 - space_fromrect);
+		gr.LineTo (first_x + 0.5, first_y - 0.02 - space_fromrect);
+		gr.Stroke ();
+		gr.MoveTo (first_x + 0.5, first_y - 0.04 - space_fromrect);
+		gr.LineTo (first_x + 0.5, first_y - space_fromrect);
+		gr.Stroke ();
+
+		gr.MoveTo (first_x + 0.2, first_y - 0.04 - space_fromrect);
+		gr.ShowText (Catalog.GetString ("8 units"));
+		gr.Stroke ();
+
+		//  ---
+		//	 |
+		//	 |
+		//	 |
+		//  ---
+		gr.MoveTo (first_x  - space_fromrect, first_y);
+		gr.LineTo (first_x  - space_fromrect - 0.04, first_y);
+		gr.Stroke ();
+		gr.MoveTo (first_x - space_fromrect - 0.02, first_y);
+		gr.LineTo (first_x - space_fromrect - 0.02, first_y + 0.5);
+		gr.Stroke ();
+		gr.MoveTo (first_x - space_fromrect, first_y + 0.5);
+		gr.LineTo (first_x - space_fromrect - 0.04, first_y + 0.5);
+		gr.Stroke ();
+
+		gr.Save ();
+		gr.MoveTo (first_x - space_fromrect - 0.05, first_y + 0.3);
+		gr.Rotate (270 * Math.PI/180);
+		gr.ShowText (Catalog.GetString ("8 units"));
+		gr.Restore ();		
+		gr.Stroke ();
+		
+		// Sample circle
+		gr.Arc (first_x + 0.7, first_y + 0.1, unit / 2, 0, 2 * Math.PI);
+		gr.Stroke ();
+
+		// |-------|
+		gr.MoveTo (first_x + 0.65, first_y + 0.05 - 0.04 - space_fromcircle);
+		gr.LineTo (first_x + 0.65, first_y + 0.05 - space_fromcircle);
+		gr.Stroke ();
+		gr.MoveTo (first_x + 0.65, first_y + 0.05 - 0.02 - space_fromcircle);
+		gr.LineTo (first_x + 0.65 + 0.1, first_y + 0.05 - 0.02 - space_fromcircle);
+		gr.Stroke ();
+		gr.MoveTo (first_x + 0.65 + 0.1, first_y + 0.05 - 0.04 - space_fromcircle);
+		gr.LineTo (first_x + 0.65 + 0.1, first_y + 0.05 - space_fromcircle);
+		gr.Stroke ();
+
+		gr.MoveTo (first_x + 0.65, first_y - space_fromcircle);
+		gr.ShowText (Catalog.GetString ("1 unit"));
+		gr.Stroke ();
+
+		//  ---
+		//	 |
+		//	 |
+		//	 |
+		//  ---
+		gr.MoveTo (first_x + 0.65  - space_fromcircle, first_y + 0.05);
+		gr.LineTo (first_x + 0.65  - space_fromcircle - 0.04, first_y + 0.05);
+		gr.Stroke ();
+		gr.MoveTo (first_x + 0.65 - space_fromcircle - 0.02, first_y + 0.05);
+		gr.LineTo (first_x + 0.65 - space_fromcircle - 0.02, first_y  + 0.05 + 0.1);
+		gr.Stroke ();
+		gr.MoveTo (first_x + 0.65 - space_fromcircle, first_y + 0.1 + 0.05);
+		gr.LineTo (first_x + 0.65 - space_fromcircle - 0.04, first_y + 0.1 + 0.05);
+		gr.Stroke ();
+
+		gr.Save ();
+		gr.MoveTo (first_x + 0.65 - space_fromcircle - 0.05, first_y + 0.15);
+		gr.Rotate (270 * Math.PI/180);
+		gr.ShowText (Catalog.GetString ("1 unit"));
+		gr.Restore ();		
+		gr.Stroke ();
+
+
+		if (DrawAnswer == false)
+			return;
+
+		double x;
+		for (int line = 0; line < 9; line++)
+		{
+			for (int circle = 0; circle < circles; circle++) 
+			{
+				x = first_x + (unit / 2) + (circle * unit);
+				
+				if (circles == 7)
+					x+= unit / 2;
+
+				gr.Arc (x, (unit / 2) + first_y + (unit * line) - (unit / 8) * line, 
+						(unit / 2), 0, 2 * Math.PI);
+				gr.Stroke ();
+			}
+
+			if (circles ==8)
+				circles = 7;
+			else
+				circles = 8;
+		}
+
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleClocks.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleClocks.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleClocks : Game
+{
+	private const double figure_size = 0.3;
+	private const double radian = Math.PI / 180;
+	private int addition;
+	private int []handles;
+	private const int clocks = 4;
+	private const int handle_num = 2;
+
+	public override string Name {
+		get {return Catalog.GetString ("Clocks");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("To what number should the large handle of the last clock point? Answer A, B, C or D.");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("Starting from the first clock sum {0} to the value indicated by the hands."), addition);
+			return answer;
+		}
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The clocks do not follow the time logic.");}
+	}
+
+	public override void Initialize ()
+	{
+		int position;
+
+		// In all these cases the clock logic clearly do not work since the small hand is in the next hour
+		switch (random.Next (3)) {
+		case 0:
+			position = 48;
+			addition = 5;
+			break;
+		case 1:
+			position = 38;
+			addition = 15;
+			break;
+		case 2:
+		default:
+			position = 24;
+			addition = 5;
+			break;
+		}
+
+		handles = new int [clocks * handle_num];
+
+		for (int i = 0; i < handles.Length; i++, i++)
+		{
+			handles [i] = position / 10;
+			handles [i + 1] = position - ((position / 10) * 10);
+			position += addition;
+		}
+		
+		right_answer = handles[7].ToString ();
+
+		/*DateTime dt1 = new DateTime (2008, 2, 20, handles[0], handles[1] * 5, 0);
+		DateTime dt2 = new DateTime (2008, 2, 20, handles[2], handles[3] * 5, 0);
+		Console.WriteLine ("t1 {0}", dt1);
+		Console.WriteLine ("t2 {0}", dt2);
+		Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);
+
+		dt1 = new DateTime (2008, 2, 20, handles[2], handles[3] * 5, 0);
+		dt2 = new DateTime (2008, 2, 20, handles[4], handles[5] * 5, 0);
+		Console.WriteLine ("t1 {0}", dt1);
+		Console.WriteLine ("t2 {0}", dt2);
+		Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);
+
+		dt1 = new DateTime (2008, 2, 20, handles[4], handles[5] * 5, 0);
+		dt2 = new DateTime (2008, 2, 20, handles[6], handles[7] * 5, 0);
+		Console.WriteLine ("t1 {0}", dt1);
+		Console.WriteLine ("t2 {0}", dt2);
+		Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);*/
+
+	}	
+
+	public void DrawClock (CairoContextEx gr, double x, double y, int hand_short, int hand_large, bool draw_large)
+	{
+		double radius = figure_size / 2;
+		double x0, y0;
+		int num, degrees;
+
+		gr.Arc (x, y, radius, 0, 2 * Math.PI);
+		gr.Stroke ();
+		for (degrees = 0; degrees < 360; degrees+= 30) {
+			x0 = radius * Math.Cos (degrees * radian);
+			y0 = radius * Math.Sin (degrees * radian);
+			 // Small lines
+			gr.MoveTo (x + 0.9 * x0, y + 0.9 * y0);
+			gr.LineTo (x + x0, y + y0);
+			gr.Stroke ();
+			// Numbers
+			num = (degrees / 30) + 3;
+			if (num > 12) num = num - 12;
+
+			gr.DrawTextCentered (x + x0 * 0.75,  y + y0 * 0.75, num.ToString ());
+			gr.Stroke ();
+		}
+
+		if (draw_large) {
+			// Hand Large
+			degrees = (hand_large - 3) * 30; 
+			x0 = radius * Math.Cos (degrees * radian);
+			y0 = radius * Math.Sin (degrees * radian);
+			gr.MoveTo (x, y);
+			gr.LineTo (x + x0 * 0.55, y + y0 * 0.55);
+			gr.Stroke ();
+		}
+		// Hand Short
+		degrees = (hand_short - 3) * 30; 
+		x0 = radius * Math.Cos (degrees * radian);
+		y0 = radius * Math.Sin (degrees * radian);
+		gr.MoveTo (x, y);
+		gr.LineTo (x + x0 * 0.4, y + y0 * 0.4);
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
+
+		base.Draw (gr, area_width, area_height);
+
+		DrawClock (gr, x + 0.1, y + 0.1, handles[0], handles[1], true);
+		gr.MoveTo (x + 0.03, y + 0.31);
+		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), 'A'));
+		gr.Stroke ();
+	
+		DrawClock (gr, x + 0.5, y + 0.1, handles[2], handles[3], true);
+		gr.MoveTo (x + 0.43, y + 0.31);
+		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), 'B'));
+		gr.Stroke ();
+
+		DrawClock (gr, x + 0.1, y + 0.52, handles[4], handles[5], true);
+		gr.MoveTo (x + 0.03, y + 0.73);
+		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), 'C'));
+		gr.Stroke ();
+
+		DrawClock (gr, x + 0.5, y + 0.52, handles[6], handles[7], DrawAnswer == true);
+		gr.MoveTo (x + 0.43, y + 0.73);
+		gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), 'D'));
+		gr.Stroke ();
+
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleCountCircles.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleCountCircles.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleCountCircles : Game
+{
+	private const double figure_size = 0.3;
+	private const double radian = Math.PI / 180;
+	private int n_circles;
+
+	class ItemCircle
+	{
+		public double x, y, rad;
+
+		public ItemCircle (double x, double y, double rad)
+		{
+			this.x = x;
+			this.y = y;
+			this.rad = rad;
+		}
+	}
+
+	ItemCircle[] circles;
+
+	public override string Name {
+		get {return Catalog.GetString ("Count circles");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many circles do you count?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("It is an easy exercise if you systematically count the circles.");}
+	}
+
+	public override void Initialize ()
+	{
+		double x, y, rad;
+
+		switch (CurrentDifficulty) {
+		case Difficulty.Easy:
+			n_circles = 7;
+			break;
+		case Difficulty.Master:
+			n_circles = 14;
+			break;		
+		case Difficulty.Medium:
+		default:
+			n_circles = 10;
+			break;		
+		}
+
+		n_circles += random.Next (5);
+		circles = new ItemCircle [n_circles];
+		for (int i = 0; i < circles.Length; i++)
+		{
+			x = random.Next (500) / 1000d;
+			y = random.Next (500) / 1000d;
+			rad = 0.03 +  random.Next (500) / 3200d;
+
+			circles[i] = new ItemCircle (x, y, rad);
+		}
+
+		right_answer = n_circles.ToString ();
+	}	
+
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int i = 0; i < circles.Length; i++)
+		{
+			gr.Arc (x + circles[i].x + 0.1, y + circles[i].y + 0.1, circles[i].rad, 0, 2 * Math.PI);
+			gr.Stroke ();
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleCountSeries.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleCountSeries.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 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;
+
+public class PuzzleCountSeries : Game
+{
+	enum GameType
+	{
+		HowManyNines,
+		HowManySmallerDigits,
+		HowManyBiggerDigits,
+		Length		
+	}
+
+	private string question;
+
+	public override string Name {
+		get {return Catalog.GetString ("Count series");}
+	}
+
+	public override string Question {
+		get {return question;} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		switch ((GameType) random.Next ((int) GameType.Length))
+		{
+			case GameType.HowManyNines:
+				question = Catalog.GetString ("How many numbers \"9\" are required to represent the numbers between 10 to 100?");
+				right_answer = "19";
+				break;
+
+			case GameType.HowManyBiggerDigits:
+				question = Catalog.GetString ("How many two digit numbers occur where the first digit is larger than the second (e.g.: 20 and 21)?");
+				right_answer = "45";
+				break;
+
+			case GameType.HowManySmallerDigits:
+				question = Catalog.GetString ("How many two digit numbers occur where the first digit is smaller than the second (e.g.: 12 and 13)?");
+				right_answer = "36";
+				break;
+		}
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		base.Draw (gr, area_width, area_height);
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleCoverPercentage.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleCoverPercentage.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,170 @@
+/*
+ * 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;
+
+public class PuzzleCoverPercentage : Game
+{
+	private bool cover_zone1, cover_zone2, cover_zone3, cover_zone4;
+	private int partial_zone, partial_zones;
+	private const double width = 0.5, height = 0.5;
+	private double line_width = 0.001;
+
+	public override string Name {
+		get {return Catalog.GetString ("Cover percentage");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What percentage of the figure is colored?");} 
+	}
+
+	public override void Initialize ()
+	{
+		int total = 0;
+
+		cover_zone1 = random.Next (3) == 0;
+		cover_zone2 = random.Next (3) == 0;
+		cover_zone3 = random.Next (3) == 0;
+		cover_zone4 = random.Next (3) == 0;
+
+		if (cover_zone1 && cover_zone2 && cover_zone3)
+			cover_zone4 = false;
+
+		if (cover_zone1) total+= 25;
+		if (cover_zone2) total+= 25;
+		if (cover_zone3) total+= 25;
+		if (cover_zone4) total+= 25;
+
+		if (cover_zone1 == false)
+			partial_zone = 1;
+		else
+			if (cover_zone2 == false)
+				partial_zone = 2;
+			else
+				if (cover_zone3 == false)
+					partial_zone = 3;
+				else
+					if (cover_zone4 == false)
+						partial_zone = 4;
+
+		partial_zones = random.Next (2) + 1;
+		total += partial_zones * 5;
+		right_answer = total.ToString ();
+	}
+
+	private void Fill (CairoContextEx gr, double x, double y, double w, double h)
+	{
+		gr.Rectangle (x, y, w, h);
+		gr.FillGradient (x, y, w, h);
+	}
+
+	private void DrawSection (CairoContextEx gr, double x, double y)
+	{
+		double w =  width / 2, h = height / 2;
+		double pos_x = x, pos_y = y;
+		for (int i = 0; i < 5; i++) {
+			gr.MoveTo (pos_x, pos_y + h / 5);
+			gr.LineTo (pos_x + w, pos_y + h / 5);
+			gr.Stroke ();
+			pos_y += h / 5;
+		}
+	
+		gr.MoveTo (x + w / 2, y);
+		gr.LineTo (x + w / 2, y + h);
+		gr.Stroke ();
+
+		gr.Save ();
+		gr.Color = new Cairo.Color (0.90, 0.90, 0.90);
+		for (int i = 0; i < partial_zones; i++) {
+			Fill (gr, x + line_width, line_width + y, 
+				(w / 2) - (line_width * 2) , (h / 5) - (line_width * 2));
+			Fill (gr, x + (w / 2) + line_width * 2, line_width + y, 
+				(w / 2) - (line_width * 4) , (h / 5) - (line_width * 2));
+			y += h / 5;
+		}
+		gr.Restore ();
+	}
+
+	private void CoverZone (CairoContextEx gr, double x, double y)
+	{
+		Fill (gr, x + line_width, y + line_width , (width / 2) - (line_width * 2), (height / 2) - (line_width * 2));
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = 0.25, y = 0.25;
+
+		base.Draw (gr, area_width, area_height);
+		
+		gr.Rectangle (x, y, width, height);
+		gr.Stroke ();
+
+		gr.MoveTo (x, y + height / 2);
+		gr.LineTo (x + width, y + height / 2);
+		gr.Stroke ();
+
+		gr.MoveTo (x + width / 2, y);
+		gr.LineTo (x + width / 2, y + height);
+		gr.Stroke ();
+
+		if (cover_zone1) 
+			CoverZone (gr, x, y);
+
+		if (cover_zone2) 
+			CoverZone (gr, x + width / 2, y);
+
+		if (cover_zone3) 
+			CoverZone (gr, x, y + height / 2);
+		
+		if (cover_zone4) 
+			CoverZone (gr, x + width / 2, y + height / 2);
+
+		switch (partial_zone) {
+			case 1:
+				break;
+			case 2:
+				x += width / 2;
+				break;
+			case 3:
+				y += height / 2;
+				break;
+			case 4:
+				y += height / 2;
+				x += width / 2;
+				break;
+		}
+
+		DrawSection (gr, x, y);
+	}
+
+	public override bool CheckAnswer (string answer)
+	{	
+		if (String.Compare (answer, right_answer, true) == 0) 
+			return true;
+
+		if (String.Compare (answer, right_answer + "%", true) == 0) 
+			return true;
+
+		return false;
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleCube.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleCube.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleCube : Game
+{
+	private char question;
+	const int pairs = 4;
+
+	private int[] question_answer = 
+	{
+		1, 4,
+		6, 2,
+		4, 1,
+		2, 6,
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Cube");}
+	}
+
+	public override string Question {
+		get {return String.Format (Catalog.GetString ("When folded as a cube, which face on the figure is opposite the face with a {0} drawn on it? Answer the number written on face."), question);} 
+	}
+
+	public override void Initialize ()
+	{
+		int pair = random.Next (pairs);
+		question = (char) (48 + question_answer[pair * 2]);
+		right_answer += (char) (48 + question_answer[(pair * 2) + 1]);
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.1;
+		double y = DrawAreaY + 0.1;
+		double txtoff_x = 0.04;
+		double txtoff_y = 0.06;
+
+		base.Draw (gr, area_width, area_height);
+
+		gr.Rectangle (x + 0.1, y, 0.1, 0.1);
+		gr.MoveTo (x + 0.1 + txtoff_x, y + txtoff_y);
+		gr.ShowText ("1");
+
+		gr.Rectangle (x + 0.2, y, 0.1, 0.1);
+		gr.MoveTo (x + 0.2 + txtoff_x, y + txtoff_y);
+		gr.ShowText ("2");
+
+		gr.Rectangle (x + 0.2, y + 0.1, 0.1, 0.1);
+		gr.MoveTo (x + 0.2 + txtoff_x, y + 0.1 + txtoff_y);
+		gr.ShowText ("3");
+
+		gr.Rectangle (x + 0.3, y + 0.1, 0.1, 0.1);
+		gr.MoveTo (x + 0.3 + txtoff_x, y + 0.1 + txtoff_y);
+		gr.ShowText ("4");
+
+		gr.Rectangle (x + 0.4, y + 0.1, 0.1, 0.1);
+		gr.MoveTo (x + 0.4 + txtoff_x, y + 0.1 + txtoff_y);
+		gr.ShowText ("5");
+
+		gr.Rectangle (x + 0.4, y + 0.2, 0.1, 0.1);
+		gr.MoveTo (x + 0.4 + txtoff_x, y + 0.2 + txtoff_y);
+		gr.ShowText ("6");
+
+		gr.Stroke ();
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleDivideCircle.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleDivideCircle.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleDivideCircle : Game
+{
+	private const double figure_size = 0.15;
+	private int dots;
+	
+	private class Circle
+	{	
+		public double x;
+		public double y;
+
+		public Circle (double x, double y) 
+		{
+			this.x = x;
+			this.y = y;
+		}
+	}
+
+	public override string Name {
+		get {return Catalog.GetString ("Divide circles");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("In the last figure, in how many regions is the circle divided into when all dots are connected?");} 
+	}
+
+	public override void Initialize ()
+	{
+		if (CurrentDifficulty==Difficulty.Easy)
+			dots = 5;
+		else
+			dots = 5 + random.Next (2);
+
+		switch (dots) {
+		case 5:
+			right_answer = "16";
+			break;
+		case 6:
+			right_answer = "30";
+			break;
+		}			
+	}
+
+	private void DrawAndConnectPoints (CairoContextEx gr, double x, double y, Circle[] circles, bool connect)
+	{
+		double point_size = 0.01;
+		for (int i = 0; i < circles.Length; i++) {
+			gr.Arc (x + point_size + circles[i].x, y + point_size + circles[i].y, point_size, 0, 2 * Math.PI);
+			gr.Fill ();
+			gr.Stroke ();
+		}
+
+		if (connect == false)
+			return;
+		
+		gr.Save ();
+		gr.LineWidth = 0.003;
+		double offset = point_size;
+		for (int from = 0; from < circles.Length; from++) {
+			for (int to = 0; to < circles.Length; to++) {
+				gr.MoveTo (x + circles[from].x+ offset, y + circles[from].y + offset);
+				gr.LineTo (x + circles[to].x + offset, y + circles[to].y + offset);
+				gr.Stroke ();
+			}
+		}
+		gr.Restore ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.05, y = DrawAreaY;
+		double pos_x = x;
+		double pos_y = y;
+		Circle[] circles = null;
+
+		base.Draw (gr, area_width, area_height);
+
+		// First circle
+		gr.Arc (pos_x + figure_size, y + figure_size, figure_size, 0, 2 * Math.PI);
+		gr.Stroke ();
+		DrawAndConnectPoints (gr, pos_x, pos_y, 
+			new Circle [] {
+				new Circle (0.14, 0),
+				new Circle (0.14, 0.29),
+			}, true);
+
+		gr.MoveTo (pos_x, pos_y + figure_size * 2 + 0.05);
+		gr.ShowText (String.Format (Catalog.GetString ("Has {0} regions"), 2));
+		gr.Stroke ();
+
+		// Second circle
+		pos_x += 0.4;
+		gr.Arc (pos_x + figure_size, pos_y + figure_size, figure_size, 0, 2 * Math.PI);
+		gr.Stroke ();		
+		DrawAndConnectPoints (gr, pos_x, pos_y,
+			new Circle [] {
+				new Circle (0.01, 0.06),
+				new Circle (0.27, 0.06),
+				new Circle (0.14, 0.29),
+			}, true);
+
+		gr.MoveTo (pos_x, pos_y + figure_size * 2 + 0.05);
+		gr.ShowText (String.Format (Catalog.GetString ("Has {0} regions"), 4));
+		gr.Stroke ();
+
+		// Third circle
+		pos_x = x;
+		pos_y += 0.45;
+		gr.Arc (pos_x + figure_size, pos_y + figure_size, figure_size, 0, 2 * Math.PI);
+		gr.Stroke ();		
+		DrawAndConnectPoints (gr, pos_x, pos_y,
+			new Circle [] {
+				new Circle (0.01, 0.06),
+				new Circle (0.27, 0.06),
+				new Circle (0.01, 0.21),
+				new Circle (0.27, 0.21),
+			}, true);
+
+		gr.MoveTo (pos_x, pos_y + figure_size * 2 + 0.05);
+		gr.ShowText (String.Format (Catalog.GetString ("Has {0} regions"), 8));
+		gr.Stroke ();
+
+		switch (dots) {
+		case 5:
+			circles =  new Circle [] {
+				new Circle (0.01, 0.06),
+				new Circle (0.27, 0.06),
+				new Circle (0.01, 0.21),
+				new Circle (0.27, 0.21),
+				new Circle (0.14, 0),
+			};
+			break;
+		case 6:
+			circles =  new Circle [] {
+				new Circle (0.01, 0.06),
+				new Circle (0.27, 0.06),
+				new Circle (0.01, 0.21),
+				new Circle (0.27, 0.21),
+				new Circle (0.14, 0),
+				new Circle (0.14, 0.29)
+			};
+			break;
+		}
+
+		// Forth circle
+		pos_x += 0.4;
+		gr.Arc (pos_x + figure_size, pos_y + figure_size, figure_size, 0, 2 * Math.PI);
+		gr.Stroke ();		
+		DrawAndConnectPoints (gr, pos_x, pos_y, circles, DrawAnswer);
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleEquation.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleEquation.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleEquation : Game
+{
+	private int num_a, num_b, num_c, num_d, num_e;
+	private string formula;
+
+	public override string Name {
+		get {return Catalog.GetString ("Equation");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the result of the equation below?");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("The order of arithmetical operations is always as follows: exponents and roots, multiplication and division, addition and subtraction.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		bool found  = false;
+		int order = 0, sequential;
+
+		while (found == false) {
+			num_a = 2 + random.Next (5);
+			num_b = 2 + random.Next (5);
+			num_c = 2 + random.Next (5);
+			num_d = 2 + random.Next (5);
+			num_e = 2 + random.Next (5);
+			order = num_a * num_b + num_c *  num_d - num_e;
+			sequential = ((num_a * num_b + num_c) * num_d) - num_e;
+
+			if (order != sequential)
+				found = true;
+		}
+
+		formula = String.Format ("{0}  * {1} + {2} * {3} - {4} = ?", num_a, num_b, num_c, num_d, num_e);
+		right_answer = (order).ToString ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		base.Draw (gr, area_width, area_height);
+
+		gr.SetLargeFont ();
+		gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);
+	}
+}

Added: trunk/src/PuzzleGames/PuzzleExtraCircle.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleExtraCircle.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleExtraCircle : Game
+{
+	private const int total_slices = 6;
+	private const int circles = 4;
+	private const double radius = 0.1;
+	private const double radian = Math.PI / 180;
+	private int ans_pos;
+	private Color[] cercle_colors;
+	private Color[] badcercle_colors;
+	private int[] start_indices;
+	private ColorPalette cp;
+
+	public override string Name {
+		get {return Catalog.GetString ("Extra circle");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which circle does not belong to the group? It is not a sequence of elements. Answer A, B, C or D.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("All circles share a common property except for one.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("In all circles the color slices follow the same order except for this one."));
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		ArrayListIndicesRandom random_indices = new ArrayListIndicesRandom (total_slices);
+		Color clr;
+
+		cp = new ColorPalette (ColorPalette.Id.Last);
+		cp.Initialize ();
+
+		cercle_colors = new Color [total_slices];
+		badcercle_colors =  new Color [total_slices];
+		for (int i = 0; i < total_slices; i++) {
+			cercle_colors [i] = cp.Cairo (i);
+			badcercle_colors [i] = cp.Cairo (i);
+		}
+		
+		// Correct answer
+		random_indices.Initialize ();
+		clr = badcercle_colors [random_indices[0]];
+		badcercle_colors [random_indices[0]] =  badcercle_colors [random_indices[1]];
+		badcercle_colors [random_indices[1]] = clr;
+
+		// Indices
+		start_indices = new int [circles];
+		for (int i = 0; i < circles; i++)
+			start_indices[i] = (random_indices[i]);
+
+		ans_pos = random.Next (circles);
+		right_answer += (char) (65 + ans_pos);
+	}
+
+	private void DrawSlice (CairoContextEx gr, double x, double y, double dg, Color color)
+	{
+		double x1, y1, smallest_x, smallest_y, degrees;
+
+		smallest_x = x;
+		smallest_y = y;
+		degrees = radian * (60 + dg);
+		gr.MoveTo (x, y);
+		x1 = x + radius * Math.Cos (degrees);
+		y1 = y + radius * Math.Sin (degrees);
+		gr.LineTo (x1, y1);
+		if (x1 < smallest_x) smallest_x = x1;
+		if (y1 < smallest_y) smallest_y = y1;
+		
+		degrees = dg * radian;
+		gr.MoveTo (x, y);
+		x1 = x + radius * Math.Cos (degrees);
+		y1 = y + radius * Math.Sin (degrees);
+		gr.LineTo (x1, y1);
+		if (x1 < smallest_x) smallest_x = x1;
+		if (y1 < smallest_y) smallest_y = y1;
+
+		gr.Arc (x, y, radius, dg * radian, radian * (60 + dg));
+		gr.FillGradient (smallest_x, smallest_y, radius, radius, color);
+		gr.Stroke ();
+	}
+
+	private void DrawCircle (CairoContextEx gr, double x, double y, Color[] colors, int color_indice)
+	{		
+		double dg;
+		gr.Arc (x, y, radius, 0, 2 * Math.PI);
+		gr.Stroke ();
+		
+		gr.Save ();
+		for (int slice = 0; slice < total_slices; slice++) 
+		{	
+			dg = slice * (360 / total_slices);
+			DrawSlice (gr, x, y, dg, colors [color_indice]);
+			
+			color_indice++;
+			if (color_indice >= colors.Length)
+				color_indice = 0;
+			
+		}
+		gr.Restore ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{		
+		double x = DrawAreaX, y = DrawAreaY;
+		Color [] colors;
+
+		base.Draw (gr, area_width, area_height);
+
+		x+= radius / 2;
+		y+= radius / 2;
+
+		for (int i = 0; i < circles; i++)
+		{
+			if (ans_pos == i)
+				colors = badcercle_colors;
+			else
+				colors = cercle_colors;
+
+			DrawCircle (gr, x + i * 0.23, y + 0.2, colors, start_indices[i]);
+
+			gr.MoveTo (x - 0.07 + i * 0.22, y + 0.38);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+			gr.Stroke ();
+		}
+	}
+}
+

Added: trunk/src/PuzzleGames/PuzzleFigureLetter.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleFigureLetter.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleFigureLetter : Game
+{
+	private QuestionType question;
+	
+	enum QuestionType
+	{
+		TwoRectangles	= 0,
+		TwoCercles,
+		ThreeCercles,
+		Length		
+	}
+
+	public override string Name {
+		get {return Catalog.GetString ("Figures and text");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("The figures and the text are related. What text should go under the last figure?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Every character of the text represents a property of the figure.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("'A' indicates that the figures overlap, 'B' that are rectangles, 'C' that are circles, 'D' that the figures are separated, 'E' that there are three figures and 'F' that there are two figures.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		question = (QuestionType) random.Next ((int) QuestionType.Length);
+
+		switch (question) {
+		case QuestionType.TwoRectangles:
+			right_answer = "ABF";
+			break;
+		case QuestionType.TwoCercles:
+			right_answer = "CDF";
+			break;
+		case QuestionType.ThreeCercles:
+			right_answer = "ACE";
+			break;
+		}
+	}
+
+	public override bool CheckAnswer (string answer)
+	{	
+		answer = TrimAnswer (answer);
+		switch (question) {
+		case QuestionType.TwoRectangles:		
+			if ((String.Compare (answer, "ABF", true) == 0) 
+				|| (String.Compare (answer, "AFB", true) == 0)
+				|| (String.Compare (answer, "BAF", true) == 0)
+				|| (String.Compare (answer, "BFA", true) == 0)
+				|| (String.Compare (answer, "FBA", true) == 0)
+				|| (String.Compare (answer, "FAB", true) == 0)) {
+				return true;
+			}
+			break;
+		case QuestionType.TwoCercles:		
+			if ((String.Compare (answer, "CDF", true) == 0)
+				|| (String.Compare (answer, "CFD", true) == 0)
+				|| (String.Compare (answer, "DCF", true) == 0)
+				|| (String.Compare (answer, "DFC", true) == 0)
+				|| (String.Compare (answer, "FCD", true) == 0)
+				|| (String.Compare (answer, "FDC", true) == 0)) {
+				return true;
+			}
+			break;
+		case QuestionType.ThreeCercles:		
+			if ((String.Compare (answer, "ACE", true) == 0)
+				|| (String.Compare (answer, "AEC", true) == 0)
+				|| (String.Compare (answer, "CAE", true) == 0)
+				|| (String.Compare (answer, "CEA", true) == 0)
+				|| (String.Compare (answer, "EAC", true) == 0)
+				|| (String.Compare (answer, "ECA", true) == 0)) {
+				return true;
+			}
+			break;
+		}
+				
+		return false;
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.05;
+		double y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+		
+		// Three circles
+		gr.Arc (x + 0.06, y, 0.05, 0, 2 * Math.PI);
+		gr.Stroke ();
+		gr.Arc (x, y + 0.1, 0.05, 0, 2 * Math.PI);
+		gr.Stroke ();
+		gr.Arc (x + 0.11, y + 0.1, 0.05, 0, 2 * Math.PI);
+		gr.Stroke ();
+		gr.MoveTo (x + 0.02, y + 0.2);
+		gr.ShowText ("CDE");
+		gr.Stroke ();
+
+		// Two linked circles
+		gr.Arc (x + 0.3, y, 0.05, 0, 2 * Math.PI);
+		gr.Stroke ();
+		gr.Arc (x + 0.3 + 0.06, y + 0.05, 0.05, 0, 2 * Math.PI);
+		gr.Stroke ();
+		gr.MoveTo (x + 0.30, y + 0.2);
+		gr.ShowText ("ACF");
+		gr.Stroke ();
+
+		// Two rectangles
+		gr.Rectangle (x + 0.5, y, 0.1, 0.1);
+		gr.Rectangle (x + 0.62, y, 0.1, 0.1);
+		gr.Stroke ();
+		gr.MoveTo (x + 0.58, y + 0.2);
+		gr.ShowText ("BDF");
+		gr.Stroke ();
+
+	
+		// Tree rectangles
+		gr.Rectangle (x - 0.05, y + 0.35, 0.1, 0.1);
+		gr.Rectangle (x + 0.06 - 0.05, y + 0.37, 0.1, 0.1);
+		gr.Rectangle (x + 0.12 - 0.05, y + 0.39, 0.1, 0.1);
+		gr.Stroke ();
+		gr.MoveTo (x + 0.04, y + 0.55);
+		gr.ShowText ("ABE");
+		gr.Stroke ();
+
+		x += 0.25;
+		y += 0.35;
+
+		switch (question) {
+		case QuestionType.TwoRectangles:
+			gr.Rectangle (x, y, 0.1, 0.1);
+			gr.Rectangle (x + 0.05, y + 0.03, 0.1, 0.1);
+			gr.Stroke ();
+			gr.MoveTo (x + 0.05, y + 0.2);
+			break;
+		case QuestionType.TwoCercles:
+			gr.Arc (x + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.Arc (x + 0.12 + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.MoveTo (x + 0.1, y + 0.2);
+			break;
+		case QuestionType.ThreeCercles:
+			gr.Arc (x + 0.05 + 0.06, y + 0.04, 0.05, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.Arc (x + 0.05, y + 0.06 + 0.04, 0.05, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.Arc (x + 0.05  + 0.11, y + 0.06 + 0.04, 0.05, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.MoveTo (x + 0.1, y + 0.2);
+			break;
+		}
+
+		gr.ShowText ("?");
+		gr.Stroke ();		
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleFigurePattern.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleFigurePattern.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleFigurePattern : Game
+{
+	private ArrayListIndicesRandom random_indices;
+
+	enum Figures
+	{
+		TwoLines = 0,
+		Cross,
+		RotatedCross,
+		Last
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Figure pattern");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What figure should replace the question mark? Answer A, B or C.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The third figure of every row involves somehow combining the first two figures.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("Superpose the first and second figures and remove the lines that they have in common, then rotate the resulting figure 45 degrees.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom ((int) Figures.Last);
+		random_indices.Initialize ();
+
+		for (int i = 0; i < (int) Figures.Last; i++)
+		{
+			if ((int) random_indices[i] == (int) Figures.Cross) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+	}
+
+	private void DrawRotatedCross (CairoContextEx gr, double x, double y, double size)
+	{
+		gr.MoveTo (x, y);
+		gr.LineTo (x + size, y + size);
+		gr.MoveTo (x + size, y);
+		gr.LineTo (x, y + size);
+		gr.Stroke ();
+	}
+
+	private void DrawTwoLines (CairoContextEx gr, double x, double y, double size)
+	{
+		gr.MoveTo (x, y);
+		gr.LineTo (x + size, y);
+		gr.MoveTo (x, y + size);
+		gr.LineTo (x + size, y + size);
+		gr.Stroke ();
+	}
+
+	private void DrawCross (CairoContextEx gr, double x, double y, double size)
+	{
+		gr.MoveTo (x + size / 2, y);
+		gr.LineTo (x + size / 2, y + size);
+		gr.MoveTo (x, y + size / 2);
+		gr.LineTo (x + size, y + size / 2);
+		gr.Stroke ();
+	}
+	
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double org_x = DrawAreaX + 0.1;
+		double x = org_x, y = 0.08;
+		double figure_size = 0.13, space_x = 0.1, space_y = 0.2;
+		double x45, y45, x135, y135, offset;
+
+		base.Draw (gr, area_width, area_height);
+
+		// First pattern
+		gr.Rectangle (x, y, figure_size, figure_size);
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.MoveTo (x + figure_size, y);
+		gr.LineTo (x, y + figure_size);
+		gr.MoveTo (x + figure_size / 2, y);
+		gr.LineTo (x + figure_size / 2, y + figure_size);
+		gr.MoveTo (x, y + figure_size / 2);
+		gr.LineTo (x + figure_size, y + figure_size / 2);
+		gr.Stroke ();
+
+		x += figure_size + space_x;
+		gr.Rectangle (x, y, figure_size, figure_size);
+		gr.MoveTo (x + figure_size / 2, y);
+		gr.LineTo (x + figure_size / 2, y + figure_size);
+		gr.MoveTo (x, y + figure_size / 2);
+		gr.LineTo (x + figure_size, y + figure_size / 2);
+		gr.Stroke ();
+
+		x += figure_size + space_x;
+		DrawCross (gr, x, y, figure_size);
+
+		y += space_y;
+		x = org_x;
+		// Second pattern
+		gr.Rectangle (x, y, figure_size, figure_size);
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.MoveTo (x + figure_size, y);
+		gr.LineTo (x, y + figure_size);
+		gr.Stroke ();
+
+		x += figure_size + space_x;
+		DrawRotatedCross (gr, x, y, figure_size);
+
+		// Rotated rectangle
+		x += figure_size + space_x;
+		x45 = figure_size * Math.Cos (45 * Math.PI / 180);
+		y45 = figure_size * Math.Sin (45 * Math.PI / 180);
+		x135 = figure_size * Math.Cos (135 * Math.PI / 180);
+		y135 = figure_size * Math.Sin (135 * Math.PI / 180);
+		offset = - 0.03;
+		// Down-right
+		gr.MoveTo (x + figure_size / 2, y + offset);
+		gr.LineTo (x + figure_size / 2 + x45, y + offset + y45);
+		// Up right
+		gr.LineTo ((x + figure_size / 2 + x45) + x135, (y + offset +  y45) + y135);
+		gr.Stroke ();
+		// Down left
+		gr.MoveTo (x + figure_size / 2, y + offset);
+		gr.LineTo (x + figure_size / 2 + x135, y + offset + y135);
+		// Up left
+		gr.LineTo (x + figure_size / 2 + x135 + x45, y + offset + y135 + y45);
+		gr.Stroke ();
+
+		y += space_y;
+		x = org_x;
+
+		// Third pattern
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size, y);
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size, y  + figure_size);
+		gr.Stroke ();
+
+		x += figure_size + space_x;
+		gr.MoveTo (x + figure_size, y);
+		gr.LineTo (x, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.LineTo (x, y  + figure_size);
+		gr.Stroke ();
+		
+		x += figure_size + space_x;
+		gr.Save ();
+		gr.MoveTo (x + 0.03, y + 0.1);
+		gr.SetFontSize (figure_size);	
+		gr.ShowText ("?");
+		gr.Stroke ();
+		gr.Restore ();
+	
+		gr.MoveTo (0.05, y + 0.01 + space_y);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+
+		// Answers
+		x = org_x;
+		y += space_y + 0.07;
+
+		for (int i = 0; i < (int) Figures.Last; i++)
+		{
+		 	switch ((Figures) random_indices[i]) {
+			case Figures.TwoLines:
+				DrawTwoLines (gr, x, y, figure_size);
+				break;
+			case Figures.Cross:
+				DrawCross (gr, x, y, figure_size);
+				break;
+			case Figures.RotatedCross:
+				DrawRotatedCross (gr, x, y, figure_size);
+				break;
+			}
+			
+			gr.MoveTo (x, y + 0.2);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+
+			x += figure_size + space_x;			
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleFigures.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleFigures.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleFigures : Game
+{
+	private int [] figures  = new int []
+	{
+		0, 0, 1, 1, 2, 2,
+		1, 2, 2, 0, 1, 0,
+		2, 1, 0, 2, 0, 1
+	};
+
+	private ArrayListIndicesRandom random_indices;
+	private const double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0;
+
+	public override string Name {
+		get {return Catalog.GetString ("Figures");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the next logical sequence of objects in the last column? See below the convention when giving the answer.");} 
+	}
+
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			answer += Catalog.GetString ("It is the only combination that you can build with the given elements without repeating them.");
+
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom (6);
+		random_indices.Initialize ();
+
+		StringBuilder sb = new StringBuilder (3);
+		
+		sb.Append ((char) (65 + figures[random_indices [5]]));
+		sb.Append ((char) (65 + figures[6 + random_indices [5]]));
+		sb.Append ((char) (65 + figures[(2 * 6) + random_indices [5]]));
+
+		right_answer = sb.ToString ();
+	}
+
+	private void AnswerCoding (CairoContextEx gr, double x, double y)
+	{
+		double pos_x = x;
+
+		gr.MoveTo (pos_x, y);
+		y += 0.05;
+		gr.ShowText (Catalog.GetString ("Convention when giving the answer is:"));
+
+		gr.MoveTo (pos_x, y + 0.05);
+		gr.ShowText ("A ->");
+		gr.Stroke ();
+		gr.DrawDiamond (x + 0.1, y, 0.1);
+		gr.Stroke ();
+	
+		pos_x += 0.3;
+		gr.MoveTo (pos_x, y + 0.05);
+		gr.ShowText ("B ->");
+		gr.Stroke ();
+		pos_x += 0.1;
+		gr.Arc (pos_x + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);	
+		gr.Stroke ();
+
+		pos_x += 0.2;
+		gr.MoveTo (pos_x, y + 0.05);
+		gr.ShowText ("C ->");
+		gr.Stroke ();
+		pos_x += 0.1;
+		gr.DrawEquilateralTriangle (pos_x, y, 0.1);
+		gr.Stroke ();
+
+		y += 0.18;
+		gr.MoveTo (x, y);		
+		gr.ShowText (Catalog.GetString ("E.g: ACB (diamond, triangle, circle)"));	
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{		
+		int element;
+		double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0.1;
+		double x = DrawAreaX, y = DrawAreaY;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int i = 0; i < (DrawAnswer ? 6 : 5) ; i++)
+		{
+			element = random_indices [i];
+			y = DrawAreaY;
+			for (int n = 0; n < 3; n++) 
+			{
+				switch ((int) figures[(n * 6) + element])
+				{
+					case 0:
+						gr.DrawDiamond (x, y, 0.1);
+						break;
+					case 1:
+						gr.Arc (x + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);	
+						break;
+					case 2:
+						gr.DrawEquilateralTriangle (x, y, 0.1);
+						break;
+					default:
+						break;
+				}
+				gr.Stroke ();
+				y+= figure_height + space_height;		
+			}
+			x+= figure_width + space_width;
+		}
+
+		if (DrawAnswer == false) {
+			y = DrawAreaY + 0.08;
+			gr.Save ();
+			gr.SetFontSize (0.1);
+			for (int n = 0; n < 3; n++) {
+				gr.MoveTo (x, y);
+				gr.ShowText ("?");
+				gr.Stroke ();
+				y+= figure_height + space_height;		
+			}
+			gr.Restore ();	
+			y -= 0.08;
+		}
+
+		AnswerCoding (gr, DrawAreaX, y);
+	}
+
+	public override bool CheckAnswer (string answer)
+	{
+		answer = TrimAnswer (answer);
+		return base.CheckAnswer (answer);
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleFourSided.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleFourSided.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 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;
+
+public class PuzzleFourSided : Game
+{
+	int type;
+	public override string Name {
+		get {return Catalog.GetString ("Four sided");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many four sided figures do you count in the figure below?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("A four sided figure can be embedded inside another figure.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			answer += String.Format (Catalog.GetString ("The four sided figures are made by connecting the following points: {0}"),
+				(type == 0) ? "abde, degh, bcef, efhi, acdf, dfgi, abhg, bcih, acig, aghe, aefc, deig, bcie." : 
+				"abde, degh, bcef, efhi, acdf, dfgi, abhg, bcih, acig, aghe, aefc, deig, bcie, acde, cehi, abeg, egif.");
+
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		if (CurrentDifficulty==Difficulty.Easy)
+			type = 0;
+		else
+			type = random.Next (2);
+
+		
+		if (type == 0)	
+			right_answer = "13";
+		else
+			right_answer = "17";
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.1, y = DrawAreaY + 0.1, w = 0.6, h = 0.6;
+
+		base.Draw (gr, area_width, area_height);
+		
+		gr.Rectangle (x, y, w, h);
+		gr.Stroke ();
+
+		// Lines
+		gr.MoveTo (x + w /2, y);
+		gr.LineTo (x + w /2, y + h);
+		gr.Stroke ();
+		gr.MoveTo (x, y + h /2);
+		gr.LineTo (x + w, y + h / 2);
+		gr.Stroke ();
+
+		// Diagonals
+		gr.MoveTo (x, y);
+		gr.LineTo (x + w, y + h);
+		gr.Stroke ();
+
+		if (type == 1) {
+			gr.MoveTo (x + w, y);
+			gr.LineTo (x, y + h);
+			gr.Stroke ();
+		}
+
+		if (DrawAnswer == false)
+			return;
+
+		// References
+		gr.MoveTo (x - 0.04, y - 0.02);
+		gr.ShowText ("a");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w / 2 - 0.02, y - 0.02);
+		gr.ShowText ("b");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w + 0.02, y - 0.02);
+		gr.ShowText ("c");
+		gr.Stroke ();
+
+		gr.MoveTo (x - 0.04, y + h /2 - 0.02);
+		gr.ShowText ("d");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w / 2 - 0.04, y  + h /2 - 0.04);
+		gr.ShowText ("e");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w + 0.02, y  + h /2 - 0.02);
+		gr.ShowText ("f");
+		gr.Stroke ();
+
+		gr.MoveTo (x - 0.04, y + h + 0.04);
+		gr.ShowText ("g");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w / 2 - 0.02, y + h + 0.04);
+		gr.ShowText ("h");
+		gr.Stroke ();
+
+		gr.MoveTo (x + w + 0.02, y + h + 0.04);
+		gr.ShowText ("i");
+		gr.Stroke ();
+
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleLines.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleLines.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleLines : Game
+{
+	private const int max_types = 3;
+	private int type;
+	private int fig1, fig2;
+
+	public override string Name {
+		get {return Catalog.GetString ("Lines");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many lines do you count of in the figures below? Consider a line a segment between two points with no crossing lines.");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("There are {0} lines in the figure to the left and {1} in the figure to the right."), fig1, fig2);
+			return answer;
+		}
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("It is an easy exercise if you systematically count the lines.");}
+	}
+
+	public override void Initialize ()
+	{
+		if (CurrentDifficulty==Difficulty.Easy)
+			type = 0;
+		else
+			type = random.Next (max_types);		
+
+		switch (type) {
+		case 0:
+			fig1 = 15;
+			fig2 = 21;
+			break;
+		case 1:
+			fig1 = 33;
+			fig2 = 21;
+			break;
+		case 2:
+			fig1 = 15;
+			fig2 = 39;
+			break;
+		}
+
+		right_answer = (fig1 + fig2).ToString ();
+	}
+
+	private void DrawLine (CairoContextEx gr, double x, double y, double w, double h)
+	{
+		gr.MoveTo (x, y);
+		gr.LineTo (x + w, y + h);
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		base.Draw (gr, area_width, area_height);
+	
+		DrawLine (gr, 0.1, 0.2, 0.4, 0.38);
+		DrawLine (gr, 0.1, 0.3, 0.4, 0.3);
+		DrawLine (gr, 0.1, 0.4, 0.4, 0.25);
+
+		if (type == 1)  {
+			DrawLine (gr, 0.6, 0.3, -0.2, 0.35);
+			DrawLine (gr, 0.5, 0.25, -0.2, 0.35);		
+		}
+
+		DrawLine (gr, 0.1, 0.25, 0.6, 0.1);
+		DrawLine (gr, 0.25, 0.2, 0, 0.4);
+
+		if (type == 2 || type == 1)  {
+			DrawLine (gr, 0.85, 0.25, -0.2, 0.4);
+			DrawLine (gr, 0.88, 0.25, -0.2, 0.4);
+		}
+
+		DrawLine (gr, 0.91, 0.25, -0.2, 0.4);
+		DrawLine (gr, 0.8, 0.2, 0, 0.4);
+		DrawLine (gr, 0.82, 0.2, 0, 0.4);
+		DrawLine (gr, 0.6, 0.50, 0.25, 0);
+		DrawLine (gr, 0.6, 0.53, 0.25, 0);
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleMatrixGroups.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMatrixGroups.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,135 @@
+/*
+ * 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;
+
+public class PuzzleMatrixGroups : Game
+{
+	private int [] numbers;
+	private int good_pos;
+	private const int rows = 4, columns = 4;
+	private int divisor;
+
+	public override string Name {
+		get {return Catalog.GetString ("Matrix groups");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("One of numbers in the matrix must be circled. Which one?");}
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("All circled numbers share an arithmetical property.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("Every circled number can be divided by {0}."), divisor);
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		numbers = new int [rows * columns];
+		bool completed = false;
+		int count;
+		int good = 1 + random.Next (5);
+
+		switch (random.Next (2)) {
+		case 0:
+			divisor = 2;
+			break;
+		case 1:
+			divisor = 3;
+			break;
+		}
+		
+		while (completed == false) {
+			count = 0;
+			for (int n = 0; n < rows; n++) {
+				for (int i = 0; i < columns; i++) {
+					numbers[(n*rows) + i] = GetUnique ((n*rows) + i);
+					if (numbers[(n*rows) + i] % divisor == 0) {
+						count++;
+						if  (count == good) {
+							good_pos =  (n*rows) + i;
+						}
+					}
+				}
+			}
+			
+			if (count > 5 && count < 10)
+				completed = true;
+		}
+		right_answer = numbers[good_pos].ToString ();
+	}
+
+	private int GetUnique (int max)
+	{
+		int unique = 0, i;
+		bool found = false;
+
+		while (found == false)
+		{
+			unique = 1 + random.Next (100);
+			for (i = 0; i < max; i++) {
+				if (unique == numbers [i]) {
+					break;
+				}
+			}
+			if (i == max)
+				found = true;
+		}
+		return unique;
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double rect_w = DrawAreaWidth / rows;
+		double rect_h = DrawAreaHeight / columns;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int column = 0; column < columns; column++) {
+			for (int row = 0; row < rows; row++) {
+				
+				gr.Color = DefaultDrawingColor;
+				gr.Rectangle (DrawAreaX + row * rect_w, DrawAreaY + column * rect_h, rect_w, rect_h);
+				gr.Stroke ();
+
+				gr.DrawTextCentered (DrawAreaX + (rect_w / 2) + column * rect_w, (rect_h / 2) + DrawAreaY + row * rect_h, 
+					(numbers[column + (row * 4)]).ToString() );
+
+				if (numbers[column + (row * 4)] % divisor == 0 && good_pos != column + (row * 4)) {
+					gr.Arc (DrawAreaX + (rect_w / 2) + column * rect_w, (rect_h / 2) + DrawAreaY + row * rect_h,
+						0.05, 0, 2 * Math.PI);
+					gr.FillGradient (DrawAreaX + (rect_w / 2) + column * rect_w, (rect_h / 2) + DrawAreaY + row * rect_h,
+						0.05, 0.05);
+
+				}		
+				gr.Stroke ();
+			}
+		}
+	}
+}
+

Added: trunk/src/PuzzleGames/PuzzleMatrixNumbers.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMatrixNumbers.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007 Javier MÂ Mora MerchÃn <jamarier gmail com>
+ *
+ * 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;
+
+public class PuzzleMatrixNumbers : Game
+{
+	public enum Operation
+	{
+		MultiplyAndAdd = 0,	// Multiplies two elements and adds a third
+		MutilplyAndSubs,	// Multiplies two elements and substracts a third
+		AddAndSubs,		// Adds two elements and  substracts a third 
+		LastOperation
+	}
+
+	private int [] numbers;
+	private Operation operation;
+	private bool orientation;
+	private const int rows = 4, columns = 4;
+
+	public override string Name {
+		get {return Catalog.GetString ("Matrix numbers");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("The numbers in the matrix follow a logic. Which is the number that should replace the question mark?");}
+	}
+
+	public override string Tip {
+		get { 
+			if (orientation) 
+				return Catalog.GetString ("The logic is arithmetical and works vertically.");
+			else 
+				return Catalog.GetString ("The logic is arithmetical and works horizontally.");
+		}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			switch (operation) {
+			case Operation.MultiplyAndAdd:
+				if (orientation) {
+					answer += String.Format(Catalog.GetString("The fourth row is calculated by multiplying the first two rows and adding the third."));
+				} else {
+					answer += String.Format(Catalog.GetString("The fourth column is calculated by multiplying the first two columns and adding the third."));
+				}
+				break;
+			case Operation.MutilplyAndSubs:
+				if (orientation) {
+					answer += String.Format(Catalog.GetString("The fourth row is calculated by multiplying the first two rows and subtracting the third."));
+				} else {
+					answer += String.Format(Catalog.GetString("The fourth column is calculated by multiplying the first two columns and subtracting the third."));
+				}
+				break;
+			case Operation.AddAndSubs:
+				if (orientation) {
+					answer += String.Format(Catalog.GetString("The fourth row is calculated by adding the first two rows and subtracting the third."));
+				} else {
+					answer += String.Format(Catalog.GetString("The fourth column is calculated by adding the first two columns and subtracting the third."));
+				}
+				break;
+			}
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		operation = (Operation) random.Next ((int) Operation.LastOperation);
+		orientation = (random.Next ((int) 2) == 0) ? true : false;
+		numbers = new int [4 * 4];
+
+		int coordinateA, coordinateB;
+
+		if (orientation) {
+			coordinateA=4; 
+			coordinateB=1;
+		}
+		else {
+			coordinateA=1;
+			coordinateB=4;
+		}
+
+		
+		for (int n = 0; n < 3; n++)
+			for (int i = 0; i < 4; i++) 
+				numbers[n*coordinateA + i*coordinateB] = random.Next (10) + random.Next (5);
+
+		for (int i = 0; i < 4; i++) {
+			switch (operation) {
+			case Operation.MultiplyAndAdd:
+				numbers[3*coordinateA + i*coordinateB] = (numbers [0*coordinateA + i*coordinateB ] * numbers[1*coordinateA + i*coordinateB]) + numbers[2*coordinateA + i*coordinateB];
+				break;
+			case Operation.MutilplyAndSubs:
+				numbers[3*coordinateA + i*coordinateB] = (numbers [0*coordinateA + i*coordinateB ] * numbers[1*coordinateA + i*coordinateB]) - numbers[2*coordinateA + i*coordinateB];
+				break;
+			case Operation.AddAndSubs:
+				numbers[3*coordinateA + i*coordinateB] = (numbers [0*coordinateA + i*coordinateB ] + numbers[1*coordinateA + i*coordinateB]) - numbers[2*coordinateA + i*coordinateB];
+				break;
+			default:
+				break;
+			}			
+		}
+
+		right_answer = numbers[3*coordinateA + 3*coordinateB].ToString ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double rect_w = DrawAreaWidth / rows;
+		double rect_h = DrawAreaHeight / columns;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int column = 0; column < columns; column++) {
+			for (int row = 0; row < rows; row++) {
+				gr.Rectangle (DrawAreaX + row * rect_w, DrawAreaY + column * rect_h, rect_w, rect_h);
+
+				if (row != 3  || column != 3) {
+					gr.MoveTo (0.04 + DrawAreaX + column * rect_w, (rect_h / 2) + DrawAreaY + row * rect_h);
+					gr.ShowText ( (numbers[column + (row * 4)]).ToString() );
+				}
+			}
+		}
+
+		gr.MoveTo (0.04 + DrawAreaX + 3 * rect_w, (rect_h / 2) + DrawAreaY + 3 * rect_h);
+		gr.ShowText ("?");
+		gr.Stroke ();
+	}
+
+}

Added: trunk/src/PuzzleGames/PuzzleMissingPiece.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMissingPiece.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleMissingPiece : Game
+{
+
+	private ArrayListIndicesRandom random_indices;
+	private const double sub_figure = 0.15;
+
+	public override string Name {
+		get {return Catalog.GetString ("Missing piece");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which square completes the figure below? Answer A, B or C.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The logic works at row level.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("In every row the third square is made by flipping the first square and superimposing it on the second square, followed by removing the matching lines.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom (3);
+		random_indices.Initialize ();
+
+		for (int i = 0; i < random_indices.Count; i++) {
+			if (random_indices [i] == 0) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+	}
+
+	private void DrawFigureSequence (CairoContextEx gr, double x, double y, int sequence, bool last_block)
+	{
+		gr.Rectangle (x, y, sub_figure, sub_figure);
+		gr.Rectangle (x + sub_figure, y, sub_figure, sub_figure);
+
+		if (last_block)
+			gr.Rectangle (x + sub_figure * 2, y, sub_figure, sub_figure);
+
+		switch (sequence) {
+		case 0:
+			gr.MoveTo (x, y + sub_figure);
+			gr.LineTo (x + sub_figure, y);
+			gr.MoveTo (x, y);
+			gr.LineTo (x + sub_figure, y + sub_figure);
+			x+= sub_figure;
+			gr.MoveTo (x, y);
+			gr.LineTo (x + sub_figure, y  + sub_figure);
+			x+= sub_figure;
+			gr.MoveTo (x, y + sub_figure);
+			gr.LineTo (x + sub_figure, y);
+			break;
+		case 1:
+			gr.MoveTo (x + sub_figure, y);
+			gr.LineTo (x, y + sub_figure);
+			gr.MoveTo (x + sub_figure / 2, y + sub_figure);
+			gr.LineTo (x + sub_figure, y + sub_figure / 2);
+			x+= sub_figure;
+			gr.MoveTo (x, y + sub_figure / 2);
+			gr.LineTo (x + sub_figure / 2, y + sub_figure);
+			x+= sub_figure;
+			gr.MoveTo (x, y);
+			gr.LineTo (x + sub_figure, y + sub_figure);
+			break;
+		case 2:
+			gr.MoveTo (x + sub_figure / 2, y);
+			gr.LineTo (x + sub_figure, y + sub_figure / 2);
+			gr.MoveTo (x, y + sub_figure);
+			gr.LineTo (x + sub_figure / 2, y + sub_figure / 2);
+			gr.LineTo (x + sub_figure, y + sub_figure);
+			x+= sub_figure;
+			gr.MoveTo (x, y + sub_figure / 2);
+			gr.LineTo (x + sub_figure / 2, y);
+			break;
+		}
+
+		gr.Stroke ();
+	}
+
+	private void DrawAnswerFigures (CairoContextEx gr, double x, double y, int figure)
+	{
+		gr.Rectangle (x, y, sub_figure, sub_figure);
+
+		switch (figure) {
+		case 0:
+			gr.MoveTo (x, y + sub_figure);
+			gr.LineTo (x + sub_figure / 2, y + sub_figure / 2);
+			gr.LineTo (x + sub_figure, y + sub_figure);
+			break;
+		case 1:
+			gr.MoveTo (x, y + sub_figure);
+			gr.LineTo (x + sub_figure, y);
+			break;
+		case 2:
+			gr.MoveTo (x, y);
+			gr.LineTo (x + sub_figure, y + sub_figure);
+			break;
+		}
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.15, y = DrawAreaY;
+		int figure;
+
+		base.Draw (gr, area_width, area_height);
+		
+		for (int i = 0; i < 2; i++)
+			DrawFigureSequence (gr, x, y + sub_figure * i , i, true);
+
+		DrawFigureSequence (gr, x, y + sub_figure * 2 , 2, false);
+
+		gr.MoveTo (0.1, 0.66);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+
+		x = DrawAreaX + 0.1;
+		for (int i = 0; i < random_indices.Count; i++) {
+			figure = random_indices [i];
+			DrawAnswerFigures (gr, x + (0.08 + sub_figure) * i, 0.70, figure);
+			gr.MoveTo (x + (0.08 + sub_figure) * i, 0.9);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+		}
+	}
+}
+

Added: trunk/src/PuzzleGames/PuzzleMissingSlice.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMissingSlice.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleMissingSlice : Game
+{
+	private const int total_slices = 6;
+	private const int half_slices = total_slices / 2;
+	private const int items_per_slice = 3;
+	private const double radius = 0.22;
+	private const double radian = Math.PI / 180;
+	private const double arc_centerx = 0.2, arc_centery = 0.2;
+	private const int possible_answers = 3;
+	private ArrayListIndicesRandom random_indices;
+	private int ans_pos;
+	private int[] bad_answers;
+	private int sum_offset;
+
+	private int [] slices = new int []
+	{
+		2, 4, 3,
+		2, 3, 6,
+		1, 3, 4,
+		3, 7, 1,
+		6, 3, 2,
+	};
+
+	private int [] slices_opposite = new int []
+	{
+		6, 4, 5,
+		6, 5, 2,
+		7, 5, 4,
+		5, 1, 7,
+		2, 5, 6,
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Missing slice");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Some slices have a common property. Which is the missing slice in the circle below? Answer A, B or C.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Each slice is related to the opposite one.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("All numbers of each slice, when added to the ones of the opposite slice, add always {0}."), sum_offset + 8);
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		sum_offset = random.Next (3);
+		random_indices = new ArrayListIndicesRandom (slices.Length / items_per_slice);
+		random_indices.Initialize ();
+		ans_pos = random.Next (possible_answers);
+		right_answer += (char) (65 + (int) ans_pos);
+		
+		bad_answers = new int [possible_answers * items_per_slice];
+		for (int i = 0; i < bad_answers.Length; i++) {
+			bad_answers[i] = 1 + random.Next (9);
+		}
+	}
+
+	private void DrawSlice (CairoContextEx gr, double x, double y)
+	{
+		double degrees, x1, y1;
+		
+		degrees = 0;
+		gr.MoveTo (x, y);
+		x1 = x + radius * Math.Cos (degrees);
+		y1 = y + radius * Math.Sin (degrees);
+		gr.LineTo (x1, y1);
+		gr.Stroke ();
+
+		degrees = radian * 60;
+		gr.MoveTo (x, y);
+		x1 = x + radius * Math.Cos (degrees);
+		y1 = y + radius * Math.Sin (degrees);
+		gr.LineTo (x1, y1);
+		gr.Stroke ();
+
+		gr.Arc (x, y, radius, 0, radian * 60);
+		gr.Stroke ();
+	}
+
+	private void DrawSliceText (CairoContextEx gr, double x, double y, int slice, string str1, string str2, string str3)
+	{	
+		double x0, y0, degrees;
+
+		// Number more near to the center;
+		degrees = radian * (slice * ((360 / total_slices)) + (360 / 12));
+		x0 = 0.35 * radius * Math.Cos (degrees);
+		y0 = 0.35 * radius * Math.Sin (degrees);
+		gr.DrawTextCentered (x + x0, y + y0, str1);
+	
+		// Number opposite to the center and at the top
+		degrees = radian * (slice * ((360 / total_slices)) + (360 / 24));
+		x0 = 0.8 * radius * Math.Cos (degrees);
+		y0 = 0.8 * radius * Math.Sin (degrees);
+		gr.DrawTextCentered (x + x0, y + y0, str2);
+	
+		// Number opposite to the center and at the bottom
+		degrees = radian * (slice * ((360 / total_slices)) + (360 / 8));			
+		x0 = 0.8 * radius * Math.Cos (degrees);
+		y0 = 0.8 * radius * Math.Sin (degrees);
+		gr.DrawTextCentered (x + x0, y + y0, str3);
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{		
+		double x = DrawAreaX + 0.2, y = DrawAreaY;
+		double x0, y0, degrees;
+		int pos;
+
+		base.Draw (gr, area_width, area_height);
+			
+		gr.Arc (x + arc_centerx, y + arc_centery, radius, 0, 2 * Math.PI);
+		gr.Stroke ();
+
+		for (int slice = 0; slice < total_slices; slice++) 
+		{
+			degrees = radian * slice * (360 / total_slices);
+			gr.MoveTo (x + arc_centerx, y + arc_centery);
+			gr.LineTo (x + arc_centerx + (radius * Math.Cos (degrees)), y + arc_centery + (radius * Math.Sin (degrees)));
+	
+			if (slice > total_slices - 1) continue;
+
+			if (slice == 0) {
+				degrees = radian * (slice * ((360 / total_slices)) + (360 / 12));
+				x0 = 0.5 * radius * Math.Cos (degrees);
+				y0 = 0.5 * radius * Math.Sin (degrees);
+				gr.DrawTextCentered (x + arc_centerx + x0, y + arc_centery + y0, "?");
+				continue;
+			}
+			
+			if (slice < half_slices) {
+				pos = random_indices [slice];
+				DrawSliceText (gr, x + arc_centerx, y + arc_centery, slice, (sum_offset + slices [pos * items_per_slice]).ToString (),
+					 (sum_offset + slices [1 + (pos * items_per_slice)]).ToString (), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString ());
+			}
+			else {
+				pos = random_indices [slice - half_slices];
+				DrawSliceText (gr, x + arc_centerx, y + arc_centery, slice, slices_opposite [pos * items_per_slice].ToString (),
+					 slices_opposite [2 + (pos * items_per_slice)].ToString (), slices_opposite [1 + (pos * items_per_slice)].ToString ());
+			}
+		}
+
+		gr.MoveTo (0.1, 0.61);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+
+		y = 0.68;
+ 		for (int i = 0; i < possible_answers; i++) 
+		{
+			DrawSlice (gr, 0.10 + i * 0.28, y);
+			if (i == ans_pos) {
+				pos = random_indices [0];
+				DrawSliceText (gr, 0.10 + i * 0.28, y, 0, (sum_offset + slices [pos * items_per_slice]).ToString (),
+					 (sum_offset + slices [1 + (pos * items_per_slice)]).ToString (), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString ());
+			} else {
+				DrawSliceText (gr, 0.10 + i * 0.28, y, 0, bad_answers [i * items_per_slice].ToString (),
+					 bad_answers [1 + (i * items_per_slice)].ToString (), bad_answers [2 + (i * items_per_slice)].ToString ());
+			}
+			
+			gr.MoveTo (0.10  + i * 0.28, y + 0.25);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+		}
+	}
+}
+

Added: trunk/src/PuzzleGames/PuzzleMostInCommon.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMostInCommon.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 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 System.Collections;
+
+public class PuzzleMostInCommon : Game
+{
+	public enum Element
+	{
+		SmallCircle,
+		MediumCircleWithChild,
+		MediumCircle,
+		LargeCircle,
+	}
+
+	struct FigureElement
+	{
+		public double x;
+		public double y;
+		public Element element;
+
+		public FigureElement (double _x, double _y, Element _element)
+		{
+			x = _x;
+			y = _y;
+			element = _element;
+		}
+	}
+	
+	private double small_size = 0.01;
+	private double medium_size = 0.02;
+  	private ArrayList questions;
+  	private ArrayList answers;
+	private ArrayListIndicesRandom random_indices_answers;
+	private const double pos1_x = 0.03;
+	private const double pos2_x = 0.06;
+	private const double pos3_x = 0.09;
+	private const double pos4_x = 0.07;
+	private const double pos5_x = 0.10;
+	private const double pos6_x = 0.02;
+	private const double pos7_x = 0.05;
+	private const double pos1_y = 0.03;
+	private const double pos2_y = 0.06;
+	private const double pos3_y = 0.09;
+	private const double pos4_y = 0.02;
+	private const double pos5_y = 0.05;
+	private const double pos6_y = 0.07;
+	private const double pos7_y = 0.11;
+
+	public override string Name {
+		get {return Catalog.GetString ("Most in common");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which of the possible answers have the most in common with the four given figures? Answer A, B, C or D.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Think of the common elements that the given figures have inside them.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			if (CurrentDifficulty ==  Difficulty.Easy) 
+				answer += Catalog.GetString ("It has the same number of elements inside the figure as the given figures.");
+			else
+				answer += Catalog.GetString ("It is the figure with the most elements in common compared to the given figures.");
+			
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		// Question
+		ArrayList array_good = new ArrayList ();
+		array_good.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.SmallCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+
+		// Four random samples with equal elements
+		questions = new ArrayList ();
+		for (int i = 0; i < 4; i++) {
+			questions.Add (BuildFigure (array_good, questions));
+		}
+
+		ArrayList array = new ArrayList ();
+		answers = new ArrayList ();
+		random_indices_answers = new ArrayListIndicesRandom (4);
+		random_indices_answers.Initialize ();
+
+		for (int i = 0; i < random_indices_answers.Count; i++) {
+			if ((int) random_indices_answers [i] == 0) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+
+		if (CurrentDifficulty ==  Difficulty.Easy) {
+			// Answer 1 (good)
+			array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.SmallCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+			answers.Add (BuildFigure (array, answers));
+
+			// Answer 2
+			array.Clear ();
+			array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+			answers.Add (BuildFigure (array, answers));
+
+			// Answer 3
+			array.Clear ();
+			array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+			answers.Add (BuildFigure (array, answers));
+
+			// Answer 4
+			array.Clear ();
+			array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+			answers.Add (BuildFigure (array, answers));
+			return;
+		}
+
+		// Medium or Master
+
+		// Answer 1 (good)
+		array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircleWithChild, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+		answers.Add (BuildFigure (array, answers));
+
+		// Answer 2
+		array.Clear ();
+		array.AddRange (new Element [] {Element.SmallCircle, Element.MediumCircle, Element.MediumCircle, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+		answers.Add (BuildFigure (array, answers));
+
+		// Answer 3
+		array.Clear ();
+		array.AddRange (new Element [] {Element.SmallCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+		answers.Add (BuildFigure (array, answers));
+
+		// Answer 4
+		array.Clear ();
+		array.AddRange (new Element [] {Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild, 
+			Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
+		answers.Add (BuildFigure (array, answers));
+	}
+
+	private ArrayListIndicesRandom RandomizeFromArray (ArrayList ar)
+	{		
+		int index;
+		object []array = (object []) ar.ToArray (typeof (object));
+		ArrayListIndicesRandom elements = new ArrayListIndicesRandom (ar.Count);
+		int left = ar.Count;
+		elements.Clear ();
+
+		// Generate a random number that can be as big as the maximum -1
+		// Add the random element picked up element in the list
+		// The element just randomized gets out of pending list and replaced by the maximum -1 element 
+		for (int i = 0; i < ar.Count; i++, left--) {
+			index = random.Next (left);
+			elements.Add ((int) array[index]);
+			array[index] = array[left - 1];
+		}
+		return elements;
+	}
+
+	// Generates a new figure that was not generated before
+	private FigureElement [] BuildFigure (ArrayList array, ArrayList figures)
+	{
+		bool done = false;
+		FigureElement [] element = null;
+		ArrayListIndicesRandom elements = new ArrayListIndicesRandom (array.Count);
+		bool element_exists = false;
+
+		while (done == false) {
+
+			elements = RandomizeFromArray (array);
+			element = new FigureElement []
+			{
+				new FigureElement (pos1_x, pos1_y, (Element) elements[0]),
+				new FigureElement (pos2_x, pos2_y, (Element) elements[1]),
+				new FigureElement (pos3_x, pos3_y, (Element) elements[2]),
+				new FigureElement (pos4_x, pos4_y, (Element) elements[3]),
+				new FigureElement (pos5_x, pos5_y, (Element) elements[4]),
+				new FigureElement (pos6_x, pos6_y, (Element) elements[5]),
+				new FigureElement (pos7_x, pos7_y, (Element) elements[6]),
+			};
+	
+			for (int i = 0; i < figures.Count; i++) {
+				FigureElement [] element2 = (FigureElement []) figures[i];
+
+				if (element.Length != element2.Length)
+					continue;
+
+				element_exists = true;
+				for (int n = 0; n < element.Length; n++) {
+					if (element[n].element != element2[n].element) {
+						element_exists = false;
+						break;
+					}
+				}
+				if (element_exists == true)
+					break;
+			}
+
+			if (element_exists == false)
+				done = true;
+		}
+
+		return element;
+	}
+
+	private void DrawFigureElement (CairoContextEx gr, double x, double y, FigureElement figure)
+	{
+		switch (figure.element) {
+		case Element.SmallCircle:
+			gr.Arc (x + figure.x + small_size / 2, y + figure.y + small_size / 2, small_size, 0, 2 * Math.PI);
+			break;
+		case Element.MediumCircle:
+			gr.Arc (x + figure.x + medium_size / 2, y + figure.y + medium_size / 2, medium_size, 0, 2 * Math.PI);
+			break;
+		case Element.MediumCircleWithChild:
+			gr.Arc (x + figure.x + medium_size / 2, y + figure.y + medium_size / 2, medium_size, 0, 2 * Math.PI);
+			gr.Stroke ();
+			gr.Arc (x + figure.x + medium_size / 2, y + figure.y + medium_size / 2, small_size, 0, 2 * Math.PI);
+			break;
+		}
+		gr.Stroke ();
+	}
+
+	private void DrawFigure (CairoContextEx gr, double x, double y, FigureElement[] figure)
+	{
+		double cercle_size = 0.15;
+		gr.Stroke ();
+		gr.Arc (x + cercle_size / 2, y + cercle_size / 2, cercle_size / 2, 0, 2 * Math.PI);
+		gr.Stroke ();
+
+		for (int i = 0; i < figure.Length; i++)
+			DrawFigureElement (gr, x, y,  figure[i]);			
+
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+		
+		for (int i = 0; i < questions.Count; i++) {
+			DrawFigure (gr, x, y, (FigureElement []) questions[i]);
+			 x+= 0.22;
+		}
+
+		y += 0.3;
+		x = DrawAreaX;
+		gr.MoveTo (x - 0.04, y);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+		gr.Stroke ();
+	
+		y += 0.08;
+		for (int i = 0; i < random_indices_answers.Count; i++) {
+			DrawFigure (gr, x, y, (FigureElement []) answers[(int)random_indices_answers[i]]);
+			gr.MoveTo (x, y + 0.2);
+			x+= 0.22;
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+		}
+	}
+}
+

Added: trunk/src/PuzzleGames/PuzzleMoveFigure.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleMoveFigure.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleMoveFigure: Game
+{
+	private int lines;
+	private int type;
+
+	public override string Name {
+		get {return Catalog.GetString ("Move figure");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the minimum number of circles to be moved in order to convert the left figure into the right figure?");} 
+	}
+	
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			switch (type) {
+			case 0:
+				answer += Catalog.GetString ("Move the circle from the first line to the second and move two circles from the fourth line to the second and the fifth lines.");
+				break;
+			case 1:
+				answer += Catalog.GetString ("Move the first line to the seventh; move the two circles of the second line to third; and move first and last circles of the fifth line to the sixth.");
+				break;
+			}
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{	
+		type = random.Next (2);
+		lines = 4 + type;
+		
+		switch (type)
+		{
+			case 0:
+				right_answer = "3";
+				break;
+			case 1:
+				right_answer = "5";
+				break;
+		}
+		
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double first_x, x, y;
+		double figure_size = 0.07 + (0.01 * (5 - lines));
+		double margin = 0;
+
+		base.Draw (gr, area_width, area_height);
+
+		// Figure 1
+		margin = ((1.0 - (figure_size * lines * 2)) / 2);
+
+		x = first_x = margin + (figure_size * lines / 2) + figure_size / 2;
+		y = DrawAreaY;
+		for (int line = 0; line < lines + 1; line++)
+		{
+			for (int circles = 0; circles < line; circles++)
+			{
+				gr.Arc (x, y, figure_size / 2, 0, 2 * Math.PI);	
+				gr.Stroke ();
+				x += figure_size;
+			}
+			x = first_x = first_x - (figure_size / 2);
+			y += figure_size;			
+		}
+
+		// Figure 2
+		first_x = margin + (figure_size * lines);
+		y = DrawAreaY + figure_size;
+		for (int line = 0; line < lines; line++)
+		{
+			x = first_x = first_x + (figure_size / 2);
+			for (int circles = 0; circles < lines - line; circles++)
+			{
+				gr.Arc (x, y, figure_size / 2, 0, 2 * Math.PI);	
+				gr.Stroke ();
+				x += figure_size;
+			}
+			y += figure_size;			
+		}
+
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleNextFigure.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleNextFigure.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleNextFigure : Game
+{
+	private const double figure_size = 0.2;
+	private ArrayListIndicesRandom random_indices;
+
+	public enum CerclePosition 
+	{
+		None		= 0,
+		Top		= 2,
+		Right		= 4,
+		Bottom		= 8,
+		Left		= 16,
+	}
+
+	enum Figures
+	{
+		First,
+		Second,
+		Third,
+		Last
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Next figure");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which is the next logical figure in the sequence? Answer A, B or C.");} 
+	}
+
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			answer += String.Format (Catalog.GetString ("From first figure, the top circle advances by two positions clockwise, while the left circle goes backwards one position."));
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom ((int) Figures.Last);
+		random_indices.Initialize ();
+
+		for (int i = 0; i < (int) Figures.Last; i++)
+		{
+			if ((int) random_indices[i] == (int) Figures.Third) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+	}
+
+	private void DrawDiamon (CairoContextEx gr, double x, double y, CerclePosition cercles)
+	{	
+		double distance = 0.04;
+
+		gr.MoveTo (x + figure_size / 2, y);
+		gr.LineTo (x, y + figure_size / 2);
+		gr.LineTo (x + figure_size / 2, y + figure_size);
+		gr.LineTo (x + figure_size, y + figure_size / 2);
+		gr.LineTo (x + figure_size / 2, y);
+		gr.Stroke ();
+
+		if ((cercles & CerclePosition.Top) == CerclePosition.Top) {
+			gr.Arc (x + figure_size / 2, y + distance, 0.01, 0, 2 * Math.PI);	
+			gr.Stroke ();
+		}
+
+		if ((cercles & CerclePosition.Right) == CerclePosition.Right) {
+			gr.Arc (x + figure_size - distance, y + figure_size / 2, 0.01, 0, 2 * Math.PI);	
+			gr.Stroke ();
+		}
+
+		if ((cercles & CerclePosition.Bottom) == CerclePosition.Bottom) {
+			gr.Arc (x + figure_size / 2, y + figure_size - distance, 0.01, 0, 2 * Math.PI);	
+			gr.Stroke ();
+		}
+
+		if ((cercles & CerclePosition.Left) == CerclePosition.Left) {
+			gr.Arc (x + distance, y + figure_size / 2, 0.01, 0, 2 * Math.PI);
+			gr.Stroke ();
+		}
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX;
+		double y = DrawAreaY;
+		double space_figures = figure_size + 0.1;
+		
+		base.Draw (gr, area_width, area_height);
+
+		DrawDiamon (gr, x, y, CerclePosition.Top | CerclePosition.Left);
+		DrawDiamon (gr, x + space_figures , y, CerclePosition.Bottom);
+		DrawDiamon (gr, x + space_figures * 2, y, CerclePosition.Top | CerclePosition.Right);
+		
+		y += figure_size + 0.10;
+		gr.MoveTo (x, y);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+		gr.Stroke ();
+		y += 0.06;
+
+		for (int i = 0; i < (int) Figures.Last; i++)
+		{
+		 	switch ((Figures) random_indices[i]) {
+			case Figures.First:
+				DrawDiamon (gr, x, y, CerclePosition.Right | CerclePosition.Left);
+				break;
+			case Figures.Second:
+				DrawDiamon (gr, x, y, CerclePosition.Top | CerclePosition.Right);
+				break;
+			case Figures.Third:
+				DrawDiamon (gr, x, y, CerclePosition.Bottom | CerclePosition.Top);
+				break;
+			}
+			
+			gr.MoveTo (x + 0.02, y + 0.25);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+			x += space_figures;			
+		}
+
+		gr.Stroke ();
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleNumericRelation.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleNumericRelation.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleNumericRelation : Game
+{
+	private const int group_size = 3;
+	private int sum_value;
+	private int question;
+	private int[] numbers;
+	private int formula;
+	private const int max_num = 9;
+
+	public override string Name {
+		get {return Catalog.GetString ("Numeric relation");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What number should replace the question mark?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The numbers are related arithmetically.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			switch (formula) {
+			case 0:
+				answer += String.Format (Catalog.GetString ("Every group of {0} numbers sums exactly {1}."), group_size, sum_value);
+				break;
+			case 1:
+				answer += Catalog.GetString ("Divide the sequence in groups of three numbers. Every third number is calculated by multiplying by the two previous ones.");
+				break;
+
+			case 2:
+				answer += Catalog.GetString ("Divide the sequence in groups of three numbers. Every third number is calculated by subtracting the second number from the first.");
+				break;
+			}
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		int group = 0, inc = 0;
+
+		if (CurrentDifficulty == Difficulty.Easy) {
+			sum_value = 10 + random.Next (10);
+			inc = 5;
+		}
+		else {
+			sum_value = 30 + random.Next (10);
+			inc = 12;
+		}
+
+		question = 1 + random.Next (max_num - 2);
+		formula = random.Next (3);
+		numbers =  new int [max_num];
+		
+		for (int i = 0; i < max_num; i++) {
+			if (group == group_size - 1) {	
+				switch (formula) {
+				case 0:
+					numbers[i] = sum_value - numbers[i - 1] - numbers[i - 2];
+					break;
+				case 1:
+					numbers[i] = numbers[i - 1] * numbers[i - 2];
+					break;
+				case 2:
+					numbers[i] = numbers[i - 2] - numbers[i - 1];
+					break;
+				}
+				group = 0;
+				continue;
+			}
+			numbers[i] = 1 + random.Next (inc);
+			group++;
+		}
+
+		right_answer = numbers[question].ToString ();
+	}
+
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		StringBuilder sequence = new StringBuilder (64);
+
+		base.Draw (gr, area_width, area_height);
+
+		gr.SetLargeFont ();
+
+		for (int num = 0; num < max_num - 1; num++)
+		{
+			if (num == question) {
+				sequence.Append ("?, ");
+			} else {
+				sequence.Append (numbers[num]);
+				sequence.Append (", ");
+			}
+		}
+		sequence.Append (numbers[max_num - 1]);
+		gr.DrawTextCentered (0.5, DrawAreaY + 0.3, sequence.ToString ());
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleNumericSequence.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleNumericSequence.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2007 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 System.Text;
+using Mono.Unix;
+
+public class PuzzleNumericSequence : Game
+{
+	private const int max_num = 6;
+	private int[] numbers;
+	private int formula;
+
+	public override string Name {
+		get {return Catalog.GetString ("Numeric sequence");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("The next sequence follows a logic. What number should replace the question mark?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Every number in the sequence is related to the previous one.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			switch (formula) {
+			case 0:
+				answer += Catalog.GetString ("Every number in the sequence is the result of subtracting 1 from the previous number and multiplying it by 2.");
+				break;
+			case 1:
+				answer += Catalog.GetString ("Every number in the sequence is the result of adding 1 to the previous number and multiplying it by 3.");
+				break;
+			case 2:
+				answer += Catalog.GetString ("Every number in the sequence is the result of subtracting 2 from the previous number and multiplying it by -2.");
+				break;
+			}
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		formula = random.Next (CurrentDifficulty == Difficulty.Easy ? 2 : 3);
+		numbers =  new int [max_num];
+		numbers[0] = 3 + random.Next (3);
+		for (int i = 1; i < max_num; i++) {
+			switch (formula) {
+			case 0:
+				numbers[i] = (numbers[i - 1] - 1) * 2;
+				break;
+			case 1:
+				numbers[i] = (numbers[i - 1] + 1) * 3;
+				break;
+			case 2:
+				numbers[i] = (numbers[i -1] - 2) * (-2);
+				break;
+			}				
+		}
+
+		right_answer = numbers[max_num-1].ToString ();
+	}
+
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		StringBuilder sequence = new StringBuilder (64);
+
+		base.Draw (gr, area_width, area_height);
+		gr.SetLargeFont ();
+
+		for (int num = 0; num < max_num - 1; num++)
+		{
+			sequence.Append (numbers[num]);
+			sequence.Append (", ");
+		}
+		sequence.Append ("?");
+
+		gr.DrawTextCentered (0.5, DrawAreaY + 0.3, sequence.ToString ());
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleOstracism.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleOstracism.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleOstracism : Game
+{
+	private ArrayListIndicesRandom random_indices;
+	private const int wrong_answer = 2;
+	private string [] equations = new string []
+	{
+		"21 x 60 = 1260",
+		"15 x 93 = 1395",
+		"70 x 16 = 1120",
+		"43 x 51 = 1453",
+		"80 x 16 = 1806",
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Ostracism");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which equation does not belong to the group? Answer A, B, C, D or E.");} 
+	}
+
+
+	public override string Tip {
+		get { return Catalog.GetString ("The criteria for deciding if an equation belongs to the group is not arithmetical.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("In all equations the digits from the left side should also appear in the right side.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom (equations.Length);
+		random_indices.Initialize ();
+		right_answer = string.Empty;
+
+		for (int i = 0; i < random_indices.Count; i++)
+		{
+			if (random_indices[i] == wrong_answer) {
+				right_answer += ((char) (65 + i));
+				break;
+			}
+		}
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.15, y = DrawAreaY + 0.2;
+
+		base.Draw (gr, area_width, area_height);
+
+		gr.SetLargeFont ();		
+		for (int i = 0; i < random_indices.Count; i++)
+		{
+			gr.MoveTo (x, y);
+			gr.ShowText (((char)( 65 + i)) + ") " +  equations [random_indices[i]]);
+			y += 0.1;
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzlePencil.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzlePencil.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzlePencil : Game
+{
+	private ArrayListIndicesRandom random_indices;
+	private const double figure_width = 0.1, figure_height = 0.1, space_width = 0.1, space_height = 0.15;
+	private const double figure_size = 0.2;
+	private const int figures = 5;
+	private const int answer_index = 4;
+
+	public override string Name {
+		get {return Catalog.GetString ("Pencil");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which of the following figures cannot be drawn without crossing any previous lines nor lifting the pencil? Answer A, B, C, D or E.");} 
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom (figures);
+		random_indices.Initialize ();
+		right_answer = string.Empty;
+
+		for (int i = 0; i < random_indices.Count; i++) {
+			if (random_indices[i] != answer_index)
+				continue;
+			
+			right_answer += (char) (65 + (int) i);
+			break;
+		}	
+	}
+
+	private void DrawTriangle (CairoContextEx gr, double x, double y)
+	{
+		gr.MoveTo (x + (figure_size / 2), y);
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.LineTo (x + (figure_size / 2), y);
+		gr.LineTo (x + (figure_size / 2), y + figure_size);
+		gr.Stroke ();	
+	}
+
+	private void DrawDiamon (CairoContextEx gr, double x, double y)
+	{
+		gr.MoveTo (x, y);
+		gr.LineTo (x - (figure_size / 2), y + (figure_size / 2));
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size / 2, y + (figure_size / 2));
+		gr.LineTo (x, y);
+		gr.LineTo (x, y + figure_size);
+		gr.Stroke ();
+	}
+
+	private void DrawRectangleWithTriangles (CairoContextEx gr, double x, double y)
+	{
+		gr.Rectangle (x, y, figure_size, figure_size);
+		gr.Stroke ();	
+	
+		gr.MoveTo (x, y + figure_size);
+		gr.LineTo (x + figure_size / 4, y);
+		gr.LineTo (x + figure_size / 2, y + figure_size);
+
+		gr.Stroke ();		
+	
+		gr.MoveTo (x + figure_size / 2, y + figure_size);
+		gr.LineTo (x + figure_size / 4 * 3, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+
+		gr.Stroke ();
+	}
+
+	private void DrawThreeTriangles (CairoContextEx gr, double x, double y)
+	{
+		gr.MoveTo (x, y);
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size, y);
+		gr.LineTo (x, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.LineTo (x + figure_size, y);
+
+		gr.Stroke ();
+		
+	}
+
+	private void DrawHouse (CairoContextEx gr, double x, double y)
+	{
+		gr.MoveTo (x, y + figure_size);
+		gr.LineTo (x, y + figure_size / 2);
+		gr.LineTo (x + figure_size / 2, y);
+		gr.LineTo (x + figure_size, y + figure_size / 2);
+		gr.LineTo (x, y + figure_size / 2);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.LineTo (x + figure_size, y + figure_size / 2);
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.Stroke ();
+		
+	}
+
+	private void DrawRectangleWithCross (CairoContextEx gr, double x, double y)
+	{
+		gr.Rectangle (x, y, figure_size, figure_size);
+
+		gr.MoveTo (x, y);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.Stroke ();
+
+		gr.MoveTo (x + figure_size, y);
+		gr.LineTo (x, y + figure_size);
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int figure = 0; figure < figures; figure++)
+		{
+			switch (random_indices[figure]) {
+			case 0:
+				DrawTriangle (gr, x, y);
+				break;
+			case 1:
+				DrawDiamon (gr, x + 0.1, y);
+				break;
+			//case 2:
+			//	DrawHouse (gr, x, y);				
+			//	break;
+			case 2:
+				DrawRectangleWithTriangles (gr, x, y);
+				break;
+			case 3:
+				DrawThreeTriangles (gr, x, y);
+				break;
+			case answer_index:
+				DrawRectangleWithCross (gr, x, y);
+				break;
+			
+			}			
+						
+			gr.MoveTo (x, y + figure_size + 0.05);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + figure)));
+
+			if (figure == 2) {
+				x = DrawAreaX;
+				y += figure_size + space_height;
+
+			} else {						
+				x += figure_size + space_width;		
+			}
+		}
+
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzlePeopleTable.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzlePeopleTable.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzlePeopleTable : Game
+{
+	private const double figure_size = 0.15;
+	private string ques1, ques2;
+	
+	private class Circle
+	{	
+		public double x;
+		public double y;
+
+		public Circle (double x, double y) 
+		{
+			this.x = x;
+			this.y = y;
+		}
+	}
+
+	public override string Name {
+		get {return Catalog.GetString ("People at a table");}
+	}
+
+	public override string Question {
+		get {return String.Format (Catalog.GetString ("A group of people are sitting at round table, evenly spaced out. How many people are there if the {0} person is across from the {1}?"), ques1, ques2);} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("Subtracting the two positions you find out how many people are seated half way around the table. Doubling this number leaves you with the total amount of people.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		switch (random.Next (3)) {
+		case 0:
+			ques1 = Catalog.GetString ("5th");
+			ques2 = Catalog.GetString ("19th");
+			right_answer = "28";
+			break;
+		case 1:
+			ques1 = Catalog.GetString ("4th");
+			ques2 = Catalog.GetString ("12th");
+			right_answer = "16";
+			break;
+		case 2:
+			ques1 = Catalog.GetString ("9th");
+			ques2 = Catalog.GetString ("22nd");
+			right_answer = "26";
+			break;
+		}			
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.22, y = DrawAreaY + 0.2;
+		double pos_x = x;
+		double pos_y = y;
+		Circle[] circles = null;
+
+		base.Draw (gr, area_width, area_height);
+
+		circles =  new Circle [] {
+			new Circle (0.01, 0.06),
+			new Circle (0.27, 0.06),
+			new Circle (0.01, 0.21),
+			new Circle (0.27, 0.21),
+			new Circle (0.14, 0),
+			new Circle (0.14, 0.29)
+		};
+
+		// Circle
+		gr.Arc (pos_x + figure_size, pos_y + figure_size, figure_size, 0, 2 * Math.PI);
+		gr.Stroke ();		
+
+		double point_size = 0.01;
+		for (int i = 0; i < circles.Length; i++) {
+			gr.Arc (x + point_size + circles[i].x, y + point_size + circles[i].y, point_size, 0, 2 * Math.PI);
+			gr.Fill ();
+			gr.Stroke ();
+		}
+
+		gr.MoveTo (x + circles[2].x + 0.01, y + circles[2].y + 0.01);
+		gr.LineTo (x + circles[1].x + 0.01, y + circles[1].y + 0.01);
+		gr.Stroke ();
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleQuadrilaterals.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleQuadrilaterals.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 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;
+
+public class PuzzleQuadrilaterals : Game
+{
+	enum Figures
+	{
+		FigureA,
+		FigureB,
+		FigureC,
+		FigureD,
+		FigureE,
+		FigureF,
+		Last
+	};
+
+	private ArrayListIndicesRandom random_indices;
+	private const double figure_size = 0.15;
+
+	public override string Name {
+		get {return Catalog.GetString ("Quadrilaterals");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which of the following figures does not belong to the group? Answer A, B, C, D, E or F.");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("It is the only figure with all lines of equal length.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices = new ArrayListIndicesRandom ((int) Figures.Last);
+		random_indices.Initialize ();
+
+		for (int i = 0; i < (int) Figures.Last; i++)
+		{
+			if ((Figures) random_indices[i] == Figures.FigureA) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+	}
+
+	private void DrawFigure (CairoContextEx gr, double x, double y, Figures figure)
+	{
+		switch (figure) {
+		case Figures.FigureA:
+			double x105, y105;
+
+			x105 = figure_size * Math.Cos (105 * Math.PI / 180);
+			y105 = figure_size * Math.Sin (105 * Math.PI / 180);
+			gr.MoveTo (x, y);
+			gr.LineTo (x + x105, y + y105);
+			gr.LineTo (x + x105 + figure_size, y + y105);
+			gr.Stroke ();
+			gr.MoveTo (x + figure_size, y);
+			gr.LineTo (x + figure_size + x105, y + y105);
+			gr.Stroke ();
+			gr.MoveTo (x, y);
+			gr.LineTo (x + figure_size, y);
+			break;
+
+		case Figures.FigureB:
+			gr.Rectangle (x, y, figure_size * 0.8, figure_size * 1.2);
+			break;
+
+		case Figures.FigureC:
+			gr.MoveTo (x, y);
+			gr.LineTo (x + figure_size * 1.3, y);
+			gr.LineTo (x + figure_size * 1.3, y + figure_size);
+			gr.LineTo (x , y + figure_size);
+			gr.LineTo (x, y);
+			break;
+
+		case Figures.FigureD:
+			gr.MoveTo (x + 0.03, y);
+			gr.LineTo (x + figure_size - 0.03, y);
+			gr.LineTo (x + figure_size, y + figure_size);
+			gr.LineTo (x , y + figure_size);
+			gr.LineTo (x + 0.03, y);
+			break;
+
+		case Figures.FigureE:
+			gr.MoveTo (x + 0.03, y);
+			gr.LineTo (x + figure_size - 0.04, y);
+			gr.LineTo (x + figure_size - 0.04, y + figure_size);
+			gr.LineTo (x , y + figure_size);
+			gr.LineTo (x + 0.03, y);;
+			break;
+
+		case Figures.FigureF:
+			gr.MoveTo (x, y);
+			gr.LineTo (x, y + figure_size);
+			gr.LineTo (x + figure_size, y + figure_size);
+			gr.LineTo (x + figure_size - 0.02, y);
+			gr.LineTo (x, y);
+			break;
+		}
+
+		gr.Stroke ();
+
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY, space_x = 0.15;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int i = 0; i < random_indices.Count; i++) {
+			DrawFigure (gr, x, y, (Figures) random_indices[i]);
+			gr.MoveTo (x, y + figure_size * 1.6);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+
+			if (i == 2) {
+				x = DrawAreaX;
+				y += figure_size * 3;
+			} else 
+				x += figure_size + space_x;
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleSquareDots.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleSquareDots.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleSquareDots : Game
+{
+	private const double figure_size = 0.25; 
+	private const int lines = 6;
+	private const int columns = 6;
+	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 []
+	{
+		// Figure A
+		O, O, O, O, O, O,
+		O, O, O, O, O, O, 	
+		O, O, X, X, O, O,	// Down, Diagonal down left
+		O, O, X, X, O, O,	// Up, Diagonal up left
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		
+		// Figure B
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, X, O, O, O,
+		O, O, X, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+
+		// Figure C
+		O, O, O, O, O, O,
+		O, X, X, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, X, X, O, O, O,
+		O, O, O, O, O, O,
+
+		// Wrong answer 1
+		O, X, X, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, X, X, O, O, O,
+
+		// Correct Answer
+		X, O, X, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		X, O, X, O, O, O,
+
+		// Wrong answer 2
+		O, O, O, O, O, O,
+		O, X, X, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, O, O, O, O, O,
+		O, X, X, O, O, O,
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Square with dots");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the letter of the figure that represents the next logical figure in the sequence? Answer A, B or C.");} 
+	}
+
+	public override void Initialize ()
+	{
+		possible_answers = new ArrayListIndicesRandom (3);
+		possible_answers.Initialize ();
+
+		for (int i = 0; i < possible_answers.Count; i++) {
+			if (possible_answers[i] == 0) {
+				right_answer += (char) (65 + (int) i);
+				break;
+			}
+		}
+	}
+
+	public void DrawFigure (CairoContextEx gr, double x, double y, bool [] puzzle, int index)
+	{
+		double pos_x = x, pos_y = y;
+		double square_size = figure_size / lines;
+		double center_square = square_size / 2;
+		double radius_square = (square_size - (LineWidth *2)) / 2;
+
+		gr.Rectangle (pos_x, pos_y, figure_size, figure_size);
+		gr.Stroke ();
+
+		for (int line = 0; line < lines - 1; line++) // Horizontal
+		{
+			pos_y += square_size;
+			gr.MoveTo (pos_x, pos_y);
+			gr.LineTo (pos_x + figure_size, pos_y);
+			gr.Stroke ();
+		}
+
+		pos_y = y;
+		for (int column = 0; column < columns - 1; column++) // Vertical
+		{
+			pos_x += square_size;
+			gr.MoveTo (pos_x, pos_y);
+			gr.LineTo (pos_x, pos_y + figure_size);
+			gr.Stroke ();
+		}
+
+		pos_y = y + center_square;
+		pos_x = x + center_square;
+		
+		for (int line = 0; line < lines; line++) // Circles
+		{	
+			for (int column = 0; column < columns; column++)
+			{
+				if (puzzle[index + (columns * line) + column] == false)
+					continue;
+
+				gr.Arc (pos_x + (square_size * column), pos_y, radius_square, 0, 2 * Math.PI);
+				gr.Stroke ();
+			}
+			pos_y += square_size;
+		}
+	}
+
+	public void DrawPossibleAnswer (CairoContextEx 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 (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY;
+
+		base.Draw (gr, area_width, area_height);
+
+		DrawFigure (gr, x, y, puzzle_A, 0);
+		DrawFigure (gr, x + figure_size + space_figures, y, puzzle_A, columns * lines);
+		DrawFigure (gr, x + (figure_size + space_figures) * 2, y, puzzle_A, columns * lines * 2);
+	
+		y += figure_size + 0.10;
+		gr.MoveTo (x, y);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+		gr.Stroke ();
+		y += 0.05;
+
+		for (int i = 0; i < possible_answers.Count; i++) {
+			DrawPossibleAnswer (gr, x, y, 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;
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleSquareSheets.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleSquareSheets.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleSquareSheets : Game
+{
+
+	public override string Name {
+		get {return Catalog.GetString ("Squares sheets");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What is the minimum number of square sheets of paper of any size required to create the figure? Lines indicate frontiers between different sheets.");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("The sheets should overlap.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("The numbers in the figure reflect the different areas covered by each one of the sheets.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		right_answer = "5";
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.2, y = DrawAreaY + 0.2, width = 0.4, height = 0.4;
+
+		base.Draw (gr, area_width, area_height);
+
+		gr.Rectangle (x, y, width, height);
+		gr.Stroke ();
+		
+		gr.MoveTo (x, y + 0.1);
+		gr.LineTo (x + width, y + 0.1);  // First horizontal
+		gr.Stroke ();
+
+		gr.MoveTo (x, y + 0.3);
+		gr.LineTo (x + width - 0.1, y + 0.3); // Second horizontal
+		gr.Stroke ();
+
+		gr.MoveTo (x + 0.1, y);
+		gr.LineTo (x + 0.1, y + height);  // First vertical
+		gr.Stroke ();
+
+		gr.MoveTo (x + 0.3, y);
+		gr.LineTo (x + 0.3, y + height - 0.1);  // Second vertical
+		gr.Stroke ();
+
+		if (DrawAnswer == false)
+			return;
+
+		gr.LineTo (x + 0.04, y + 0.06);
+		gr.ShowText ("1");
+
+		gr.LineTo (x + 0.18, y + 0.06);
+		gr.ShowText ("2");
+
+		gr.LineTo (x + 0.34, y + 0.06);
+		gr.ShowText ("3");
+		
+		gr.LineTo (x + 0.04, y + 0.2);
+		gr.ShowText ("2");
+
+		gr.LineTo (x + 0.18, y + 0.2);
+		gr.ShowText ("4");
+
+		gr.LineTo (x + 0.34, y + 0.2);
+		gr.ShowText ("5");
+
+		gr.LineTo (x + 0.04, y + 0.36);
+		gr.ShowText ("3");
+
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleSquares.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleSquares.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+
+public class PuzzleSquares : Game
+{
+	private double rows, columns;
+	private int type;
+
+	public override string Name {
+		get {return Catalog.GetString ("Squares");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many squares of any size do you count of in the figure below?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("A square is a rectangle with sides of equal length. A square can also be built from other squares.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			switch (type) {
+			case 0:
+				answer += Catalog.GetString ("There are 16 single squares, 9 squares made by 4 single squares, 4 squares made by 9 single squares and 1 square made by 16 single squares.");
+				break;
+			case 1:
+				answer += Catalog.GetString ("There are 9 single squares, 4 squares made by 4 single squares and 1 square made by 9 single squares.");
+				break;
+			}
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		if (CurrentDifficulty==Difficulty.Easy)
+			type = 0;
+		else
+			type = random.Next (2);
+
+		rows = 3;
+		columns = 3;		
+
+		if (type == 0) {
+			rows++;
+			columns++;
+			right_answer = "30";
+		} else {
+			right_answer = "14";
+		}
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double rect_w = DrawAreaWidth / rows;
+		double rect_h = DrawAreaHeight / columns;
+
+		base.Draw (gr, area_width, area_height);
+
+		for (int column = 0; column < columns; column++) {
+			for (int row = 0; row < rows; row++) {
+				gr.Rectangle (DrawAreaX + row * rect_w, DrawAreaY + column * rect_h, rect_w, rect_h);
+			}
+		}
+
+		gr.Stroke ();
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleSquaresAndLetters.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleSquaresAndLetters.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleSquaresAndLetters : Game
+{
+	private char[] characters;
+	private int step;
+	private const double figure_size = 0.2;
+	private const int figures = 3;
+
+	public override string Name {
+		get {return Catalog.GetString ("Squares and letters");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("The letters around the squares follow a logic. Which letter should replace the question mark in the last square?");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("Every letter is calculated by taking the alphabetical position of the previous character and adding {0} to it in order to get the position of the new letter."), step);
+
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		int first_letter;
+		ArrayListIndicesRandom first_letters;
+
+		first_letters = new ArrayListIndicesRandom (figures); // Make sure that the first letter is never the same
+		first_letters.Initialize ();
+		step = random.Next (3) + 3;
+
+		characters = new char [(1 + figures) * 4]; 
+		for (int figure = 0; figure < figures; figure++) {
+			first_letter = first_letters [figure];
+			for (int letter = 0; letter < 4; letter++) {
+				characters[(figure * 4) + letter] = (char) (65 + first_letter + (step * letter));
+			}				
+		}
+
+		right_answer = ToStr (characters[((figures - 1) * 4) + 3]);
+		characters[((figures - 1) * 4) + 3] = '?';
+	}
+
+	private string ToStr (char ch)
+	{
+		string s = string.Empty;
+		s+= ch;
+		return s;
+	}
+
+	private void DrawRectangleWithText (CairoContextEx gr, double x, double y, int index)
+	{
+		gr.Rectangle (x, y, figure_size, figure_size);
+
+		gr.MoveTo (x - 0.04, y);
+		gr.ShowText (ToStr (characters [index]));
+		gr.Stroke ();
+
+		gr.MoveTo (x + 0.01 + figure_size, y);
+		gr.ShowText (ToStr (characters [index + 1]));
+		gr.Stroke ();
+
+		gr.MoveTo (x - 0.04, y + figure_size);
+		gr.ShowText (ToStr (characters [index + 2]));
+		gr.Stroke ();
+
+		gr.MoveTo (x + 0.01 + figure_size, y + figure_size);
+		gr.ShowText (ToStr (characters [index + 3]));
+		gr.Stroke ();
+	}
+
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.05, y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+		
+		DrawRectangleWithText (gr, x, y, 0);
+		DrawRectangleWithText (gr, x + figure_size + 0.2, y, 4);
+		DrawRectangleWithText (gr, x + figure_size + 0.05, y + 0.2 + figure_size, 8);
+			
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleTetris.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleTetris.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2007 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 Cairo;
+using Mono.Unix;
+using System;
+
+public class PuzzleTetris : Game
+{
+	private ArrayListIndicesRandom random_indices_questions;
+	private ArrayListIndicesRandom random_indices_answers;
+	private const double rect_witdh = 0.04, rect_height = 0.04, space_figures = 0.22;
+
+	public override string Name {
+		get {return Catalog.GetString ("Tetris");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("What figure completes the sequence below? Answer A, B or C.");} 
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += Catalog.GetString ("It is the figure that completes all possible combinations with four blocks without taking into account rotations.");
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		random_indices_questions = new ArrayListIndicesRandom (4);
+		random_indices_questions.Initialize ();
+
+		random_indices_answers = new ArrayListIndicesRandom (3);
+		random_indices_answers.Initialize ();
+
+		for (int i = 0; i < random_indices_answers.Count; i++) {
+			if ((int) random_indices_answers [i] == 0) {
+				right_answer += (char) (65 + i);
+				break;
+			}
+		}
+	}
+
+	private void DrawQuestionFigures (CairoContextEx gr, double x, double y, int figure)
+	{
+		switch (figure) {
+		case 0:
+			// XX
+			// XX
+			for (int i = 0; i < 2; i++) {
+				gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
+				gr.Rectangle (x + i * rect_witdh, y - rect_height, rect_witdh, rect_height);
+			}
+			gr.Stroke ();
+			break;
+		case 1:
+			//  X
+			// XXX
+			for (int i = 0; i < 3; i++) {
+				gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
+			}
+			gr.Rectangle (x + 1 * rect_witdh, y - rect_height, rect_witdh, rect_height);
+			gr.Stroke ();
+			break;
+		case 2:
+			//   X
+			// XXX
+			for (int i = 0; i < 3; i++) {
+				gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
+			}
+			gr.Rectangle (x + 2 * rect_witdh, y - rect_height, rect_witdh, rect_height);
+			gr.Stroke ();
+			break;
+		case 3:
+			// XXXX
+			for (int i = 0; i < 4; i++) {
+				gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
+			}
+			gr.Stroke ();
+			break;
+		}
+	}
+
+	private void DrawAnswerFigures (CairoContextEx gr, double x, double y, int figure)
+	{
+		switch (figure) {
+		case 0:
+			//  XX
+			// XX
+			for (int i = 0; i < 2; i++) {
+				gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
+				gr.Rectangle (x + rect_witdh + i * rect_witdh, y -  rect_height, rect_witdh, rect_height);
+			}
+			break;
+		case 1:
+			// X
+			// X
+			// X
+			// X
+			for (int i = 0; i < 4; i++) {
+				gr.Rectangle (x, y -  rect_height * i, rect_witdh, rect_height);
+			}
+			break;
+		case 2:
+			// XXX
+			//  X
+			for (int i = 0; i < 3; i++) {
+				gr.Rectangle (x + i * rect_witdh, y - rect_height, rect_witdh, rect_height);
+			}
+			gr.Rectangle (x + rect_witdh, y, rect_witdh, rect_height);
+			break;
+		}
+		gr.Stroke ();
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+		
+		for (int i = 0; i < 4; i++) {
+			DrawQuestionFigures (gr, x, y, random_indices_questions [i]);
+			x += space_figures;
+		}
+
+		gr.MoveTo (0.1, 0.4);
+		gr.ShowText (Catalog.GetString ("Possible answers are:"));
+
+		x = 0.2;
+		y = 0.6;
+		for (int i = 0; i < 3; i++) {
+			DrawAnswerFigures (gr, x, y, random_indices_answers [i]);
+			gr.MoveTo (x, y + 0.15);
+			gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
+			x += space_figures;
+		}
+	}
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleTriangles.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleTriangles.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleTriangles : Game
+{
+	int type;
+	public override string Name {
+		get {return Catalog.GetString ("Triangles");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("How many triangles of any size do you count in the figure below?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("A triangle can be embedded inside another triangle.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+
+			answer += String.Format (Catalog.GetString ("The triangles are made by connecting the following points: {0}"),
+				(type == 0) ? "bdc, dcf, dfg, abd, ade, edg, acg, abg, bcg, afg, ecg, acd, acf, ace, adg, cdg." : 
+				"dcf, ade, acg, afg, ecg, acd, acf, ace.");
+
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		if (CurrentDifficulty==Difficulty.Easy)
+			type = 1;
+		else
+			type = random.Next (2);
+
+		if (type == 0)	
+			right_answer = "16";
+		else
+			right_answer = "8";
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX + 0.1, y = DrawAreaY + 0.2;
+		double witdh = 0.6, height = 0.5;
+
+		base.Draw (gr, area_width, area_height);
+		
+		gr.MoveTo (x, y);
+		gr.LineTo (x + witdh, y);		
+		gr.LineTo (x + witdh / 2, y + height / 2);
+		gr.LineTo (x, y);
+		gr.LineTo (x + 0.45, y + height /4);
+		gr.Stroke ();
+	
+		if (type == 0) {
+			gr.MoveTo (x + witdh / 2, y);
+			gr.LineTo (x + witdh / 2, y + height / 2);
+			gr.Stroke ();
+		}
+
+		gr.MoveTo (x + 0.152, y + 0.125);
+		gr.LineTo (x + witdh, y);
+		gr.Stroke ();
+
+		if (DrawAnswer == false)
+			return;
+
+		// References
+		gr.MoveTo (x - 0.02, y - 0.02);
+		gr.ShowText ("a");
+
+		gr.MoveTo (x + witdh /2  - 0.02, y - 0.02);
+		gr.ShowText ("b");
+
+		gr.MoveTo (x + witdh, y - 0.02);
+		gr.ShowText ("c");
+
+		gr.MoveTo (x + witdh /2  - 0.03, y + 0.09 - 0.02);
+		gr.ShowText ("d");
+
+		gr.MoveTo (x + 0.11, y + 0.16 - 0.02);
+		gr.ShowText ("e");
+
+		gr.MoveTo (x + 0.47, y + 0.16 - 0.02);
+		gr.ShowText ("f");
+
+		gr.MoveTo (x + (witdh /2) - 0.01, y + 0.28);
+		gr.ShowText ("g");
+
+	}
+
+}
+
+

Added: trunk/src/PuzzleGames/PuzzleTrianglesWithNumbers.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleGames/PuzzleTrianglesWithNumbers.cs	Mon Jul 21 16:37:04 2008
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2007 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;
+
+public class PuzzleTrianglesWithNumbers : Game
+{
+	private const double figure_size = 0.2;
+	private const int elements_group = 12;
+	private int group;
+	private string answer_number;
+	private int [] numbers = new int []
+	{
+		15, 14,	// 210
+		35, 6,
+		70, 3,
+		42, 5,
+		7, 30,
+		21, 10,		
+		
+		8, 20,	// 160
+		5, 32,
+		40, 4,
+		2, 80,
+		10, 16,
+		1, 160,
+
+		6, 20,  // 120
+		40, 3,
+		4, 30,
+		15, 8,
+		24, 5,
+		2, 60,
+	};
+
+	public override string Name {
+		get {return Catalog.GetString ("Triangles with numbers");}
+	}
+
+	public override string Question {
+		get {return Catalog.GetString ("Which number should replace the question mark below?");} 
+	}
+
+
+	public override string Tip {
+		get { return Catalog.GetString ("All the triangles share a property and are independent of the rest.");}
+	}
+
+	public override string Answer {
+		get { 
+			string answer = base.Answer + " ";
+			answer += String.Format (Catalog.GetString ("The result of multiplying the two numbers inside every triangle is {0}."), answer_number);
+			return answer;
+		}
+	}
+
+	public override void Initialize ()
+	{
+		group = random.Next (3);
+		switch (group) {
+		case 0:
+			right_answer = "10";
+			answer_number = "210";
+			break;
+		case 1:
+			right_answer = "160";
+			answer_number = "160";
+			break;
+		case 2:
+			right_answer = "60";
+			answer_number = "120";
+			break;
+		}
+	}
+
+
+	private void DrawTriangle (CairoContextEx gr, double x, double y, int index, bool question)
+	{
+		gr.MoveTo (x + figure_size / 2, y);
+		gr.LineTo (x, y + figure_size);
+		gr.LineTo (x + figure_size, y + figure_size);
+		gr.LineTo (x + figure_size / 2, y);
+		gr.LineTo (x + figure_size / 2, y + figure_size);
+		gr.Stroke ();
+
+		gr.MoveTo (x + 0.04, y + 0.17);
+		gr.ShowText (numbers [(elements_group * group) + index * 2].ToString ());	
+		gr.MoveTo (x + 0.12, y + 0.17);
+
+		if (question == true)
+			gr.ShowText ("?");	
+		else
+			gr.ShowText (numbers [(elements_group * group) + (index * 2) + 1].ToString ());	
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+		base.Draw (gr, area_width, area_height);
+		
+		DrawTriangle (gr, x, y, 0, false);
+		x += 0.3;
+		DrawTriangle (gr, x, y, 1, false);
+		x += 0.3;
+		DrawTriangle (gr, x, y, 2, false);
+
+		y += 0.3;
+		x = DrawAreaX;	
+		DrawTriangle (gr, x, y, 3, false);
+		x += 0.3;
+		DrawTriangle (gr, x, y, 4, false);
+		x += 0.3;
+		DrawTriangle (gr, x, y, 5, true);
+	}
+
+}
+
+



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