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
using gbrainy.Core.Main;
25
using gbrainy.Core.Libraries;
27
namespace gbrainy.Games.Memory
29
public class MemoryIndications : Core.Main.Memory
36
public Indication (Type type, object obj)
49
public enum TurnDirection
57
public void Draw (CairoContextEx gr, ref double x, ref double y, Indication next_prev)
59
const double line_length = 0.050;
60
const double points = 0.050;
62
if (type == Type.Start) {
63
gr.Rectangle (x, y, points, points);
64
gr.DrawTextCentered (x + points /2 , y + points /2, ((int)obj).ToString ());
65
switch ((TurnDirection) next_prev.obj) {
66
case TurnDirection.Right:
70
case TurnDirection.Left:
73
case TurnDirection.Down:
77
case TurnDirection.Up:
84
} else if (type == Type.Turn) {
86
switch ((TurnDirection) obj) {
87
case TurnDirection.Right:
90
case TurnDirection.Left:
93
case TurnDirection.Up:
96
case TurnDirection.Down:
103
} else if (type == Type.End) {
104
switch ((TurnDirection) next_prev.obj) {
105
case TurnDirection.Right:
108
case TurnDirection.Left:
112
case TurnDirection.Down:
115
case TurnDirection.Up:
120
gr.Rectangle (x, y, points, points);
122
gr.DrawTextCentered (x + points /2 , y + points /2, ((int)obj).ToString ());
126
public override string ToString ()
130
return String.Format (Catalog.GetString ("Start at point number {0}"), (int) obj);
132
switch ((TurnDirection) obj) {
133
case TurnDirection.Right:
134
return Catalog.GetString ("Turn right");
135
case TurnDirection.Left:
136
return Catalog.GetString ("Turn left");
137
case TurnDirection.Up:
138
return Catalog.GetString ("Go up");
139
case TurnDirection.Down:
140
return Catalog.GetString ("Go down");
145
return String.Format (Catalog.GetString ("End at point {0}"), obj);
151
private Indication[] indications;
152
private Indication[] indications_wrongA;
153
private Indication[] indications_wrongB;
154
private Indication[] indications_wrongC;
155
private ArrayListIndicesRandom answers;
158
public override string Name {
159
get {return Catalog.GetString ("Memorize indications");}
162
public override string MemoryQuestion {
164
return String.Format (
165
Catalog.GetString ("Which of the following graphics represent the indications previously given? Answer {0}, {1}, {2} or {3}."),
166
GetPossibleAnswer (0), GetPossibleAnswer (1), GetPossibleAnswer (2), GetPossibleAnswer (3));}
169
public override void Initialize ()
171
indications = new Indication [CurrentDifficulty == Difficulty.Easy ? 5 : 7];
172
Indication.TurnDirection second_turn = (Indication.TurnDirection) 2 + random.Next (2);
174
indications[0] = new Indication (Indication.Type.Start, 0);
175
indications[1] = new Indication (Indication.Type.Turn, random.Next (2)); // right or left
176
indications[2] = new Indication (Indication.Type.Turn, second_turn); // up or down
177
indications[3] = new Indication (Indication.Type.Turn, random.Next (2)); // right or left
179
if (CurrentDifficulty==Difficulty.Easy) {
180
indications[4] = new Indication (Indication.Type.End, 1);
182
if (second_turn == Indication.TurnDirection.Up)
183
indications[4] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Up);
185
indications[4] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Down);
187
indications[5] = new Indication (Indication.Type.Turn, random.Next (2)); // right or left
188
indications[6] = new Indication (Indication.Type.End, 1);
191
indications_wrongA = CopyAnswer ();
192
indications_wrongB = CopyAnswer ();
193
indications_wrongC = CopyAnswer ();
195
if ((Indication.TurnDirection) indications[3].obj == Indication.TurnDirection.Right) {
196
indications_wrongA[3] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Left);
199
indications_wrongA[3] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Right);
202
if (CurrentDifficulty == Difficulty.Easy) {
203
if ((Indication.TurnDirection) indications[2].obj == Indication.TurnDirection.Up) {
204
indications_wrongB[2] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Down);
207
indications_wrongB[2] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Up);
210
if ((Indication.TurnDirection) indications[5].obj == Indication.TurnDirection.Right) {
211
indications_wrongB[5] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Left);
214
indications_wrongB[5] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Right);
218
if ((Indication.TurnDirection) indications[1].obj == Indication.TurnDirection.Right) {
219
indications_wrongC[1] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Left);
222
indications_wrongC[1] = new Indication (Indication.Type.Turn, Indication.TurnDirection.Right);
227
answers = new ArrayListIndicesRandom (4);
228
answers.Initialize ();
230
for (int i = 0; i < answers.Count; i++) {
231
if (answers [i] == 0) {
232
right_answer = GetPossibleAnswer (i);
238
//for (int i = 0; i < indications.Length; i++)
239
// Console.WriteLine ("{0}", indications[i].ToString ());
242
private Indication[] CopyAnswer ()
244
Indication[] answer = new Indication [indications.Length];
245
for (int i = 0; i < indications.Length; i++)
246
answer[i] = new Indication (indications[i].type, indications[i].obj);
251
private static void DrawPossibleAnswers (CairoContextEx gr, double x, double y, Indication[] indications)
253
for (int i = 0; i < indications.Length - 1; i++)
254
indications[i].Draw (gr, ref x, ref y, indications[i + 1]);
256
indications[indications.Length - 1].Draw (gr, ref x, ref y, indications[indications.Length - 2]);
259
private Indication[] WhichAnswer (object answer)
261
switch ((int) answer) {
265
return indications_wrongA;
267
return indications_wrongB;
269
return indications_wrongC;
275
public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
280
DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[0]));
281
gr.MoveTo (x, y + 0.2);
282
gr.ShowPangoText (GetPossibleFigureAnswer (0));
285
DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[1]));
286
gr.MoveTo (x, y + 0.2);
287
gr.ShowPangoText (GetPossibleFigureAnswer (1));
290
DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[2]));
291
gr.MoveTo (x, y + 0.2);
292
gr.ShowPangoText (GetPossibleFigureAnswer (2));
295
DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[3]));
296
gr.MoveTo (x, y + 0.2);
297
gr.ShowPangoText (GetPossibleFigureAnswer (3));
300
public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
302
base.DrawObjectToMemorize (gr, area_width, area_height);
304
if (DrawAnswer == false) {
305
for (int i = 0; i < indications.Length; i++)
307
gr.MoveTo (0.3, 0.2 + i * 0.08);
308
gr.ShowPangoText (indications[i].ToString ());
312
for (int i = 0; i < indications.Length; i++)
314
gr.MoveTo (0.1, 0.2 + i * 0.08);
315
gr.ShowPangoText (indications[i].ToString ());
318
DrawPossibleAnswers (gr, 0.7, 0.3, WhichAnswer (answers[ans]));
319
gr.MoveTo (0.7, 0.5);
320
gr.ShowPangoText (GetPossibleFigureAnswer (ans));