2
* Copyright (C) 2007 Javier M Mora <javiermm@gmail.com>
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 MemoryCountDots : Memory
26
private const int NUMCOLUMNS = 7;
27
private const int MINDOTS = 1;
28
private const int MAXDOTS = 25;
29
private int maxdotscolor;
31
private ArrayListIndicesRandom location_order;
32
private ColorPalette palette;
34
private int [] dotsPerColor;
36
public override string Name {
37
get {return Catalog.GetString ("Counting dots");}
40
public override string MemoryQuestion {
41
get { return String.Format(Catalog.GetString ("How many {0} dots were in the previous image? Answer using numbers."),
45
public override void Initialize ()
47
switch (CurrentDifficulty) {
51
case Difficulty.Medium:
54
case Difficulty.Master:
59
location_order = new ArrayListIndicesRandom (NUMCOLUMNS*NUMCOLUMNS);
60
location_order.Initialize();
62
palette = new ColorPalette(ColorPalette.Id.Last);
65
// dotsPerColor is compared with iterator of dots. (this iterator is 0 based, so I
66
// have to substract 1 to make dotsPerColor contents 0 based.
67
dotsPerColor = new int [palette.Count];
68
for (int i=0,before=-1; i< palette.Count; i++) {
69
dotsPerColor[i] = before + MINDOTS + random.Next(maxdotscolor-MINDOTS+1);
70
before = dotsPerColor[i];
73
right_answer = (dotsPerColor[0]+1).ToString ();
78
public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
80
base.DrawObjectToMemorize (gr, area_width, area_height);
81
DrawObject (gr, area_width, area_height);
84
private void DrawObject (CairoContextEx gr, int area_width, int area_height)
86
palette.Alpha = alpha;
87
double x = DrawAreaX + 0.15, y = DrawAreaY + 0.1;
89
gr.Color = palette.Cairo(ColorPalette.Id.Black);
90
double pos_x = x, pos_y = y;
91
const double figure_size = 0.6;
92
const double square_size = figure_size / NUMCOLUMNS ;
93
const double center_square = square_size / 2;
94
double radius_square = .8 * (square_size - (LineWidth *2)) / 2;
96
gr.Rectangle (pos_x, pos_y, figure_size, figure_size);
99
for (int line = 0; line < NUMCOLUMNS - 1; line++) // Horizontal
101
pos_y += square_size;
102
gr.MoveTo (pos_x, pos_y);
103
gr.LineTo (pos_x + figure_size, pos_y);
108
for (int column = 0; column < NUMCOLUMNS - 1; column++) // Vertical
110
pos_x += square_size;
111
gr.MoveTo (pos_x, pos_y);
112
gr.LineTo (pos_x, pos_y + figure_size);
116
pos_y = y + center_square;
117
pos_x = x + center_square;
119
for (int i = 0,itcolor=0; i < MAXDOTS && itcolor<palette.Count; i++)
122
Color color = palette.Cairo(itcolor);
123
dx = (location_order[i]) % NUMCOLUMNS;
124
dy = (location_order[i]) / NUMCOLUMNS;
126
gr.Arc (pos_x+square_size*dx, pos_y+square_size*dy,radius_square,0,2*Math.PI);
127
gr.FillGradient (pos_x+square_size*dx, pos_y+square_size*dy, radius_square, radius_square, color);
129
if (i==dotsPerColor[itcolor]) itcolor++;