[gbrainy] Percentage puzzle
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Percentage puzzle
- Date: Fri, 25 Sep 2009 13:43:50 +0000 (UTC)
commit d790f0282a615c4a9de3cd3f00a8d93cb0fe3027
Author: Jordi Mas <jmas softcatala org>
Date: Fri Sep 25 15:43:02 2009 +0200
Percentage puzzle
po/POTFILES.in | 1 +
src/GameManager.cs | 1 +
src/Makefile.am | 1 +
src/PuzzleGames/PuzzlePercentage.cs | 129 +++++++++++++++++++++++++++++++++++
4 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5301c93..b3ec66d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -61,6 +61,7 @@ src/PuzzleGames/PuzzleNumericSequence.cs
src/PuzzleGames/PuzzleOstracism.cs
src/PuzzleGames/PuzzlePencil.cs
src/PuzzleGames/PuzzlePeopleTable.cs
+src/PuzzleGames/PuzzlePercentage.cs
src/PuzzleGames/PuzzleQuadrilaterals.cs
src/PuzzleGames/PuzzleSquareDots.cs
src/PuzzleGames/PuzzleSquaresAndLetters.cs
diff --git a/src/GameManager.cs b/src/GameManager.cs
index a779c0a..728fb6b 100644
--- a/src/GameManager.cs
+++ b/src/GameManager.cs
@@ -71,6 +71,7 @@ public class GameManager
typeof (PuzzleLargerShape),
typeof (PuzzleHandshakes),
typeof (PuzzleCounting),
+ typeof (PuzzlePercentage),
};
static Type[] CalculationTrainersInternal = new Type[]
diff --git a/src/Makefile.am b/src/Makefile.am
index 75c34e1..fe7a78b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,6 +84,7 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/CalculationGames/CalculationAverage.cs \
$(srcdir)/CalculationGames/CalculationProportions.cs \
$(srcdir)/CalculationGames/CalculationRatio.cs \
+ $(srcdir)/PuzzleGames/PuzzlePercentage.cs \
$(srcdir)/SimpleLabel.cs \
$(srcdir)/gbrainy.cs
diff --git a/src/PuzzleGames/PuzzlePercentage.cs b/src/PuzzleGames/PuzzlePercentage.cs
new file mode 100644
index 0000000..2e48eab
--- /dev/null
+++ b/src/PuzzleGames/PuzzlePercentage.cs
@@ -0,0 +1,129 @@
+/*
+ * 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 PuzzlePercentage : Game
+{
+ enum GameType
+ {
+ Discount,
+ Sales,
+ Water,
+ Total
+ }
+
+ string question, answer;
+ GameType gametype;
+
+ public override string Name {
+ get {return Catalog.GetString ("Percentage");}
+ }
+
+ public override string Question {
+ get {return question; }
+ }
+
+ public override string Answer {
+ get {
+
+ if (String.IsNullOrEmpty (answer) == true)
+ return base.Answer;
+
+ return base.Answer + " " + answer;
+ }
+ }
+
+ public override void Initialize ()
+ {
+ int ans;
+
+ gametype = (GameType) random.Next ((int) GameType.Total);
+
+ switch ((int) gametype)
+ {
+ case (int) GameType.Discount:
+ int price, discount, paid;
+
+ discount = 10 + random.Next (30);
+ price = 100 + random.Next (100);
+ paid = price - (price * discount / 100);
+
+ question = String.Format (
+ Catalog.GetString ("After getting {0}% discount you have paid {1} monetary units for a TV set. What was the original price of the TV set?"),
+ discount, paid);
+ ans = price;
+ break;
+ case (int) GameType.Sales:
+ int sales, increase, previous;
+
+ previous = 10 + random.Next (90);
+ increase = 10 + random.Next (20);
+ sales = previous + (previous * increase / 100);
+
+ question = String.Format (
+ Catalog.GetString ("John's shop had sales of {0} monetary units. This was an increase of {1}% over last month. What were last month sales?"),
+ sales, increase);
+ ans = previous;
+ break;
+ case (int) GameType.Water:
+ double decrease, percentage;
+
+ do
+ {
+ decrease = (1 + random.Next (70));
+ percentage = decrease / (100 - decrease) * 100;
+
+ } while (percentage != Math.Truncate (percentage));
+
+ question = String.Format (
+ Catalog.GetString ("The amount of water in a bucket decreases by {0}%. By what percentage must the amount of water increase to reach its original value?"),
+ decrease);
+
+ answer = Catalog.GetString ("The objective is to obtain the same total amount");
+ ans = (int) percentage;
+ break;
+ default:
+ throw new Exception ("Unexpected value");
+ }
+
+ right_answer = (ans).ToString ();
+ }
+
+ 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)
+ {
+ if (gametype == GameType.Water) {
+ if (String.Compare (answer, right_answer + "%", true) == 0)
+ return true;
+ }
+
+ if (String.Compare (answer, right_answer, true) == 0)
+ return true;
+
+ return false;
+ }
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]