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
using gbrainy.Core.Main;
25
using gbrainy.Core.Libraries;
27
namespace gbrainy.Games.Logic
29
public class PuzzleEquation : Game
31
private int num_a, num_b, num_c, num_d, num_e;
32
private string formula;
34
public override string Name {
35
get {return Catalog.GetString ("Equation");}
38
public override string Question {
39
get {return Catalog.GetString ("What is the result of the equation below?");}
42
public override string Answer {
44
string answer = base.Answer + " ";
45
answer += Catalog.GetString ("The order of arithmetical operations is always as follows: exponents and roots, multiplication and division, addition and subtraction.");
50
public override void Initialize ()
53
int order = 0, sequential;
55
while (found == false) {
56
num_a = 2 + random.Next (5);
57
num_b = 2 + random.Next (5);
58
num_c = 2 + random.Next (5);
59
num_d = 2 + random.Next (5);
60
num_e = 2 + random.Next (5);
61
order = num_a * num_b + num_c * num_d - num_e;
62
sequential = ((num_a * num_b + num_c) * num_d) - num_e;
64
if (order != sequential)
68
formula = String.Format ("{0} * {1} + {2} * {3} - {4} = ?", num_a, num_b, num_c, num_d, num_e);
69
right_answer = (order).ToString ();
72
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
74
base.Draw (gr, area_width, area_height, rtl);
76
gr.SetPangoLargeFontSize ();
77
gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);