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

« back to all changes in this revision

Viewing changes to src/MemoryGames/MemoryCountDots.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 Javier M Mora <javiermm@gmail.com>
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
 
public class MemoryCountDots : Memory
25
 
{
26
 
        private const int NUMCOLUMNS = 7;
27
 
        private const int MINDOTS = 1;
28
 
        private const int MAXDOTS = 25;
29
 
        private int maxdotscolor;
30
 
 
31
 
        private ArrayListIndicesRandom location_order;
32
 
        private ColorPalette palette;
33
 
 
34
 
        private int [] dotsPerColor;
35
 
 
36
 
        public override string Name {
37
 
                get {return Catalog.GetString ("Counting dots");}
38
 
        }
39
 
 
40
 
        public override string MemoryQuestion {
41
 
                get { return String.Format(Catalog.GetString ("How many {0} dots were in the previous image? Answer using numbers."),
42
 
                                                palette.Name(0)); }
43
 
        }
44
 
 
45
 
        public override void Initialize ()
46
 
        {
47
 
                switch (CurrentDifficulty) {
48
 
                case Difficulty.Easy:
49
 
                        maxdotscolor = 2;
50
 
                        break;
51
 
                case Difficulty.Medium:
52
 
                        maxdotscolor = 5;
53
 
                        break;
54
 
                case Difficulty.Master:
55
 
                        maxdotscolor = 8;
56
 
                        break;
57
 
                }
58
 
 
59
 
                location_order = new ArrayListIndicesRandom (NUMCOLUMNS*NUMCOLUMNS);
60
 
                location_order.Initialize();
61
 
 
62
 
                palette = new ColorPalette(ColorPalette.Id.Last);
63
 
                palette.Initialize();
64
 
 
65
 
                // dotsPerColor is compared with iterator of dots. (this iterator is 0 based, so I
66
 
                // have to substract 1 to make dotsPerColor contents 0 based.
67
 
                dotsPerColor = new int [palette.Count];
68
 
                for (int i=0,before=-1; i< palette.Count; i++) {
69
 
                        dotsPerColor[i] = before + MINDOTS + random.Next(maxdotscolor-MINDOTS+1);
70
 
                        before = dotsPerColor[i];
71
 
                }
72
 
 
73
 
                right_answer = (dotsPerColor[0]+1).ToString ();
74
 
                
75
 
                base.Initialize ();
76
 
        }
77
 
 
78
 
        public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
79
 
        {
80
 
                base.DrawObjectToMemorize (gr, area_width, area_height);
81
 
                DrawObject (gr, area_width, area_height);
82
 
        }
83
 
 
84
 
        private void DrawObject (CairoContextEx gr, int area_width, int area_height)
85
 
        {
86
 
                palette.Alpha = alpha;
87
 
                double x = DrawAreaX + 0.15, y = DrawAreaY + 0.1;
88
 
 
89
 
                gr.Color = palette.Cairo(ColorPalette.Id.Black);
90
 
                double pos_x = x, pos_y = y;
91
 
                const double figure_size = 0.6;
92
 
                const double square_size = figure_size / NUMCOLUMNS ;
93
 
                const double center_square = square_size / 2;
94
 
                double radius_square = .8 * (square_size - (LineWidth *2)) / 2;
95
 
 
96
 
                gr.Rectangle (pos_x, pos_y, figure_size, figure_size);
97
 
                gr.Stroke ();
98
 
 
99
 
                for (int line = 0; line < NUMCOLUMNS - 1; line++) // Horizontal
100
 
                {
101
 
                        pos_y += square_size;
102
 
                        gr.MoveTo (pos_x, pos_y);
103
 
                        gr.LineTo (pos_x + figure_size, pos_y);
104
 
                        gr.Stroke ();
105
 
                }
106
 
 
107
 
                pos_y = y;
108
 
                for (int column = 0; column < NUMCOLUMNS - 1; column++) // Vertical
109
 
                {
110
 
                        pos_x += square_size;
111
 
                        gr.MoveTo (pos_x, pos_y);
112
 
                        gr.LineTo (pos_x, pos_y + figure_size);
113
 
                        gr.Stroke ();
114
 
                }
115
 
 
116
 
                pos_y = y + center_square;
117
 
                pos_x = x + center_square;
118
 
 
119
 
                for (int i = 0,itcolor=0; i < MAXDOTS && itcolor<palette.Count; i++)
120
 
                {
121
 
                        int dx,dy;
122
 
                        Color color = palette.Cairo(itcolor);
123
 
                        dx = (location_order[i]) % NUMCOLUMNS;
124
 
                        dy = (location_order[i]) / NUMCOLUMNS;
125
 
 
126
 
                        gr.Arc (pos_x+square_size*dx, pos_y+square_size*dy,radius_square,0,2*Math.PI);
127
 
                        gr.FillGradient (pos_x+square_size*dx, pos_y+square_size*dy, radius_square, radius_square, color);
128
 
 
129
 
                        if (i==dotsPerColor[itcolor]) itcolor++;
130
 
                }
131
 
        }
132
 
}
133
 
 
134