2
* Copyright (C) 2007-2008 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
using gbrainy.Core.Main;
25
using gbrainy.Core.Libraries;
27
namespace gbrainy.Games.Calculation
29
public class CalculationGreatestDivisor : Game
31
private int []numbers;
32
private int []answers;
34
private int num_answ_ques;
36
public override string Name {
37
get {return Catalog.GetString ("Greatest divisor");}
40
public override Types Type {
41
get { return Game.Types.MathTrainer;}
44
public override string Question {
45
get {return Catalog.GetString ("Which of the possible divisors is the greatest that divides all numbers?");}
48
public override void Initialize ()
52
int []mult = new int [3];
54
switch (CurrentDifficulty) {
59
case Difficulty.Medium:
63
case Difficulty.Master:
69
numbers = new int [num_answ_ques];
70
answers = new int [num_answ_ques];
72
// Common multiplayers for all numbers
73
for (m = 0; m < mult.Length; m++) {
74
mult[m] = GetMultiplier (mult);
78
while (n < numbers.Length) {
79
numbers [n] = 4 + random.Next (5);
80
for (int i = 1; i < 5; i++) {
81
numbers [n] = numbers [n] * (1 + random.Next (10));
84
for (m = 0; m < mult.Length; m++) {
85
numbers[n] = numbers [n] * mult[m];
88
if (numbers[n] > max_num || numbers[n] < 50)
92
for (int i = 0; i < n; i++) {
93
if (numbers[i] == numbers [n]) {
102
for (n = 0; n < answers.Length; n++) {
103
answers[n] = GetUniqueAnswer (mult, answers);
108
for (int a = 0; a < answers.Length; a++)
110
for (n = 0; n < answers.Length; n++)
112
if ((double)numbers[n] / (double)answers[a] != Math.Abs (numbers[n] / answers[a]))
116
if (n == answers.Length && answers[a] > answer)
120
right_answer = answer.ToString ();
123
private int GetUniqueAnswer (int []mult, int []answers)
129
while (found == false) {
130
switch (random.Next (7)) {
135
answer = mult[0] * mult[1];
138
answer = mult[0] * mult[2];
141
answer = mult[0] * 7;
144
answer = mult[0] * 13;
147
answer = mult[0] * mult[1] * mult[2];
150
answer = mult[0] * 19;
154
for (n = 0; n < answers.Length; n++) {
155
if (answers [n] == answer)
159
if (n == answers.Length)
166
private int GetMultiplier (int []nums)
172
while (found == false) {
173
switch (random.Next (4)) {
188
for (n = 0; n < nums.Length; n++) {
193
if (n == nums.Length)
200
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
202
double x = DrawAreaX, y = DrawAreaY + 0.1;
204
base.Draw (gr, area_width, area_height, rtl);
206
gr.SetPangoLargeFontSize ();
209
gr.ShowPangoText (Catalog.GetString ("Numbers"));
212
for (int n = 0; n < numbers.Length; n++)
215
gr.ShowPangoText (numbers[n].ToString ());
224
gr.ShowPangoText (Catalog.GetString ("Possible divisors"));
227
for (int n = 0; n < answers.Length; n++)
230
gr.ShowPangoText (answers[n].ToString ());