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

« back to all changes in this revision

Viewing changes to src/Games/Logic/PuzzleCounting.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) 2009 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 PuzzleCounting : Game
 
30
        {
 
31
                enum GameType
 
32
                {
 
33
                        Machine,
 
34
                        Fence,
 
35
                        Present,
 
36
                        Total
 
37
                }
 
38
 
 
39
                string question, answer;
 
40
                GameType gametype;
 
41
 
 
42
                public override string Name {
 
43
                        get {return Catalog.GetString ("Counting");}
 
44
                }
 
45
 
 
46
                public override string Question {
 
47
                        get {return question; }
 
48
                }
 
49
 
 
50
                public override string Answer {
 
51
                        get { return base.Answer + " " + answer;}
 
52
                }
 
53
 
 
54
                public override void Initialize ()
 
55
                {
 
56
                        int ans, var, total;
 
57
 
 
58
                        gametype = (GameType) random.Next ((int) GameType.Total);
 
59
 
 
60
                        switch ((int) gametype)
 
61
                        {
 
62
                        case (int) GameType.Machine:
 
63
                                var = 2 + random.Next (5);
 
64
                                total = 50 + random.Next (100);
 
65
                                question = String.Format (
 
66
                                        // Translators: {0} and {1} are always numbers greater than 1
 
67
                                        Catalog.GetString ("We have a {0} meters piece of fabric. Machine A takes {1} seconds to cut 1 meter of this fabric. How many seconds does Machine A take to cut the entire piece of fabric into 1 meter pieces?"),
 
68
                                        total, var);
 
69
                                answer = String.Format (
 
70
                                        // Translators: {0} is always a number greater than 1
 
71
                                        Catalog.GetString ("With the {0} cut, Machine A creates two 1 meter pieces."), (total - 1));
 
72
        
 
73
                                ans = (total - 1) * var;
 
74
                                break;
 
75
 
 
76
                        case (int) GameType.Fence:
 
77
                                total = 20 + random.Next (20);
 
78
                                ans = 4 * total - 4;
 
79
                                question = String.Format (
 
80
                                        // Translators: {0} is always a number greater than 20
 
81
                                        Catalog.GetString ("A fence is built to enclose a square shaped region. {0} fence poles are used in each side of the square. How many fence poles are used in total?"),
 
82
                                        total);
 
83
                                        // Translators: {0} is always a number greater than 20
 
84
                                answer = String.Format (
 
85
                                        Catalog.GetString ("There are {0} fence poles since the poles on the corners of the square are shared."), ans);
 
86
                                break;
 
87
 
 
88
                        case (int) GameType.Present:
 
89
                                int present = 5 + random.Next (20);
 
90
                                total = present + 2;
 
91
                                ans = total;
 
92
                                question = String.Format (
 
93
                                        // Translators: {0} is always a number greater than 5
 
94
                                        Catalog.GetString ("Wrapping an anniversary present costs one euro. The anniversary present costs {0} euros more than the cost to wrap it. How much does it cost to both purchase and wrap the present?"),
 
95
                                        present);
 
96
                                answer = String.Format (
 
97
                                        Catalog.GetString ("Individually, the present costs one euro more to purchase than to wrap."));
 
98
                                break;
 
99
                        default:
 
100
                                throw new Exception ("Unexpected value");
 
101
                        }
 
102
 
 
103
                        right_answer = (ans).ToString ();
 
104
                }
 
105
 
 
106
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
107
                {
 
108
                        base.Draw (gr, area_width, area_height, rtl);
 
109
 
 
110
                        if (gametype == GameType.Present) {
 
111
                                gr.DrawImageFromAssembly ("present.svg", 0.2, 0.4, 0.6, 0.2);
 
112
                        } else {
 
113
                                if (gametype == GameType.Fence)
 
114
                                {
 
115
                                        double x105, y105;
 
116
                                        const double x = 0.35, y = 0.2;
 
117
                                        const double figure_size = 0.4;
 
118
 
 
119
                                        x105 = figure_size * Math.Cos (105 * Math.PI / 180);
 
120
                                        y105 = figure_size * Math.Sin (105 * Math.PI / 180);
 
121
                                        gr.MoveTo (x, y);
 
122
                                        gr.LineTo (x + x105, y + y105);
 
123
                                        gr.LineTo (x + x105 + figure_size, y + y105);
 
124
                                        gr.Stroke ();
 
125
                                        gr.MoveTo (x + figure_size, y);
 
126
                                        gr.LineTo (x + figure_size + x105, y + y105);
 
127
                                        gr.Stroke ();
 
128
                                        gr.MoveTo (x, y);
 
129
                                        gr.LineTo (x + figure_size, y);
 
130
                                        gr.Stroke ();
 
131
                                }
 
132
                        }
 
133
                }
 
134
        }
 
135
}