[gbrainy] Two new calculation games
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Two new calculation games
- Date: Tue, 23 Oct 2012 02:21:41 +0000 (UTC)
commit 84d5383c42e7a251579f0a8192878d4fe4fbf2a1
Author: Jordi Mas <jmas softcatala org>
Date: Tue Oct 23 04:21:46 2012 +0200
Two new calculation games
po/POTFILES.in | 2 +
src/Games/Calculation/CalculationConsecutiveSum.cs | 134 +++++++++++
.../Calculation/CalculationSelectedNumbers.cs | 231 ++++++++++++++++++++
src/Games/GameList.cs | 2 +
src/Games/Makefile.am | 4 +-
5 files changed, 372 insertions(+), 1 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cc15b1a..820b753 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -43,12 +43,14 @@ src/Core/Views/WelcomeView.cs
src/Games/Calculation/CalculationArithmetical.cs
src/Games/Calculation/CalculationAverage.cs
src/Games/Calculation/CalculationCloserFraction.cs
+src/Games/Calculation/CalculationConsecutiveSum.cs
src/Games/Calculation/CalculationFractions.cs
src/Games/Calculation/CalculationGreatestDivisor.cs
src/Games/Calculation/CalculationOperator.cs
src/Games/Calculation/CalculationPrimes.cs
src/Games/Calculation/CalculationProportions.cs
src/Games/Calculation/CalculationRatio.cs
+src/Games/Calculation/CalculationSeletectedNumbers.cs
src/Games/Calculation/CalculationTwoNumbers.cs
src/Games/Logic/Puzzle3DCube.cs
src/Games/Logic/PuzzleBalance.cs
diff --git a/src/Games/Calculation/CalculationConsecutiveSum.cs b/src/Games/Calculation/CalculationConsecutiveSum.cs
new file mode 100644
index 0000000..5d69326
--- /dev/null
+++ b/src/Games/Calculation/CalculationConsecutiveSum.cs
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2012 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 gbrainy.Core.Main;
+
+namespace gbrainy.Games.Calculation
+{
+ public class CalculationConsecutiveSum : Game
+ {
+ const int CONSECUTIVE_SIZE = 5;
+ const int MIN_START = 5;
+ int total_size;
+ int consecutive_sum = 0;
+ int consecutive_pos;
+ int []numbers;
+
+ public override string Name {
+ get {return Translations.GetString ("Consecutive Sum");}
+ }
+
+ public override GameTypes Type {
+ get { return GameTypes.Calculation;}
+ }
+
+ public override string Question {
+ get { return String.Format (Translations.GetString (
+ "In the list of single digit numbers below, there are 5 consecutive numbers that sum {0}. What are these numbers?"),
+ consecutive_sum);
+ }
+ }
+
+ bool HasUniqueConsecutive ()
+ {
+ int found = 0;
+
+ for (int i = 0; i < total_size - CONSECUTIVE_SIZE; i++)
+ {
+ int sum = 0;
+ for (int c = 0; c < CONSECUTIVE_SIZE; c++)
+ {
+ sum += numbers[i + c];
+ }
+
+ if (sum == consecutive_sum)
+ found++;
+ }
+
+ return found == 1;
+ }
+
+ protected override void Initialize ()
+ {
+
+ switch (CurrentDifficulty) {
+ case GameDifficulty.Easy:
+ case GameDifficulty.Medium:
+ total_size = 15;
+ break;
+ case GameDifficulty.Master:
+ total_size = 20;
+ break;
+ }
+
+ numbers = new int [total_size];
+
+ do
+ {
+ for (int i = 0; i < total_size; i++)
+ {
+ numbers[i] = random.Next (10);
+ }
+
+ consecutive_pos = MIN_START + random.Next (total_size - MIN_START - CONSECUTIVE_SIZE);
+ Console.WriteLine("Pos " + consecutive_pos);
+ consecutive_sum = 0;
+
+ for (int i = 0; i < CONSECUTIVE_SIZE; i++)
+ {
+ consecutive_sum += numbers[i + consecutive_pos];
+ }
+
+ } while (HasUniqueConsecutive () == false);
+
+ string ans = string.Empty;
+ string show = string.Empty;
+ for (int i = 0; i < CONSECUTIVE_SIZE; i++)
+ {
+ ans+= numbers[i + consecutive_pos].ToString ();
+ show+= numbers[i + consecutive_pos].ToString ();
+ }
+
+ Answer.CheckAttributes |= GameAnswerCheckAttributes.IgnoreSpaces;
+ Answer.CheckExpression = "[-0-9]+";
+ Answer.CorrectShow = show;
+ Answer.Correct = ans;
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
+ {
+ const double SEPARATION = 0.05;
+ double x = DrawAreaX, y = 0.4;
+
+ base.Draw (gr, area_width, area_height, rtl);
+ gr.SetPangoLargeFontSize ();
+
+ x = ((1 - (DrawAreaX * 2) - SEPARATION * numbers.Length) / 2) + DrawAreaX;
+ for (int n = 0; n < numbers.Length; n++)
+ {
+ gr.MoveTo (x, y);
+ gr.ShowPangoText (numbers[n].ToString ());
+ gr.Stroke ();
+ x += SEPARATION;
+ }
+ }
+ }
+}
diff --git a/src/Games/Calculation/CalculationSelectedNumbers.cs b/src/Games/Calculation/CalculationSelectedNumbers.cs
new file mode 100644
index 0000000..4ff4b11
--- /dev/null
+++ b/src/Games/Calculation/CalculationSelectedNumbers.cs
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2012 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 gbrainy.Core.Main;
+using gbrainy.Core.Toolkit;
+using gbrainy.Core.Services;
+
+namespace gbrainy.Games.Calculation
+{
+ public class CalculationSelectedNumbers : Game
+ {
+ enum Operation
+ {
+ Addition,
+ Product,
+ Total
+ }
+
+ const int options_cnt = 4;
+ const int correct_pos = 0;
+ int []numbers;
+ int []options;
+ ArrayListIndicesRandom random_indices;
+ int correct;
+ int total_size;
+ int greater_than;
+ Operation operation;
+
+ public override string Name {
+ get {return Translations.GetString ("Selected Numbers");}
+ }
+
+ public override GameTypes Type {
+ get { return GameTypes.Calculation;}
+ }
+
+ public override string Question {
+ get {
+ switch (operation)
+ {
+ case Operation.Addition:
+ return String.Format (Translations.GetString (
+ "In the list of numbers below, what is the sum all the numbers greater than {0}? Answer {1}, {2}, {3} or {4}."),
+ greater_than,
+ Answer.GetMultiOption (0), Answer.GetMultiOption (1), Answer.GetMultiOption (2), Answer.GetMultiOption (3));
+ case Operation.Product:
+ return String.Format (Translations.GetString (
+ "In the list of numbers below, what is the product all the numbers greater than {0}? Answer {1}, {2}, {3} or {4}."),
+ greater_than,
+ Answer.GetMultiOption (0), Answer.GetMultiOption (1), Answer.GetMultiOption (2), Answer.GetMultiOption (3));
+ }
+ throw new InvalidOperationException();
+ }
+ }
+
+ void GetPuzzleNumbersAndAnswer ()
+ {
+ operation = (Operation)random.Next((int)Operation.Total);
+ numbers = new int [total_size];
+ greater_than = random.Next (5);
+
+ int selected;
+ do
+ {
+ switch (operation)
+ {
+ case Operation.Addition:
+ correct = 0;
+ break;
+ case Operation.Product:
+ correct = 1;
+ break;
+ }
+
+ selected = 0;
+ for (int i = 0; i < total_size; i++)
+ {
+ numbers [i] = 1 + random.Next (8);
+
+ if (numbers [i] > greater_than)
+ {
+ selected++;
+
+ switch (operation)
+ {
+ case Operation.Addition:
+ correct += numbers [i];
+ break;
+ case Operation.Product:
+ correct *= numbers [i];
+ break;
+ }
+ }
+ }
+ } while (selected > total_size / 3);
+ }
+
+ protected override void Initialize ()
+ {
+ bool duplicated;
+ int options_next, which = 0;
+
+ Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
+
+ switch (CurrentDifficulty) {
+ case GameDifficulty.Easy:
+ total_size = 10;
+ break;
+ case GameDifficulty.Medium:
+ total_size = 15;
+ break;
+ case GameDifficulty.Master:
+ total_size = 20;
+ break;
+ }
+
+ GetPuzzleNumbersAndAnswer();
+
+ options = new int [options_cnt];
+ options [correct_pos] = correct;
+ options_next = correct_pos + 1;
+
+ // Generate possible answers
+ while (options_next < options_cnt)
+ {
+ int ans;
+
+ ans = correct + random.Next (-correct / 2, correct / 2);
+ duplicated = false;
+
+ // No repeated answers
+ for (int num = 0; num < options_next; num++)
+ {
+ if (options [num] == ans)
+ {
+ duplicated = true;
+ break;
+ }
+ }
+
+ if (duplicated)
+ continue;
+
+ options [options_next] = ans;
+ options_next++;
+ }
+
+ 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;
+ }
+ }
+
+ Answer.SetMultiOptionAnswer (which, options [correct_pos].ToString ());
+
+ // Options
+ double x = DrawAreaX + 0.25, y = DrawAreaY + 0.26;
+ Container container = new Container (x, y, 1 - (x * 2), 0.6);
+ AddWidget (container);
+
+ for (int i = 0; i < options_cnt; i++)
+ {
+ DrawableArea drawable_area = new DrawableArea (0.3, 0.1);
+ drawable_area.X = x;
+ drawable_area.Y = y + i * 0.15;
+ container.AddChild (drawable_area);
+ drawable_area.Data = i;
+ drawable_area.DataEx = Answer.GetMultiOption (i);
+
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ int n = (int) e.Data;
+ int indx = random_indices[n];
+
+ e.Context.SetPangoLargeFontSize ();
+ e.Context.MoveTo (0.02, 0.02);
+ e.Context.ShowPangoText (String.Format ("{0}) {1}", Answer.GetMultiOption (n) , options [indx]));
+ };
+ }
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
+ {
+ const double SEPARATION = 0.05;
+ double x = DrawAreaX, y = 0.05;
+
+ base.Draw (gr, area_width, area_height, rtl);
+ gr.SetPangoLargeFontSize ();
+
+ gr.MoveTo (0.05, y);
+ gr.SetPangoLargeFontSize ();
+ gr.ShowPangoText (Translations.GetString ("Numbers"));
+ y += 0.08;
+
+ x = ((1 - (DrawAreaX * 2) - SEPARATION * numbers.Length) / 2) + DrawAreaX;
+ for (int n = 0; n < numbers.Length; n++)
+ {
+ gr.MoveTo (x, y);
+ gr.ShowPangoText (numbers[n].ToString ());
+ gr.Stroke ();
+ x += SEPARATION;
+ }
+
+ gr.MoveTo (0.1, 0.25);
+ gr.ShowPangoText (Translations.GetString ("Choose one of the following:"));
+ }
+ }
+}
diff --git a/src/Games/GameList.cs b/src/Games/GameList.cs
index 1e63a2c..4d1fee5 100644
--- a/src/Games/GameList.cs
+++ b/src/Games/GameList.cs
@@ -89,6 +89,8 @@ namespace gbrainy.Games
typeof (CalculationAverage),
typeof (CalculationProportions),
typeof (CalculationRatio),
+ typeof (CalculationSelectedNumbers),
+ typeof (CalculationConsecutiveSum),
};
static Type[] MemoryInternal = new Type[]
diff --git a/src/Games/Makefile.am b/src/Games/Makefile.am
index f4c8d71..4b816e1 100644
--- a/src/Games/Makefile.am
+++ b/src/Games/Makefile.am
@@ -69,7 +69,9 @@ CSDISTFILES = \
$(srcdir)/Calculation/CalculationPrimes.cs \
$(srcdir)/Calculation/CalculationProportions.cs \
$(srcdir)/Calculation/CalculationRatio.cs \
- $(srcdir)/Calculation/CalculationTwoNumbers.cs
+ $(srcdir)/Calculation/CalculationTwoNumbers.cs \
+ $(srcdir)/Calculation/CalculationConsecutiveSum.cs \
+ $(srcdir)/Calculation/CalculationSelectedNumbers.cs
CSFILES = $(CSDISTFILES) \
AssemblyInfo.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]