2
* Copyright (C) 2007-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 MemoryFigures : Memory
26
private ArrayListIndicesRandom figures;
29
private const double start_x_ques = 0.25;
30
private const double start_x_ans = 0.25;
31
private const double start_y = 0.15;
32
private const double figure_size = 0.08;
33
private double rect_w, rect_h;
34
private int question_pos, question_answer;
35
private int figures_active;
37
public enum FigureType
49
public override string Name {
50
get {return Catalog.GetString ("Memory figures");}
53
public override string MemoryQuestion {
55
return Catalog.GetString ("In which cell is the other figure like the one shown below? Answer the cell number." );}
58
public override void Initialize ()
62
switch (CurrentDifficulty) {
67
case Difficulty.Medium:
72
case Difficulty.Master:
78
rect_w = 0.65 / columns;
80
figures = new ArrayListIndicesRandom (figures_active * 2);
81
figures.Initialize ();
82
question_pos = random.Next (figures_active * 2);
84
for (int figure = 0; figure < figures_active * 2; figure++)
86
if (figure == question_pos)
89
fig1 = figures[figure];
90
fig2 = figures[question_pos];
92
if (fig1 >= figures_active) fig1 -= figures_active;
93
if (fig2 >= figures_active) fig2 -= figures_active;
96
question_answer = figure + 1;
100
right_answer = question_answer.ToString ();
104
public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
107
double x = start_x_ans, y = start_y;
108
gr.Color = new Color (DefaultDrawingColor.R, DefaultDrawingColor.G, DefaultDrawingColor.B, 1);
110
if (DrawAnswer == true) {
111
DrawAllFigures (gr, start_x_ans, start_y, area_width, area_height);
115
gr.SetPangoLargeFontSize ();
116
DrawGrid (gr, x, y, area_width, area_height);
117
for (int figure = 0; figure < figures.Count; figure++, col++)
119
fig = (int)figures[figure];
120
if (fig >= figures_active) fig -= figures_active;
122
if (figure == question_pos)
123
DrawFigure (gr, x, y, (FigureType) fig);
125
gr.DrawTextCentered (x + rect_w / 2, y + rect_h / 2, (figure + 1).ToString ());
129
if (col >= columns) {
139
public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
141
base.DrawObjectToMemorize (gr, area_width, area_height);
142
DrawAllFigures (gr, start_x_ques, start_y, area_width, area_height);
145
private void DrawAllFigures (CairoContextEx gr, double x, double y, int area_width, int area_height)
150
DrawGrid (gr, x, y, area_width, area_height);
151
gr.Color = new Color (DefaultDrawingColor.R, DefaultDrawingColor.G, DefaultDrawingColor.B, alpha);
152
for (int figure = 0; figure < figures.Count; figure++, col++)
154
fig = (int)figures[figure];
155
if (fig >= figures_active)
156
fig -= figures_active;
158
DrawFigure (gr, x, y, (FigureType) fig);
160
if (col >= columns) {
170
private void DrawFigure (CairoContextEx gr, double x, double y, FigureType fig)
172
double space_x, space_y;
174
space_x = (rect_w - figure_size) / 2;
175
space_y = (rect_h - figure_size) / 2;
178
case FigureType.Triangle:
179
gr.DrawEquilateralTriangle (x + space_x, y + space_y, figure_size);
181
case FigureType.Rectangle:
182
gr.Rectangle (x + space_x, y + space_y, figure_size, figure_size);
185
case FigureType.Diamond:
186
gr.DrawDiamond (x + space_x, y + space_y, figure_size);
188
case FigureType.Cercle:
189
gr.Arc (x + space_x + figure_size / 2, y + space_y + figure_size / 2, figure_size / 2, 0, 2 * Math.PI);
192
case FigureType.TriangleWithLine:
193
gr.DrawEquilateralTriangle (x + space_x, y + space_y, figure_size);
194
gr.MoveTo (x + space_x + figure_size / 2, y + space_y);
195
gr.LineTo (x + space_x + figure_size / 2, y + space_y + figure_size);
198
case FigureType.RectangleWithLine:
199
gr.Rectangle (x + space_x, y + space_y, figure_size, figure_size);
200
gr.MoveTo (x + space_x, y + space_y);
201
gr.LineTo (x + space_x + figure_size, y + space_y + figure_size);
202
gr.MoveTo (x + space_x + figure_size, y + space_y);
203
gr.LineTo (x + space_x, y + space_y + figure_size);
206
case FigureType.DiamondWithLine:
207
gr.DrawDiamond (x + space_x, y + space_y, figure_size);
208
gr.MoveTo (x + space_x + figure_size / 2, y + space_y);
209
gr.LineTo (x + space_x + figure_size / 2, y + space_y + figure_size);
212
case FigureType.CercleWithLine:
213
gr.Arc (x + space_x + figure_size / 2, y + space_y + figure_size / 2, figure_size / 2, 0, 2 * Math.PI);
215
gr.MoveTo (x + space_x + figure_size / 2, y + space_y);
216
gr.LineTo (x + space_x + figure_size / 2, y + space_y + figure_size);
222
private void DrawGrid (CairoContextEx gr, double x, double y, int area_width, int area_height)
224
gr.Color = new Color (DefaultDrawingColor.R, DefaultDrawingColor.G, DefaultDrawingColor.B, alpha);
225
for (int column = 0; column < columns; column++) {
226
for (int row = 0; row < rows; row++) {
227
gr.Rectangle (x + column * rect_w, y + row * rect_h, rect_w, rect_h);