~ubuntu-branches/ubuntu/karmic/gbrainy/karmic

« back to all changes in this revision

Viewing changes to src/PuzzleCountCircles.cs

  • Committer: Bazaar Package Importer
  • Author(s): Siegfried-Angel Gevatter Pujals
  • Date: 2008-08-25 22:29:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825222928-05c3vijmjk0i9xmk
Tags: 0.99-0ubuntu1
* Note:
   - This revision has been taken from Debian's SVN without waiting for it
     to get into Debian experimental, as Feature Freeze is approaching.
* New upstream version:
   - Two new games (one logic, one memory), better look and feel, switch font
     drawing to Pango, better internationalization support and bug fixes.
* debian/control:
   - Add librsvg2-2.18-cil as a build dependency.
   - Bump minimum cli-common-dev version in the build dependencies to 0.4.4.
   - Bump Standards Version to 3.8.0.
   - Fix a typo in the long description (designerd -> designed).
* debian/patches/configure-rsvg2.patch, debian/rules:
   - Change "librsvg-2.0" to "rsvg2-sharp-2.0" in configure{,.in}.

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
 
public class PuzzleCountCircles : Game
25
 
{
26
 
        private const double figure_size = 0.3;
27
 
        private const double radian = Math.PI / 180;
28
 
        private int n_circles;
29
 
 
30
 
        class ItemCircle
31
 
        {
32
 
                public double x, y, rad;
33
 
 
34
 
                public ItemCircle (double x, double y, double rad)
35
 
                {
36
 
                        this.x = x;
37
 
                        this.y = y;
38
 
                        this.rad = rad;
39
 
                }
40
 
        }
41
 
 
42
 
        ItemCircle[] circles;
43
 
 
44
 
        public override string Name {
45
 
                get {return Catalog.GetString ("Count circles");}
46
 
        }
47
 
 
48
 
        public override string Question {
49
 
                get {return Catalog.GetString ("How many circles do you count?");} 
50
 
        }
51
 
 
52
 
        public override string Tip {
53
 
                get { return Catalog.GetString ("It is an easy exercise if you systematically count the circles.");}
54
 
        }
55
 
 
56
 
        public override void Initialize ()
57
 
        {
58
 
                double x, y, rad;
59
 
 
60
 
                switch (CurrentDifficulty) {
61
 
                case Difficulty.Easy:
62
 
                        n_circles = 7;
63
 
                        break;
64
 
                case Difficulty.Master:
65
 
                        n_circles = 14;
66
 
                        break;          
67
 
                case Difficulty.Medium:
68
 
                default:
69
 
                        n_circles = 10;
70
 
                        break;          
71
 
                }
72
 
 
73
 
                n_circles += random.Next (5);
74
 
                circles = new ItemCircle [n_circles];
75
 
                for (int i = 0; i < circles.Length; i++)
76
 
                {
77
 
                        x = random.Next (500) / 1000d;
78
 
                        y = random.Next (500) / 1000d;
79
 
                        rad = 0.03 +  random.Next (500) / 3200d;
80
 
 
81
 
                        circles[i] = new ItemCircle (x, y, rad);
82
 
                }
83
 
 
84
 
                right_answer = n_circles.ToString ();
85
 
        }       
86
 
 
87
 
 
88
 
        public override void Draw (CairoContextEx gr, int area_width, int area_height)
89
 
        {
90
 
                double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
91
 
 
92
 
                gr.Scale (area_width, area_height);
93
 
                DrawBackground (gr);
94
 
                PrepareGC (gr);
95
 
 
96
 
                for (int i = 0; i < circles.Length; i++)
97
 
                {
98
 
                        gr.Arc (x + circles[i].x + 0.1, y + circles[i].y + 0.1, circles[i].rad, 0, 2 * Math.PI);
99
 
                        gr.Stroke ();
100
 
                }
101
 
        }
102
 
}
103
 
 
104