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

« back to all changes in this revision

Viewing changes to src/PuzzleGames/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
 
public class PuzzleEquation : Game
25
 
{
26
 
        private int num_a, num_b, num_c, num_d, num_e;
27
 
        private string formula;
28
 
 
29
 
        public override string Name {
30
 
                get {return Catalog.GetString ("Equation");}
31
 
        }
32
 
 
33
 
        public override string Question {
34
 
                get {return Catalog.GetString ("What is the result of the equation below?");} 
35
 
        }
36
 
 
37
 
        public override string Answer {
38
 
                get { 
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.");
41
 
                        return answer;
42
 
                }
43
 
        }
44
 
 
45
 
        public override void Initialize ()
46
 
        {
47
 
                bool found  = false;
48
 
                int order = 0, sequential;
49
 
 
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;
58
 
 
59
 
                        if (order != sequential)
60
 
                                found = true;
61
 
                }
62
 
 
63
 
                formula = String.Format ("{0} * {1} + {2} * {3} - {4} = ?", num_a, num_b, num_c, num_d, num_e);
64
 
                right_answer = (order).ToString ();
65
 
        }
66
 
 
67
 
        public override void Draw (CairoContextEx gr, int area_width, int area_height)
68
 
        {
69
 
                base.Draw (gr, area_width, area_height);
70
 
 
71
 
                gr.SetPangoLargeFontSize ();
72
 
                gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);
73
 
        }
74
 
}