[gbrainy] TimeNow & 3DCube puzzles



commit 922abda0ee46ad0f96c00ff6e6dc2dfe4ba79b4d
Author: Jordi Mas <jmas softcatala org>
Date:   Wed Oct 21 23:26:45 2009 +0200

    TimeNow & 3DCube puzzles

 po/POTFILES.in                   |    2 +
 src/CairoContextEx.cs            |   45 +++++++++++
 src/Game.cs                      |   18 ++--
 src/GameManager.cs               |    2 +
 src/Makefile.am                  |    2 +
 src/PuzzleGames/Puzzle3DCube.cs  |  157 ++++++++++++++++++++++++++++++++++++++
 src/PuzzleGames/PuzzleCube.cs    |    3 -
 src/PuzzleGames/PuzzleTimeNow.cs |   65 ++++++++++++++++
 8 files changed, 282 insertions(+), 12 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4fa4511..a315ece 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -33,6 +33,7 @@ src/MemoryGames/MemoryIndications.cs
 src/MemoryGames/MemoryNumbers.cs
 src/MemoryGames/MemoryWords.cs
 src/mono-addins-strings.xml
+src/PuzzleGames/Puzzle3DCube.cs
 src/PuzzleGames/PuzzleBalance.cs
 src/PuzzleGames/PuzzleBuildTriangle.cs
 src/PuzzleGames/PuzzleCirclesRectangle.cs
@@ -71,6 +72,7 @@ src/PuzzleGames/PuzzleSquaresAndLetters.cs
 src/PuzzleGames/PuzzleSquares.cs
 src/PuzzleGames/PuzzleSquareSheets.cs
 src/PuzzleGames/PuzzleTetris.cs
+src/PuzzleGames/PuzzleTimeNow.cs
 src/PuzzleGames/PuzzleTriangles.cs
 src/PuzzleGames/PuzzleTrianglesWithNumbers.cs
 src/VerbalAnalogies/Analogies.cs
diff --git a/src/CairoContextEx.cs b/src/CairoContextEx.cs
index 3fd15a0..27ffea2 100644
--- a/src/CairoContextEx.cs
+++ b/src/CairoContextEx.cs
@@ -320,6 +320,51 @@ public class CairoContextEx : Cairo.Context
 		((IDisposable)shadow).Dispose ();
 	}
 
