gbrainy r198 - trunk/src



Author: jmas
Date: Wed Feb  6 18:24:20 2008
New Revision: 198
URL: http://svn.gnome.org/viewvc/gbrainy?rev=198&view=rev

Log:
2008-02-06 Jordi Mas <jmas softcatala org>
 
 	* GameDrawingArea.cs: Fixes typo
	* Makefile.am: Add new logic puzzle
	* GameManager.cs: Add new logic puzzle
	* PuzzleMostInCommon.cs: New logic puzzle
	* ArrayListIndicesRandom.cs: New method, documentation



Added:
   trunk/src/PuzzleMostInCommon.cs
Modified:
   trunk/src/ArrayListIndicesRandom.cs
   trunk/src/ChangeLog
   trunk/src/GameDrawingArea.cs
   trunk/src/GameManager.cs
   trunk/src/Makefile.am

Modified: trunk/src/ArrayListIndicesRandom.cs
==============================================================================
--- trunk/src/ArrayListIndicesRandom.cs	(original)
+++ trunk/src/ArrayListIndicesRandom.cs	Wed Feb  6 18:24:20 2008
@@ -33,21 +33,28 @@
 	}
 
 	public void Initialize ()
-	{	
-		int index, left;
-
-		Clear ();
-
+	{
 		ArrayList random_list = new ArrayList (Capacity);
 		for (int i = 0; i < Capacity; i++) {
 			random_list.Add (i);
 		}
+		RandomizeFromArray (random_list);
+	}
+
+	public void RandomizeFromArray (ArrayList ar)
+	{		
+		int left = Capacity;
+		int index;
+		object []array = (object []) ar.ToArray (typeof (object));
+		Clear ();
 
-		left = Capacity;
+		// 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 < Capacity; i++, left--) {
 			index = random.Next (left);
-			Add (random_list[index]);
-			random_list[index] = random_list[left - 1];
+			Add (array[index]);
+			array[index] = array[left - 1];
 		}
 	}
 }

Modified: trunk/src/GameDrawingArea.cs
==============================================================================
--- trunk/src/GameDrawingArea.cs	(original)
+++ trunk/src/GameDrawingArea.cs	Wed Feb  6 18:24:20 2008
@@ -210,7 +210,7 @@
 		gr.SetFontSize (0.03);
 		y += 0.08;
 		gr.MoveTo (x, y);
-		gr.ShowText (String.Format (Catalog.GetString ("Your total is score {0}%"), session.TotalScore));
+		gr.ShowText (String.Format (Catalog.GetString ("Your total score is {0}%"), session.TotalScore));
 
 		y += space_small;	
 		gr.MoveTo (x, y);

Modified: trunk/src/GameManager.cs
==============================================================================
--- trunk/src/GameManager.cs	(original)
+++ trunk/src/GameManager.cs	Wed Feb  6 18:24:20 2008
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * 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
@@ -51,6 +51,7 @@
 		typeof (PuzzleLines),
 		typeof (PuzzleTetris),
 		typeof (PuzzleMissingPiece),
+		typeof (PuzzleMostInCommon)
 	};
 
 	static Type[] MathTrainers = new Type[] 

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Wed Feb  6 18:24:20 2008
@@ -52,6 +52,7 @@
 	$(srcdir)/PreferencesDialog.cs		\
 	$(srcdir)/PuzzleMissingPiece.cs		\
 	$(srcdir)/MemoryIndications.cs		\
+	$(srcdir)/PuzzleMostInCommon.cs		\
 	$(srcdir)/gbrainy.cs			
 
 ASSEMBLIES = \

Added: trunk/src/PuzzleMostInCommon.cs
==============================================================================
--- (empty file)
+++ trunk/src/PuzzleMostInCommon.cs	Wed Feb  6 18:24:20 2008
@@ -0,0 +1,277 @@
+/*
+ * 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 has the most in common with the four given figures?");} 
+	}
+
+	public override string Tip {
+		get { return Catalog.GetString ("Think of the common elements that the given figures have inside.");}
+	}
+
+	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 that the figures given.");
+			else
+				answer += Catalog.GetString ("It is the figure with more elements in common with the figures given.");
+			
+			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));
+	}
+
+	// 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 (Cairo.Context 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 (Cairo.Context 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 (Cairo.Context gr, int area_width, int area_height)
+	{
+		double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+		gr.Scale (area_width, area_height);
+		DrawBackground (gr);
+		PrepareGC (gr);
+		
+		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)));
+		}
+	}
+}
+



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