2
* Copyright (C) 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
public class PuzzleEquation : Game
26
private int num_a, num_b, num_c, num_d, num_e;
27
private string formula;
29
public override string Name {
30
get {return Catalog.GetString ("Equation");}
33
public override string Question {
34
get {return Catalog.GetString ("What is the result of the equation below?");}
37
public override string Answer {
39
string answer = base.Answer + " ";
40
answer += Catalog.GetString ("The order of arithmetical operations is always as follows: exponents and roots, multiplication and division, addition and subtraction.");
45
public override void Initialize ()
48
int order = 0, sequential;
50
while (found == false) {
51
num_a = 2 + random.Next (5);
52
num_b = 2 + random.Next (5);
53
num_c = 2 + random.Next (5);
54
num_d = 2 + random.Next (5);
55
num_e = 2 + random.Next (5);
56
order = num_a * num_b + num_c * num_d - num_e;
57
sequential = ((num_a * num_b + num_c) * num_d) - num_e;
59
if (order != sequential)
63
formula = String.Format ("{0} * {1} + {2} * {3} - {4} = ?", num_a, num_b, num_c, num_d, num_e);
64
right_answer = (order).ToString ();
67
public override void Draw (CairoContextEx gr, int area_width, int area_height)
69
base.Draw (gr, area_width, area_height);
71
gr.SetPangoLargeFontSize ();
72
gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);