+	public void DrawClock (double x, double y, double size, int hand_short, int hand_large)
+	{
+		const double radian = Math.PI / 180;
+		double radius = size / 2;
+		double x0, y0;
+		int num, degrees;
+
+		Arc (x, y, radius, 0, 2 * Math.PI);
+		Stroke ();
+		for (degrees = 0; degrees < 360; degrees+= 30) {
+			x0 = radius * Math.Cos (degrees * radian);
+			y0 = radius * Math.Sin (degrees * radian);
+			 // Small lines
+			MoveTo (x + 0.9 * x0, y + 0.9 * y0);
+			LineTo (x + x0, y + y0);
+			Stroke ();
+			// Numbers
+			num = (degrees / 30) + 3;
+			if (num > 12) num = num - 12;
+
+			DrawTextCentered (x + x0 * 0.75,  y + y0 * 0.75, num.ToString ());
+			Stroke ();
+		}
+
+		if (hand_large >=1 && hand_large <= 12 ) {
+			// Hand Large
+			degrees = (hand_large - 3) * 30;
+			x0 = radius * Math.Cos (degrees * radian);
+			y0 = radius * Math.Sin (degrees * radian);
+			MoveTo (x, y);
+			LineTo (x + x0 * 0.55, y + y0 * 0.55);
+			Stroke ();
+		}
+
+		if (hand_short >=1 && hand_short <= 12) {
+			// Hand Short
+			degrees = (hand_short - 3) * 30;
+			x0 = radius * Math.Cos (degrees * radian);
+			y0 = radius * Math.Sin (degrees * radian);
+			MoveTo (x, y);
+			LineTo (x + x0 * 0.4, y + y0 * 0.4);
+			Stroke ();
+		}
+	}
+
 	public void FillGradient (double x, double y, double w, double h, Cairo.Color color)
 	{
 		Save ();
diff --git a/src/Game.cs b/src/Game.cs
index 611d79e..4246c18 100644
--- a/src/Game.cs
+++ b/src/Game.cs
@@ -230,26 +230,26 @@ abstract public class Game
 	{
 		switch (answer) {
 			// Translators Note
-			// The following serie of answers may need to be adapted
+			// The following series of answers may need to be adapted
 			// in cultures with alphabets different to the Latin one.
 			// The idea is to enumerate a sequence of possible answers
 			// For languages represented with the Latin alphabet use 
 			// the same than English
-		case 0: // First possible answer for a serie (e.g.: Figure A)
+		case 0: // First possible answer for a series (e.g.: Figure A)
 			return Catalog.GetString ("A");
-		case 1: // Second possible answer for a serie
+		case 1: // Second possible answer for a series
 			return Catalog.GetString ("B");
-		case 2: // Third possible answer for a serie
+		case 2: // Third possible answer for a series
 			return Catalog.GetString ("C");
-		case 3: // Fourth possible answer for a serie
+		case 3: // Fourth possible answer for a series
 			return Catalog.GetString ("D");
-		case 4: // Fifth possible answer for a serie
+		case 4: // Fifth possible answer for a series
 			return Catalog.GetString ("E");
-		case 5: // Sixth possible answer for a serie
+		case 5: // Sixth possible answer for a series
 			return Catalog.GetString ("F");
-		case 6: // Seventh possible answer for a serie
+		case 6: // Seventh possible answer for a series
 			return Catalog.GetString ("G");
-		case 7: // Eighth possible answer for a serie
+		case 7: // Eighth possible answer for a series
 			return Catalog.GetString ("H");
 		default:
 			return string.Empty;
diff --git a/src/GameManager.cs b/src/GameManager.cs
index 728fb6b..33bf8d6 100644
--- a/src/GameManager.cs
+++ b/src/GameManager.cs
@@ -72,6 +72,8 @@ public class GameManager
 		typeof (PuzzleHandshakes),
 		typeof (PuzzleCounting),
 		typeof (PuzzlePercentage),
+		typeof (PuzzleTimeNow),
+		typeof (Puzzle3DCube),
 	};
 
 	static Type[] CalculationTrainersInternal = new Type[] 
diff --git a/src/Makefile.am b/src/Makefile.am
index e6e1c8e..d218055 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,6 +85,8 @@ GBRAINY_CSDISTFILES =				\
 	$(srcdir)/CalculationGames/CalculationProportions.cs \
 	$(srcdir)/CalculationGames/CalculationRatio.cs \
 	$(srcdir)/PuzzleGames/PuzzlePercentage.cs	\
+	$(srcdir)/PuzzleGames/PuzzleTimeNow.cs	\
+	$(srcdir)/PuzzleGames/Puzzle3DCube.cs	\
 	$(srcdir)/SimpleLabel.cs	\
 	$(srcdir)/Unix.cs	\
 	$(srcdir)/GameTips.cs	\
diff --git a/src/PuzzleGames/Puzzle3DCube.cs b/src/PuzzleGames/Puzzle3DCube.cs
new file mode 100644
index 0000000..4f7e9c6
--- /dev/null
+++ b/src/PuzzleGames/Puzzle3DCube.cs
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2009 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 Puzzle3DCube : Game
+{
+	int rows, columns, deepth;
+
+	public override string Name {
+		get {return Catalog.GetString ("Cube");}
+	}
+
+	public override string Question {
+		get {return String.Format (Catalog.GetString ("How many cubes can you count in the figure below? (not counting the figure) Answer using a number."));} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("A cube is a regular solid object having six congruent square faces.");}
+	}
+
+	public override void Initialize ()
+	{
+		int ans, max_random;
+
+		switch (CurrentDifficulty) {
+		case Difficulty.Easy:
+			max_random = 1;
+			break;
+		case Difficulty.Master:
+			max_random = 5;
+			break;
+		case Difficulty.Medium:
+		default:
+			max_random = 3;
+			break;		
+		}
+
+		rows = columns = deepth = 4 + random.Next (max_random);
+		ans = rows * columns * deepth;
+		right_answer += ans.ToString ();	
+	}
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		const double size = 0.05;
+		const double radian = Math.PI / 180;
+		const int degrees = -45;
+		const double radius = 0.035;
+		const double size_y = 0.025;
+
+		double x = DrawAreaX + 0.1;
+		double y = DrawAreaY + 0.3;
+		double x0, y0, offset_y;
+		double offset_x = 0;
+		
+		base.Draw (gr, area_width, area_height);
+
+		x = 1 - (2 * DrawAreaX) - (columns * size * 1.5);
+		x = DrawAreaX + x /2;
+
+		// Front face
+		for (int pos_y = 0; pos_y < rows; pos_y++)
+		{
+			//  |
+			//  |
+			//
+			gr.MoveTo (x, y + (pos_y * size));
+			gr.LineTo (x, y + ((pos_y + 1) * size));
+			gr.Stroke ();
+
+			for (int pos_x = 0; pos_x < columns; pos_x++)
+			{
+				//  ---|
+				//     |
+				//
+				gr.MoveTo (x + (size * pos_x) , y + (pos_y * size));
+				gr.LineTo (x + (size * (pos_x + 1)), y + (pos_y * size));
+				gr.LineTo (x + (size * (pos_x + 1)), y + (pos_y + 1) * size);
+				gr.Stroke ();
+			}
+		}
+
+		gr.MoveTo (x , y + (rows * size));
+		gr.LineTo (x + (columns * size) , y + (rows * size));
+		gr.Stroke ();
+
+		// Back face
+		for (int pos_y = 0; pos_y < rows; pos_y++)
+		{
+			offset_x = (0.025 * pos_y);
+
+			//  |
+			//  |
+			//
+			gr.MoveTo (x + offset_x, y - (pos_y * size_y));
+			gr.LineTo (x + offset_x + 0.025, y - ((pos_y + 1)  * size_y));
+			gr.Stroke ();
+
+			for (int pos_x = 0; pos_x < columns; pos_x++)
+			{
+				gr.MoveTo (x + offset_x + (size * pos_x) , y - (pos_y * size_y));
+				gr.LineTo (x + offset_x + (size * (pos_x + 1)), y - (pos_y * size_y));
+				gr.LineTo (x + offset_x +  0.025 + (size * (pos_x + 1)), y - (pos_y + 1) * size_y);
+				gr.Stroke ();
+			}
+		}
+
+		offset_x = (0.025 * columns);
+		gr.MoveTo (x + offset_x, y - (rows * size_y));
+		gr.LineTo (x + offset_x + (size * columns) , y - (rows * size_y));
+		gr.Stroke ();
+
+		// Lateral face
+		for (int pos_y = 0; pos_y < rows; pos_y++)
+		{
+			for (int pos_x = 0; pos_x < columns; pos_x++)
+			{
+				offset_x = (size * columns) + (0.025 * pos_x);
+				offset_y = size_y * pos_x;
+		
+				gr.MoveTo (x + offset_x, y - offset_y + (pos_y * size));
+				gr.LineTo (x + offset_x, y - offset_y + (pos_y + 1) * size);
+				x0 = radius * Math.Cos (degrees * radian);
+				y0 = radius * Math.Sin (degrees * radian);
+
+				gr.LineTo (x + offset_x + x0, y - offset_y + y0 +  (pos_y + 1) * size);
+				gr.Stroke ();
+			}
+		}
+
+		offset_x = (size * columns) + (0.025 * columns);
+		offset_y = size_y * rows;	
+		gr.MoveTo (x + offset_x, y - offset_y);
+		gr.LineTo (x + offset_x, y - offset_y + (rows * size));
+		gr.Stroke ();
+	}
+}	
+
diff --git a/src/PuzzleGames/PuzzleCube.cs b/src/PuzzleGames/PuzzleCube.cs
index f7a86ce..e32dd2e 100644
--- a/src/PuzzleGames/PuzzleCube.cs
+++ b/src/PuzzleGames/PuzzleCube.cs
@@ -81,10 +81,7 @@ public class PuzzleCube : Game
 		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.ShowPangoText ("6");
