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.Logic
29
public class PuzzleClocks : Game
31
private const double figure_size = 0.3;
32
private const double radian = Math.PI / 180;
34
private int []handles;
35
private const int clocks = 4;
36
private const int handle_num = 2;
38
public override string Name {
39
get {return Catalog.GetString ("Clocks");}
42
public override string Question {
43
get {return (String.Format (
44
Catalog.GetString ("To what number should the large handle of the '{0}' clock point? Answer using numbers."),
45
GetPossibleFigureAnswer (3)));}
48
public override string Answer {
50
string answer = base.Answer + " ";
51
answer += String.Format (Catalog.GetString ("Starting from the first clock sum {0} to the value indicated by the hands."), addition);
56
public override string Tip {
57
get { return Catalog.GetString ("The clocks do not follow the time logic.");}
60
public override void Initialize ()
64
// In all these cases the clock logic clearly do not work since the small hand is in the next hour
65
switch (random.Next (3)) {
81
handles = new int [clocks * handle_num];
83
for (int i = 0; i < handles.Length; i++, i++)
85
handles [i] = position / 10;
86
handles [i + 1] = position - ((position / 10) * 10);
90
right_answer = handles[7].ToString ();
92
/*DateTime dt1 = new DateTime (2008, 2, 20, handles[0], handles[1] * 5, 0);
93
DateTime dt2 = new DateTime (2008, 2, 20, handles[2], handles[3] * 5, 0);
94
Console.WriteLine ("t1 {0}", dt1);
95
Console.WriteLine ("t2 {0}", dt2);
96
Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);
98
dt1 = new DateTime (2008, 2, 20, handles[2], handles[3] * 5, 0);
99
dt2 = new DateTime (2008, 2, 20, handles[4], handles[5] * 5, 0);
100
Console.WriteLine ("t1 {0}", dt1);
101
Console.WriteLine ("t2 {0}", dt2);
102
Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);
104
dt1 = new DateTime (2008, 2, 20, handles[4], handles[5] * 5, 0);
105
dt2 = new DateTime (2008, 2, 20, handles[6], handles[7] * 5, 0);
106
Console.WriteLine ("t1 {0}", dt1);
107
Console.WriteLine ("t2 {0}", dt2);
108
Console.WriteLine ("Time diff {0} from 1st to 2nd", dt2-dt1);*/
112
static void DrawClock (CairoContextEx gr, double x, double y, int hand_short, int hand_large, bool draw_large)
114
const double radius = figure_size / 2;
118
gr.Arc (x, y, radius, 0, 2 * Math.PI);
120
for (degrees = 0; degrees < 360; degrees+= 30) {
121
x0 = radius * Math.Cos (degrees * radian);
122
y0 = radius * Math.Sin (degrees * radian);
124
gr.MoveTo (x + 0.9 * x0, y + 0.9 * y0);
125
gr.LineTo (x + x0, y + y0);
128
num = (degrees / 30) + 3;
129
if (num > 12) num = num - 12;
131
gr.DrawTextCentered (x + x0 * 0.75, y + y0 * 0.75, num.ToString ());
137
degrees = (hand_large - 3) * 30;
138
x0 = radius * Math.Cos (degrees * radian);
139
y0 = radius * Math.Sin (degrees * radian);
141
gr.LineTo (x + x0 * 0.55, y + y0 * 0.55);
145
degrees = (hand_short - 3) * 30;
146
x0 = radius * Math.Cos (degrees * radian);
147
y0 = radius * Math.Sin (degrees * radian);
149
gr.LineTo (x + x0 * 0.4, y + y0 * 0.4);
153
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
155
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
157
base.Draw (gr, area_width, area_height, rtl);
159
DrawClock (gr, x + 0.1, y + 0.1, handles[0], handles[1], true);
160
gr.MoveTo (x + 0.03, y + 0.29);
161
gr.ShowPangoText (GetPossibleFigureAnswer (0));
164
DrawClock (gr, x + 0.5, y + 0.1, handles[2], handles[3], true);
165
gr.MoveTo (x + 0.43, y + 0.29);
166
gr.ShowPangoText (GetPossibleFigureAnswer (1));
169
DrawClock (gr, x + 0.1, y + 0.52, handles[4], handles[5], true);
170
gr.MoveTo (x + 0.03, y + 0.71);
171
gr.ShowPangoText (GetPossibleFigureAnswer (2));
174
DrawClock (gr, x + 0.5, y + 0.52, handles[6], handles[7], DrawAnswer == true);
175
gr.MoveTo (x + 0.43, y + 0.71);
176
gr.ShowPangoText (GetPossibleFigureAnswer (3));