2
* Copyright (C) 2007 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 PuzzleBalance : Game
31
private const int elements = 5;
33
private int [] balances = new int []
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,
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,
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,
48
private const double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0;
50
public override string Name {
51
get {return Catalog.GetString ("Balance");}
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?");}
58
public override string Answer {
60
string answer = base.Answer + " ";
61
answer += Catalog.GetString ("Every triangle counts as 1, each diamond as 2 and each square as 3.");
66
public override string Tip {
67
get { return Catalog.GetString ("Every diamond counts as two triangles.");}
70
public override void Initialize ()
73
group = random.Next (3);
75
for (int i = 0; i < elements; i++)
76
ans += balances [(group * elements * 6) + (4 * elements) + i];
78
right_answer = ans.ToString ();
81
public void DrawBalance (CairoContextEx gr, double x, double y, int index, bool full)
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;
87
gr.Rectangle (x + 0.05, y - 0.12, 0.38, 0.08);
90
gr.Rectangle (x + 0.5, y - 0.12, 0.38, 0.08);
93
for (int i = 0; i < total; i++) {
94
switch (balances[i + index]) {
96
gr.DrawEquilateralTriangle (fig_x, fig_y, 0.05);
99
gr.DrawDiamond (fig_x, fig_y, 0.05);
102
gr.Rectangle (fig_x, fig_y + 0.005, 0.045, 0.045);
106
if (i == elements - 1)
115
gr.LineTo (x + width, y);
116
gr.LineTo (x + width, y - 0.05);
120
gr.LineTo (x , y - 0.05);
123
gr.DrawEquilateralTriangle (x + (width / 2) - 0.04, y, 0.08);
128
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
130
double x = 0.05, y = DrawAreaY + 0.1;
132
base.Draw (gr, area_width, area_height, rtl);
134
DrawBalance (gr, x, y, group * elements * 6, true);
137
DrawBalance (gr, x, y, (group * elements * 6) + 1 * elements * 2, true);
140
DrawBalance (gr, x, y, (group * elements * 6) + 2 * elements * 2, false);