2
* Copyright (C) 2007 Jordi Mas i Hernàndez <jmas@softcatala.org>
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
24
public class CalculationCloserFraction : Game
26
private double question_num;
27
private const int options_cnt = 4;
28
private double []options;
29
private ArrayListIndicesRandom random_indices;
32
public override string Name {
33
get {return Catalog.GetString ("Closer fraction");}
36
public override Types Type {
37
get { return Game.Types.MathTrainer;}
40
public override string Question {
41
get {return String.Format (
42
Catalog.GetString ("Which of the following numbers is closer to {0:##0.###}? Answer {1}, {2}, {3} or {4}."), question_num,
43
GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
46
public override string Answer {
48
string answer = base.Answer + " ";
49
int ans_idx = random_indices[which];
51
answer += String.Format (Catalog.GetString ("The result of the operation {0} / {1} is {2:##0.###}"),
52
options[ans_idx * 2], options[(ans_idx * 2) + 1], question_num);
57
public override void Initialize ()
59
options = new double [options_cnt * 2];
62
int i, ans_idx, basenum, randnum;
64
switch (CurrentDifficulty) {
70
case Difficulty.Medium:
74
case Difficulty.Master:
81
while (done == false) {
83
options[0 + 0] = basenum + random.Next (randnum);
84
options[0 + 1] = basenum + random.Next (randnum);
86
options[2 + 0] = options[0 + 0] + random.Next (2);
87
options[2 + 1] = options[0 + 1] + random.Next (2);
89
options[(2 * 2) + 0] = options[0 + 0] - random.Next (5);
90
options[(2 * 2) + 1] = options[0 + 1] - random.Next (5);
92
options[(3 * 2) + 0] = options[0 + 0] + random.Next (5);
93
options[(3 * 2) + 1] = options[0 + 1] + random.Next (5);
95
// No repeated answers
96
for (int num = 0; num < options_cnt; num++)
98
for (int n = 0; n < options_cnt; n++)
100
if (n == num) continue;
102
if (options [(num * 2) + 0] / options [(num * 2) + 1] ==
103
options [(n * 2) + 0] / options [(n * 2) + 1]) {
113
// No numerator = denominator (1 value)
114
if (options [0 + 0] == options [0 + 1]) continue;
115
if (options [(1 * 2) + 0] == options [(1 * 2) + 1]) continue;
116
if (options [(2 * 2) + 0] == options [(2 * 2) + 1]) continue;
117
if (options [(3 * 2) + 0] == options [(3 * 2) + 1]) continue;
120
for (i = 0; i < options_cnt * 2; i++) {
125
if (i < options_cnt * 2)
131
random_indices = new ArrayListIndicesRandom (4);
132
random_indices.Initialize ();
134
which = random.Next (options_cnt);
135
ans_idx = random_indices[which];
136
question_num = options[ans_idx * 2] / options[(ans_idx * 2) + 1];
137
right_answer += GetPossibleAnswer (which);
140
public override void Draw (CairoContextEx gr, int area_width, int area_height)
142
double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16;
145
base.Draw (gr, area_width, area_height);
147
gr.SetPangoLargeFontSize ();
149
for (int i = 0; i < options_cnt; i++)
152
indx = random_indices[i];
153
gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (i) , options [indx * 2] + " / " + options [(indx * 2) +1]));