~ubuntu-branches/ubuntu/lucid/gbrainy/lucid

« back to all changes in this revision

Viewing changes to src/Games/Logic/PuzzleSquaresAndLetters.cs

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-01-12 11:21:24 UTC
  • mfrom: (13.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100112112124-o4ztomxa0xfh2ulj
Tags: 1.30-1ubuntu1
* debian/control:
  - Revert build-depends to lucid versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007 Jordi Mas i Hernàndez <jmas@softcatala.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
using System;
 
21
using Cairo;
 
22
using Mono.Unix;
 
23
 
 
24
using gbrainy.Core.Main;
 
25
using gbrainy.Core.Libraries;
 
26
 
 
27
namespace gbrainy.Games.Logic
 
28
{
 
29
        public class PuzzleSquaresAndLetters : Game
 
30
        {
 
31
                private char[] characters;
 
32
                private int step;
 
33
                private const double figure_size = 0.2;
 
34
                private const int figures = 3;
 
35
 
 
36
                public override string Name {
 
37
                        get {return Catalog.GetString ("Squares and letters");}
 
38
                }
 
39
 
 
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?");} 
 
42
                }
 
43
 
 
44
                public override string Answer {
 
45
                        get { 
 
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);
 
48
 
 
49
                                return answer;
 
50
                        }
 
51
                }
 
52
 
 
53
                public override void Initialize ()
 
54
                {
 
55
                        int first_letter;
 
56
                        ArrayListIndicesRandom first_letters;
 
57
 
 
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;
 
61
 
 
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));
 
67
                                }                               
 
68
                        }
 
69
 
 
70
                        right_answer = ToStr (characters[((figures - 1) * 4) + 3]);
 
71
                        characters[((figures - 1) * 4) + 3] = '?';
 
72
                }
 
73
 
 
74
                static string ToStr (char ch)
 
75
                {
 
76
                        string s = string.Empty;
 
77
                        s+= ch;
 
78
                        return s;
 
79
                }
 
80
 
 
81
                private void DrawRectangleWithText (CairoContextEx gr, double x, double y, int index)
 
82
                {
 
83
                        gr.Rectangle (x, y, figure_size, figure_size);
 
84
 
 
85
                        gr.MoveTo (x - 0.04, y);
 
86
                        gr.ShowPangoText (ToStr (characters [index]));
 
87
                        gr.Stroke ();
 
88
 
 
89
                        gr.MoveTo (x + 0.01 + figure_size, y);
 
90
                        gr.ShowPangoText (ToStr (characters [index + 1]));
 
91
                        gr.Stroke ();
 
92
 
 
93
                        gr.MoveTo (x - 0.04, y + figure_size);
 
94
                        gr.ShowPangoText (ToStr (characters [index + 2]));
 
95
                        gr.Stroke ();
 
96
 
 
97
                        gr.MoveTo (x + 0.01 + figure_size, y + figure_size);
 
98
                        gr.ShowPangoText (ToStr (characters [index + 3]));
 
99
                        gr.Stroke ();
 
100
                }
 
101
 
 
102
 
 
103
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
104
                {
 
105
                        double x = DrawAreaX + 0.05, y = DrawAreaY + 0.1;
 
106
 
 
107
                        base.Draw (gr, area_width, area_height, rtl);
 
108
                
 
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);
 
112
                        
 
113
                }
 
114
        }
 
115
}