2
* Copyright (C) 2008 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
public class PuzzleLargerShape : Game
26
private const double rect_witdh = 0.04, rect_height = 0.04, space_figures = 0.22;
27
private ArrayListIndicesRandom random_indices;
28
private const int answers = 4;
29
private char[] quest1, quest2, answer;
31
private ColorPalette palette;
33
private static char A = 'A';
34
private static char B = 'B';
35
private static char X = 'X'; // Transparent
38
private int g1rightanswer = 0;
39
private char [] g1question_A = new char []
45
private char [] g1question_B = new char []
52
private char [] g1answer = new char []
73
private int g2rightanswer = 0;
74
private char [] g2question_A = new char []
80
private char [] g2question_B = new char []
87
private char [] g2answer = new char []
107
public override string Name {
108
get {return Catalog.GetString ("Larger shape");}
111
public override string Question {
112
get {return String.Format (
113
Catalog.GetString ("Which larger shape can you make combining the first two figures? Answer {0}, {1}, {2} or {3}."),
114
GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
117
public override void Initialize ()
119
palette = new ColorPalette (ColorPalette.Id.PrimaryColors);
120
palette.Initialize ();
122
switch (random.Next (2)) {
124
quest1 = g1question_A;
125
quest2 = g1question_B;
127
ranswer = g1rightanswer;
130
quest1 = g2question_A;
131
quest2 = g2question_B;
133
ranswer = g2rightanswer;
137
random_indices = new ArrayListIndicesRandom (answers);
138
random_indices.Initialize ();
140
for (int i = 0; i < answers; i++)
142
if ((int) random_indices[i] == ranswer) {
143
right_answer = GetPossibleAnswer (i);
149
private Color ColorForPortion (char portion)
152
return palette.Cairo (1);
154
return palette.Cairo (0);
157
private void DrawSquare (CairoContextEx gr, double x, double y)
161
for (int i = 0; i < 2; i++) {
162
if (quest1 [i] != X) {
163
gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
164
gr.FillGradient (x + i * rect_witdh, y, rect_witdh, rect_height, ColorForPortion (quest1 [i]));
166
gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
169
if (quest1 [i + 2] != X) {
170
gr.Rectangle (x + i * rect_witdh, y + rect_height, rect_witdh, rect_height);
171
gr.FillGradient (x + i * rect_witdh, y + rect_height, rect_witdh, rect_height, ColorForPortion (quest1 [i + 2]));
173
gr.Rectangle (x + i * rect_witdh, y + rect_height, rect_witdh, rect_height);
178
private void DrawLShape (CairoContextEx gr, double x, double y)
183
for (int i = 0; i < 3; i++) { // XXXX
184
if (quest2 [i] != X) {
185
gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
186
gr.FillGradient (x + i * rect_witdh, y, rect_witdh, rect_height, ColorForPortion (quest2 [i]));
188
gr.Rectangle (x + i * rect_witdh, y, rect_witdh, rect_height);
192
for (int i = 0; i < 2; i++) {
193
if (quest2 [(i + 1) * 3] != X) {
194
gr.Rectangle (x, y + rect_height * (i + 1), rect_witdh, rect_height);
195
gr.FillGradient (x, y + rect_height * (i + 1), rect_witdh, rect_height, ColorForPortion (quest2 [(i + 1) * 3]));
197
gr.Rectangle (x, y + rect_height * (i + 1), rect_witdh, rect_height);
202
private void DrawPossibleAnswer (CairoContextEx gr, double x, double y, char [] portions, int figure, int seq)
204
const int columns = 3, rows = 3;
205
const double rect_w = 0.05, rect_h = 0.05;
206
int index = figure * columns * rows;
208
for (int row = 0; row < rows; row++) {
209
for (int column = 0; column < columns; column++) {
210
if (portions [index + column + (3 * row)] != X) {
211
gr.Rectangle (x + column * rect_w, y + row * rect_h, rect_w, rect_h);
212
gr.FillGradient (x + column * rect_w, y + row * rect_h, rect_w, rect_h, ColorForPortion (portions [index + column + (3 * row)]));
214
gr.Rectangle (x + column * rect_w, y + row * rect_h, rect_w, rect_h);
219
gr.MoveTo (x, y + 0.18);
220
gr.ShowPangoText (GetPossibleFigureAnswer (seq));
224
public override void Draw (CairoContextEx gr, int area_width, int area_height)
226
double x = DrawAreaX + 0.1, y = DrawAreaY;
228
base.Draw (gr, area_width, area_height);
230
DrawSquare (gr, x, y);
231
DrawLShape (gr, x + 0.4, y);
233
gr.MoveTo (0.1, 0.3);
234
gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
237
DrawPossibleAnswer (gr, x, y + 0.32, answer, random_indices [0], 0);
238
DrawPossibleAnswer (gr, x + 0.4, y + 0.32, answer, random_indices [1], 1);
239
DrawPossibleAnswer (gr, x, y + 0.6, answer, random_indices [2], 2);
240
DrawPossibleAnswer (gr, x + 0.4, y + 0.6, answer, random_indices [3], 3);