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

« back to all changes in this revision

Viewing changes to src/Games/Logic/PuzzleClocks.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) 2008 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 Cairo;
 
21
using Mono.Unix;
 
22
using System;
 
23
 
 
24
using gbrainy.Core.Main;
 
25
using gbrainy.Core.Libraries;
 
26
 
 
27
namespace gbrainy.Games.Logic
 
28
{
 
29
        public class PuzzleClocks : Game
 
30
        {
 
31
                private const double figure_size = 0.3;
 
32
                private const double radian = Math.PI / 180;
 
33
                private int addition;
 
34
                private int []handles;
 
35
                private const int clocks = 4;
 
36
                private const int handle_num = 2;
 
37
 
 
38
                public override string Name {
 
39
                        get {return Catalog.GetString ("Clocks");}
 
40
                }
 
41
 
 
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)));}
 
46
                }
 
47
 
 
48
                public override string Answer {
 
49
                        get { 
 
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);
 
52
                                return answer;
 
53
                        }
 
54
                }
 
55
 
 
56
                public override string Tip {
 
57
                        get { return Catalog.GetString ("The clocks do not follow the time logic.");}
 
58
                }
 
59
 
 
60
                public override void Initialize ()
 
61
                {
 
62
                        int position;
 
63
 
 
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)) {
 
66
                        case 0:
 
67
                                position = 48;
 
68
                                addition = 5;
 
69
                                break;
 
70
                        case 1:
 
71
                                position = 38;
 
72
                                addition = 15;
 
73
                                break;
 
74
                        case 2:
 
75
                        default:
 
76
                                position = 24;
 
77
                                addition = 5;
 
78
                                break;
 
79
                        }
 
80
 
 
81
                        handles = new int [clocks * handle_num];
 
82
 
 
83
                        for (int i = 0; i < handles.Length; i++, i++)
 
84
                        {
 
85
                                handles [i] = position / 10;
 
86
                                handles [i + 1] = position - ((position / 10) * 10);
 
87
                                position += addition;
 
88
                        }
 
89
                
 
90
                        right_answer = handles[7].ToString ();
 
91
 
 
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);
 
97
 
 
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);
 
103
 
 
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);*/
 
109
 
 
110
                }       
 
111
 
 
112
                static void DrawClock (CairoContextEx gr, double x, double y, int hand_short, int hand_large, bool draw_large)
 
113
                {
 
114
                        const double radius = figure_size / 2;
 
115
                        double x0, y0;
 
116
                        int num, degrees;
 
117
 
 
118
                        gr.Arc (x, y, radius, 0, 2 * Math.PI);
 
119
                        gr.Stroke ();
 
120
                        for (degrees = 0; degrees < 360; degrees+= 30) {
 
121
                                x0 = radius * Math.Cos (degrees * radian);
 
122
                                y0 = radius * Math.Sin (degrees * radian);
 
123
                                 // Small lines
 
124
                                gr.MoveTo (x + 0.9 * x0, y + 0.9 * y0);
 
125
                                gr.LineTo (x + x0, y + y0);
 
126
                                gr.Stroke ();
 
127
                                // Numbers
 
128
                                num = (degrees / 30) + 3;
 
129
                                if (num > 12) num = num - 12;
 
130
 
 
131
                                gr.DrawTextCentered (x + x0 * 0.75,  y + y0 * 0.75, num.ToString ());
 
132
                                gr.Stroke ();
 
133
                        }
 
134
 
 
135
                        if (draw_large) {
 
136
                                // Hand Large
 
137
                                degrees = (hand_large - 3) * 30; 
 
138
                                x0 = radius * Math.Cos (degrees * radian);
 
139
                                y0 = radius * Math.Sin (degrees * radian);
 
140
                                gr.MoveTo (x, y);
 
141
                                gr.LineTo (x + x0 * 0.55, y + y0 * 0.55);
 
142
                                gr.Stroke ();
 
143
                        }
 
144
                        // Hand Short
 
145
                        degrees = (hand_short - 3) * 30; 
 
146
                        x0 = radius * Math.Cos (degrees * radian);
 
147
                        y0 = radius * Math.Sin (degrees * radian);
 
148
                        gr.MoveTo (x, y);
 
149
                        gr.LineTo (x + x0 * 0.4, y + y0 * 0.4);
 
150
                        gr.Stroke ();
 
151
                }
 
152
 
 
153
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
154
                {
 
155
                        double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
 
156
 
 
157
                        base.Draw (gr, area_width, area_height, rtl);
 
158
 
 
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));
 
162
                        gr.Stroke ();
 
163
        
 
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));
 
167
                        gr.Stroke ();
 
168
 
 
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));
 
172
                        gr.Stroke ();
 
173
 
 
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));
 
177
                        gr.Stroke ();
 
178
 
 
179
                }
 
180
        }
 
181
}