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
using gbrainy.Core.Main;
25
using gbrainy.Core.Libraries;
27
namespace gbrainy.Games.Memory
29
public class MemoryColouredFigures : Core.Main.Memory
39
private int columns, rows;
41
private double rect_w;
42
private double rect_h;
43
private SquareColor []squares_colours;
44
private ArrayListIndicesRandom answers_order;
45
private const int answers = 4;
46
private ColorPalette palette;
47
private int color_sheme;
48
private const double block_space = 0.35;
50
public override string Name {
51
get {return Catalog.GetString ("Colored figures");}
54
public override bool UsesColors {
58
public override string MemoryQuestion {
59
get { return String.Format (
60
Catalog.GetString ("Which of these figures was previously shown? Answer {0}, {1}, {2} or {3}."),
61
GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
64
public override void Initialize ()
66
switch (CurrentDifficulty) {
70
case Difficulty.Medium:
73
case Difficulty.Master:
78
squares = columns * rows;
80
rect_h = 0.3 / columns;
81
squares_colours = new SquareColor [squares * answers];
82
color_sheme = random.Next (2);
83
palette = new ColorPalette(ColorPalette.Id.PrimarySecundaryColors);
86
for (int i = 0; i < squares; i++)
87
squares_colours[i] = (SquareColor) random.Next ((int) SquareColor.Length);
89
Randomize (squares_colours, 0, squares);
90
Randomize (squares_colours, 0, squares * 2);
91
Randomize (squares_colours, 0, squares * 3);
93
answers_order = new ArrayListIndicesRandom (answers);
94
answers_order.Initialize ();
96
for (int i = 0; i < answers_order.Count; i++) {
97
if (answers_order[i] == 0) {
98
right_answer += GetPossibleAnswer (i);
106
private void Randomize (SquareColor []colours, int source, int target)
108
int elements = 4 + random.Next (2);
111
while (done == false) {
112
for (int i = 0; i < squares; i++) {
113
colours[i + target] = colours[i + source];
116
for (int i = 0; i < elements; i++) {
117
colours[target + random.Next (squares)] = (SquareColor) random.Next ((int) SquareColor.Length);
120
// Is not valid if it is already present
122
for (int answer = 0; answer < answers; answer++) {
123
if (answer * squares == target)
127
for (int i = 0; i < squares; i++) {
128
if (colours[i + target] != colours[i + (answer * squares)]) {
143
public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
145
double x = DrawAreaX, y = DrawAreaY;
147
palette.Alpha = alpha;
149
for (int i = 0; i < answers_order.Count; i++) {
154
DrawSquare (gr, x, y, squares_colours, squares * answers_order[i]);
155
gr.MoveTo (x, y + block_space - 0.02);
156
gr.ShowPangoText (GetPossibleFigureAnswer (i));
158
x += block_space + 0.08;
162
public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
164
base.DrawObjectToMemorize (gr, area_width, area_height);
165
palette.Alpha = alpha;
166
DrawSquare (gr, DrawAreaX + 0.3, DrawAreaY + 0.1, squares_colours, 0);
169
private void DrawSquare (CairoContextEx gr, double x, double y, SquareColor []colours, int index)
172
for (int column = 0; column < columns; column++) {
173
for (int row = 0; row < rows; row++) {
175
// if you want 2 schemes (primary or secundary colors)
176
Color c = palette.Cairo(ColorPalette.Id.First+ color_sheme*3 + (int)colours[index+(columns * row) + column]);
177
gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
178
gr.FillGradient (x + row * rect_w, y + column * rect_h, rect_w, rect_h, c);
182
for (int column = 0; column < columns; column++) {
183
for (int row = 0; row < rows; row++) {
184
gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);