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

« back to all changes in this revision

Viewing changes to src/Games/Logic/PuzzleBalance.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) 2007 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 System;
 
21
using Cairo;
 
22
using Mono.Unix;
 
23
 
 
24
using gbrainy.Core.Main;
 
25
using gbrainy.Core.Libraries;
 
26
 
 
27
namespace gbrainy.Games.Logic
 
28
{
 
29
        public class PuzzleBalance : Game
 
30
        {
 
31
                private const int elements = 5;
 
32
                private int group;
 
33
                private int [] balances = new int []
 
34
                {
 
35
                        2,3,2,0,0,      1,3,1,1,1,
 
36
                        3,3,1,0,0,      2,2,2,1,0,
 
37
                        3,2,2,0,0,      0,0,0,0,0,
 
38
 
 
39
                        2,2,3,0,0,      3,2,1,1,0,
 
40
                        1,2,2,0,0,      3,1,1,0,0,
 
41
                        3,3,1,0,0,      0,0,0,0,0,
 
42
 
 
43
                        2,2,0,0,0,      2,1,1,0,0,
 
44
                        3,2,0,0,0,      1,1,1,2,0,
 
45
                        2,2,3,0,0,      0,0,0,0,0,
 
46
                };
 
47
 
 
48
                private const double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0;
 
49
 
 
50
                public override string Name {
 
51
                        get {return Catalog.GetString ("Balance");}
 
52
                }
 
53
 
 
54
                public override string Question {
 
55
                        get {return Catalog.GetString ("How many triangles are needed in the right part of the last figure to keep it balanced?");} 
 
56
                }
 
57
 
 
58
                public override string Answer {
 
59
                        get { 
 
60
                                string answer = base.Answer + " ";
 
61
                                answer += Catalog.GetString ("Every triangle counts as 1, each diamond as 2 and each square as 3.");
 
62
                                return answer;
 
63
                        }
 
64
                }
 
65
 
 
66
                public override string Tip {
 
67
                        get { return Catalog.GetString ("Every diamond counts as two triangles.");}
 
68
                }
 
69
 
 
70
                public override void Initialize ()
 
71
                {
 
72
                        int ans = 0;
 
73
                        group = random.Next (3);
 
74
 
 
75
                        for (int i = 0; i < elements; i++)      
 
76
                                ans += balances [(group * elements * 6) + (4 * elements) + i];
 
77
 
 
78
                        right_answer = ans.ToString ();
 
79
                }
 
80
 
 
81
                public void DrawBalance (CairoContextEx gr, double x, double y, int index, bool full)
 
82
                {
 
83
                        const double width = 0.5;
 
84
                        double fig_x = x + 0.1, fig_y = y - 0.11;
 
85
                        int total = (full == true) ? (elements * 2) : elements; 
 
86
 
 
87
                        gr.Rectangle (x + 0.05, y - 0.12, 0.38, 0.08);
 
88
                        gr.Stroke ();
 
89
 
 
90
                        gr.Rectangle (x + 0.5, y - 0.12, 0.38, 0.08);
 
91
                        gr.Stroke ();
 
92
 
 
93
                        for (int i = 0; i < total; i++) {
 
94
                                switch (balances[i + index]) {
 
95
                                case 1:
 
96
                                        gr.DrawEquilateralTriangle (fig_x, fig_y, 0.05);
 
97
                                        break;
 
98
                                case 2:
 
99
                                        gr.DrawDiamond (fig_x, fig_y, 0.05);
 
100
                                        break;
 
101
                                case 3:
 
102
                                        gr.Rectangle (fig_x, fig_y + 0.005, 0.045, 0.045);
 
103
                                        break;
 
104
                                }
 
105
                        
 
106
                                if (i == elements - 1)
 
107
                                        fig_x = x + 0.54;
 
108
                                else
 
109
                                        fig_x += 0.07;
 
110
                        }
 
111
 
 
112
                        x += 0.2;
 
113
                        y += 0.01;
 
114
                        gr.MoveTo (x, y);
 
115
                        gr.LineTo (x + width, y);
 
116
                        gr.LineTo (x + width, y - 0.05);
 
117
                        gr.Stroke ();
 
118
                
 
119
                        gr.MoveTo (x , y);
 
120
                        gr.LineTo (x , y - 0.05);
 
121
                        gr.Stroke ();
 
122
                
 
123
                        gr.DrawEquilateralTriangle (x + (width / 2) - 0.04, y, 0.08);
 
124
                        gr.Stroke ();
 
125
 
 
126
                }
 
127
 
 
128
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
129
                {               
 
130
                        double x = 0.05, y = DrawAreaY + 0.1;
 
131
 
 
132
                        base.Draw (gr, area_width, area_height, rtl);
 
133
 
 
134
                        DrawBalance (gr, x, y, group * elements * 6, true);
 
135
                        y += 0.3;
 
136
                
 
137
                        DrawBalance (gr, x, y, (group * elements * 6) + 1 * elements * 2, true);
 
138
                        y += 0.3;
 
139
 
 
140
                        DrawBalance (gr, x, y, (group * elements * 6) + 2 * elements * 2, false);
 
141
                }
 
142
 
 
143
        }
 
144
}