[gbrainy] Proportions & Ratio calculation game
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Proportions & Ratio calculation game
- Date: Sun, 20 Sep 2009 08:24:06 +0000 (UTC)
commit 31f39919e95c5df260971852c7aacdabceebbd3f
Author: Jordi Mas <jmas softcatala org>
Date: Sun Sep 20 10:23:51 2009 +0200
Proportions & Ratio calculation game
po/POTFILES.in | 4 +-
src/CalculationGames/CalculationAverage.cs | 1 -
src/CalculationGames/CalculationProportions.cs | 124 +++++++++++++++++++++++
src/CalculationGames/CalculationRatio.cs | 126 ++++++++++++++++++++++++
src/GameManager.cs | 4 +-
src/Makefile.am | 2 +
6 files changed, 258 insertions(+), 3 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 87eb425..5301c93 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,12 +2,14 @@ gbrainy.desktop.in
src/Dialogs/AboutDialog.cs
src/CalculationGames/CalculationArithmetical.cs
src/CalculationGames/CalculationAverage.cs
+src/CalculationGames/CalculationCloserFraction.cs
src/CalculationGames/CalculationFractions.cs
src/CalculationGames/CalculationGreatestDivisor.cs
src/CalculationGames/CalculationOperator.cs
+src/CalculationGames/CalculationProportions.cs
+src/CalculationGames/CalculationRatio.cs
src/CalculationGames/CalculationPrimes.cs
src/CalculationGames/CalculationTwoNumbers.cs
-src/CalculationGames/CalculationCloserFraction.cs
src/ColorPalette.cs
src/Dialogs/CustomGameDialog.cs
src/Game.cs
diff --git a/src/CalculationGames/CalculationAverage.cs b/src/CalculationGames/CalculationAverage.cs
index 1cbea4f..aa42ebc 100644
--- a/src/CalculationGames/CalculationAverage.cs
+++ b/src/CalculationGames/CalculationAverage.cs
@@ -65,7 +65,6 @@ public class CalculationAverage : Game
public override void Initialize ()
{
bool duplicated;
- bool done = false;
int nums, options_next, dist, num_size, which = 0;
switch (CurrentDifficulty) {
diff --git a/src/CalculationGames/CalculationProportions.cs b/src/CalculationGames/CalculationProportions.cs
new file mode 100644
index 0000000..188ffa0
--- /dev/null
+++ b/src/CalculationGames/CalculationProportions.cs
@@ -0,0 +1,124 @@
+/*
+ * 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 System;
+using Cairo;
+using Mono.Unix;
+
+public class CalculationProportions : Game
+{
+ const int options_cnt = 4;
+ const int correct_pos = 0;
+ double []options;
+ ArrayListIndicesRandom random_indices;
+ double num, den, percentage, correct;
+
+ public override string Name {
+ get {return Catalog.GetString ("Proportions");}
+ }
+
+ public override Types Type {
+ get { return Game.Types.MathTrainer;}
+ }
+
+ public override string Question {
+ get {
+ return String.Format (
+ Catalog.GetString ("A {0}/{1} of 'number A' is {2}% of a 'number B'. 'number A' divided by a 'number B' is? Answer {3}, {4}, {5} or {6}."),
+ num, den, percentage, GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
+ }
+
+ public override string Answer {
+ get {
+ string answer = base.Answer + " ";
+
+ answer += String.Format (Catalog.GetString ("The result of the operation is {0:##0.###}"),
+ correct);
+ return answer;
+ }
+ }
+
+ public override void Initialize ()
+ {
+ int options_next, random_max, which = 0;
+
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ random_max = 20;
+ break;
+ default:
+ case Difficulty.Medium:
+ random_max = 30;
+ break;
+ case Difficulty.Master:
+ random_max = 50;
+ break;
+ }
+
+
+ do {
+ // Fraction
+ num = 10 + random.Next (random_max);
+ den = 1 + random.Next (random_max);
+ percentage = 30 + random.Next (random_max);
+ } while (num / den == 1);
+
+ options = new double [options_cnt];
+
+ options_next = 0;
+ options [options_next++] = correct = percentage / 100 / (num / den);
+ options [options_next++] = percentage / 50 * (num / den);
+ options [options_next++] = percentage / 100 / (den / num);
+ options [options_next++] = percentage / 150 * (den / num);
+
+
+ random_indices = new ArrayListIndicesRandom (options_cnt);
+ random_indices.Initialize ();
+
+ for (int i = 0; i < options_cnt; i++)
+ {
+ if (random_indices [i] == correct_pos) {
+ which = i;
+ break;
+ }
+ }
+
+ right_answer += GetPossibleAnswer (which);
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16;
+ int indx;
+
+ base.Draw (gr, area_width, area_height);
+
+ gr.SetPangoLargeFontSize ();
+
+ for (int i = 0; i < options_cnt; i++)
+ {
+ gr.MoveTo (x, y);
+ indx = random_indices[i];
+ gr.ShowPangoText (String.Format ("{0}) {1:##0.###}", GetPossibleAnswer (i) , options [indx]));
+
+ y = y + 0.15;
+ }
+ }
+}
+
diff --git a/src/CalculationGames/CalculationRatio.cs b/src/CalculationGames/CalculationRatio.cs
new file mode 100644
index 0000000..f6e2e90
--- /dev/null
+++ b/src/CalculationGames/CalculationRatio.cs
@@ -0,0 +1,126 @@
+/*
+ * 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 System;
+using Cairo;
+using Mono.Unix;
+
+public class CalculationRatio : Game
+{
+ int number_a, number_b, ratio_a, ratio_b;
+
+ public override string Name {
+ get {return Catalog.GetString ("Ratio");}
+ }
+
+ public override Types Type {
+ get { return Game.Types.MathTrainer;}
+ }
+
+ public override string Question {
+ get {
+ return String.Format (
+ Catalog.GetString ("Two numbers that sum {0} have a ratio {1} to {2}. Which are these numbers?"),
+ number_a + number_b, ratio_a, ratio_b);
+ }
+ }
+
+
+ public override string Answer {
+ get {
+ string answer = base.Answer + " ";
+
+ answer += String.Format (Catalog.GetString ("The second number is calculated by multiplying the first by {0} and dividing it by {1}"),
+ ratio_a, ratio_b);
+ return answer;
+ }
+ }
+
+ public override string Tip {
+ get { return Catalog.GetString ("A ratio specifies a proportion between two numbers. A ratio 'a' to 'b' means that for every 'a' parts you have 'b' parts.");}
+ }
+
+ public override void Initialize ()
+ {
+ int random_max;
+
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ random_max = 5;
+ break;
+ default:
+ case Difficulty.Medium:
+ random_max = 8;
+ break;
+ case Difficulty.Master:
+ random_max = 15;
+ break;
+ }
+
+ number_a = 10 + random.Next (random_max);
+
+ if (number_a % 2 !=0)
+ number_a++;
+
+ ratio_a = 2;
+ ratio_b = 3 + random.Next (random_max);
+ number_b = number_a / ratio_a * ratio_b;
+
+ right_answer = String.Format (Catalog.GetString ("{0} and {1}"), number_a, number_b);
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ base.Draw (gr, area_width, area_height);
+ }
+
+
+ public override bool CheckAnswer (string answer)
+ {
+ string num_a = string.Empty;
+ string num_b = string.Empty;
+ bool first = true;
+
+ for (int c = 0; c < answer.Length; c++)
+ {
+ if (answer[c] < '0' || answer[c] > '9') {
+ first = false;
+ continue;
+ }
+
+ if (first == true)
+ num_a += answer[c];
+ else
+ num_b += answer[c];
+ }
+
+ try {
+ if (Int32.Parse (num_a) == number_a && Int32.Parse (num_b) == number_b ||
+ Int32.Parse (num_b) == number_a && Int32.Parse (num_a) == number_b)
+ return true;
+ }
+
+ catch (FormatException) {
+ return false;
+ }
+
+ return false;
+ }
+}
+
diff --git a/src/GameManager.cs b/src/GameManager.cs
index 30c266e..a779c0a 100644
--- a/src/GameManager.cs
+++ b/src/GameManager.cs
@@ -82,7 +82,9 @@ public class GameManager
typeof (CalculationOperator),
typeof (CalculationFractions),
typeof (CalculationPrimes),
- typeof (CalculationAverage)
+ typeof (CalculationAverage),
+ typeof (CalculationProportions),
+ typeof (CalculationRatio),
};
static Type[] MemoryTrainersInternal = new Type[]
diff --git a/src/Makefile.am b/src/Makefile.am
index a6cfb20..75c34e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -82,6 +82,8 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs \
$(srcdir)/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs \
$(srcdir)/CalculationGames/CalculationAverage.cs \
+ $(srcdir)/CalculationGames/CalculationProportions.cs \
+ $(srcdir)/CalculationGames/CalculationRatio.cs \
$(srcdir)/SimpleLabel.cs \
$(srcdir)/gbrainy.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]