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

« back to all changes in this revision

Viewing changes to src/Games/Memory/MemoryColouredText.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 Mono.Unix;
 
22
 
 
23
using gbrainy.Core.Main;
 
24
using gbrainy.Core.Libraries;
 
25
 
 
26
namespace gbrainy.Games.Memory
 
27
{
 
28
        public class MemoryColouredText : Core.Main.Memory
 
29
        {
 
30
                private ColorPalette palette;
 
31
                private int question;
 
32
                private string question_colorname;
 
33
                private int colors_shown;
 
34
 
 
35
                public override string Name {
 
36
                        get {return Catalog.GetString ("Colored text");}
 
37
                }
 
38
 
 
39
                public override bool UsesColors {
 
40
                        get { return true;}
 
41
                }
 
42
 
 
43
                public override string MemoryQuestion {
 
44
                        get { 
 
45
                                return String.Format (Catalog.GetString ("What was the color of the text that said '{0}'?"), question_colorname);}
 
46
                }
 
47
 
 
48
                public override void Initialize ()
 
49
                {
 
50
                        switch (CurrentDifficulty) {
 
51
                        case Difficulty.Easy:
 
52
                                colors_shown = 3;
 
53
                                break;
 
54
                        case Difficulty.Medium:
 
55
                                colors_shown = 4;
 
56
                                break;
 
57
                        case Difficulty.Master:
 
58
                                colors_shown = 6;
 
59
                                break;
 
60
                        }
 
61
 
 
62
                        palette = new ColorPalette (colors_shown);
 
63
                        palette.Initialize ();
 
64
                
 
65
                        question = random.Next (palette.Count);
 
66
                        right_answer = palette.Name (question);
 
67
                        question_colorname = palette.Name ((ColorPalette.Id) question);
 
68
                
 
69
                        base.Initialize ();
 
70
                }
 
71
        
 
72
                public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
 
73
                {
 
74
                        base.DrawObjectToMemorize (gr, area_width, area_height);
 
75
                        DrawObject (gr);
 
76
                }
 
77
 
 
78
                private void DrawObject (CairoContextEx gr)
 
79
                {
 
80
                        palette.Alpha=alpha;
 
81
 
 
82
                        double x= DrawAreaX + 0.125, y = DrawAreaY + 0.2;
 
83
 
 
84
                        for (int i = 0; i < palette.Count ; i++)
 
85
                        {
 
86
                                gr.Color = palette.Cairo(i);
 
87
                                gr.MoveTo (x, y);
 
88
                                gr.ShowPangoText ( palette.Name((ColorPalette.Id)i) );
 
89
                                gr.Stroke ();
 
90
                        
 
91
                                if (i == 2) {
 
92
                                        y += 0.2;
 
93
                                        x = DrawAreaX + 0.125;
 
94
                                } else {
 
95
                                        x+= 0.25;
 
96
                                }
 
97
                        }
 
98
                }
 
99
        }
 
100
}