~ubuntu-branches/ubuntu/lucid/gbrainy/lucid

« back to all changes in this revision

Viewing changes to src/Games/Logic/PuzzleEquation.cs

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-01-12 11:21:24 UTC
  • mfrom: (13.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100112112124-o4ztomxa0xfh2ulj
Tags: 1.30-1ubuntu1
* debian/control:
  - Revert build-depends to lucid versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Jordi Mas i Hernàndez <jmas@softcatala.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
using Cairo;
 
21
using Mono.Unix;
 
22
using System;
 
23
 
 
24
using gbrainy.Core.Main;
 
25
using gbrainy.Core.Libraries;
 
26
 
 
27
namespace gbrainy.Games.Logic
 
28
{
 
29
        public class PuzzleEquation : Game
 
30
        {
 
31
                private int num_a, num_b, num_c, num_d, num_e;
 
32
                private string formula;
 
33
 
 
34
                public override string Name {
 
35
                        get {return Catalog.GetString ("Equation");}
 
36
                }
 
37
 
 
38
                public override string Question {
 
39
                        get {return Catalog.GetString ("What is the result of the equation below?");} 
 
40
                }
 
41
 
 
42
                public override string Answer {
 
43
                        get { 
 
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.");
 
46
                                return answer;
 
47
                        }
 
48
                }
 
49
 
 
50
                public override void Initialize ()
 
51
                {
 
52
                        bool found  = false;
 
53
                        int order = 0, sequential;
 
54
 
 
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;
 
63
 
 
64
                                if (order != sequential)
 
65
                                        found = true;
 
66
                        }
 
67
 
 
68
                        formula = String.Format ("{0} * {1} + {2} * {3} - {4} = ?", num_a, num_b, num_c, num_d, num_e);
 
69
                        right_answer = (order).ToString ();
 
70
                }
 
71
 
 
72
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
73
                {
 
74
                        base.Draw (gr, area_width, area_height, rtl);
 
75
 
 
76
                        gr.SetPangoLargeFontSize ();
 
77
                        gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);
 
78
                }
 
79
        }
 
80
}