2
* Copyright (C) 2007 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.Logic
29
public class PuzzleSquaresAndLetters : Game
31
private char[] characters;
33
private const double figure_size = 0.2;
34
private const int figures = 3;
36
public override string Name {
37
get {return Catalog.GetString ("Squares and letters");}
40
public override string Question {
41
get {return Catalog.GetString ("The letters around the squares follow a logic. Which letter should replace the question mark in the last square?");}
44
public override string Answer {
46
string answer = base.Answer + " ";
47
answer += String.Format (Catalog.GetString ("Every letter is calculated by taking the alphabetical position of the previous character and adding {0} to it in order to get the position of the new letter."), step);
53
public override void Initialize ()
56
ArrayListIndicesRandom first_letters;
58
first_letters = new ArrayListIndicesRandom (figures); // Make sure that the first letter is never the same
59
first_letters.Initialize ();
60
step = random.Next (3) + 3;
62
characters = new char [(1 + figures) * 4];
63
for (int figure = 0; figure < figures; figure++) {
64
first_letter = first_letters [figure];
65
for (int letter = 0; letter < 4; letter++) {
66
characters[(figure * 4) + letter] = (char) (65 + first_letter + (step * letter));
70
right_answer = ToStr (characters[((figures - 1) * 4) + 3]);
71
characters[((figures - 1) * 4) + 3] = '?';
74
static string ToStr (char ch)
76
string s = string.Empty;
81
private void DrawRectangleWithText (CairoContextEx gr, double x, double y, int index)
83
gr.Rectangle (x, y, figure_size, figure_size);
85
gr.MoveTo (x - 0.04, y);
86
gr.ShowPangoText (ToStr (characters [index]));
89
gr.MoveTo (x + 0.01 + figure_size, y);
90
gr.ShowPangoText (ToStr (characters [index + 1]));
93
gr.MoveTo (x - 0.04, y + figure_size);
94
gr.ShowPangoText (ToStr (characters [index + 2]));
97
gr.MoveTo (x + 0.01 + figure_size, y + figure_size);
98
gr.ShowPangoText (ToStr (characters [index + 3]));
103
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
105
double x = DrawAreaX + 0.05, y = DrawAreaY + 0.1;
107
base.Draw (gr, area_width, area_height, rtl);
109
DrawRectangleWithText (gr, x, y, 0);
110
DrawRectangleWithText (gr, x + figure_size + 0.2, y, 4);
111
DrawRectangleWithText (gr, x + figure_size + 0.05, y + 0.2 + figure_size, 8);