-
-		gr.Stroke ();
 	}
-
 }
 
 
diff --git a/src/PuzzleGames/PuzzleTimeNow.cs b/src/PuzzleGames/PuzzleTimeNow.cs
new file mode 100644
index 0000000..e583a14
--- /dev/null
+++ b/src/PuzzleGames/PuzzleTimeNow.cs
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2009 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 PuzzleTimeNow : Game
+{
+	const double figure_size = 0.3;
+	int after, position_a, position_b, ans;
+
+	public override string Name {
+		get {return Catalog.GetString ("Time now");}
+	}
+
+	public override string Question {
+		get {return (String.Format (
+
+			Catalog.GetString ("{0} hours ago it was as long after {1} as it was before {2} on the same day. What is the time now?"),
+			after, position_a, position_b));}
+	}
+
+	public override void Initialize ()
+	{
+		after = 4 + random.Next (3);
+		position_a = 2 + random.Next (3);
+		position_b = position_a + 6;
+
+		ans = after + position_b;
+
+		if (ans > 12)
+			ans = ans - 12;  
+
+		right_answer = ans.ToString ();
+	}	
+
+	public override void Draw (CairoContextEx gr, int area_width, int area_height)
+	{
+		base.Draw (gr, area_width, area_height);
+		gr.DrawClock (DrawAreaX + 0.4, DrawAreaY + 0.4, figure_size, 
+			0, 0 /* No hands */);
+
+		gr.MoveTo (DrawAreaX + 0.3, DrawAreaY + 0.3 + figure_size);
+		gr.ShowPangoText (Catalog.GetString ("Sample clock"));
+		gr.Stroke ();
+
+	}
+}



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