gbrainy r190 - trunk/src
- From: jmas svn gnome org
- To: svn-commits-list gnome org
- Subject: gbrainy r190 - trunk/src
- Date: Wed, 30 Jan 2008 21:45:58 +0000 (GMT)
Author: jmas
Date: Wed Jan 30 21:45:58 2008
New Revision: 190
URL: http://svn.gnome.org/viewvc/gbrainy?rev=190&view=rev
Log:
2008-01-29 Jordi Mas <jmas softcatala org>
* MemoryCountDots.cs: Implement difficult levels in the game
* MemoryColouredFigures.cs: Implement difficult levels in the game
* MemoryNumbers.cs: Implement difficult levels in the game
* MemoryColouredText.cs: Implement difficult levels in the game
* PreferencesDialog.cs: Add difficulty levels options
* GameManager.cs: Add difficult levels
* Game.cs: Add difficulty levels
* GameSession.cs: Difficulty levels for the game session
* PuzzleCirclesRectangle.cs: Include level for the game (only master)
* MemoryWords.cs: Add difficulty levels options
* gbrainy.cs: Add difficulty level support
* gbrainy.glade: New preferences options
Modified:
trunk/src/ChangeLog
trunk/src/Game.cs
trunk/src/GameManager.cs
trunk/src/GameSession.cs
trunk/src/MemoryColouredFigures.cs
trunk/src/MemoryColouredText.cs
trunk/src/MemoryCountDots.cs
trunk/src/MemoryNumbers.cs
trunk/src/MemoryWords.cs
trunk/src/PreferencesDialog.cs
trunk/src/PuzzleCirclesRectangle.cs
trunk/src/gbrainy.cs
trunk/src/gbrainy.glade
Modified: trunk/src/Game.cs
==============================================================================
--- trunk/src/Game.cs (original)
+++ trunk/src/Game.cs Wed Jan 30 21:45:58 2008
@@ -31,6 +31,14 @@
MathTrainer = 8
}
+ public enum Difficulty
+ {
+ None = 0,
+ Easy = 2,
+ Medium = 4,
+ Master = 8,
+ }
+
private bool draw_answer;
private gbrainy application;
private Cairo.Color default_color;
@@ -40,6 +48,7 @@
private TimeSpan game_time;
private bool won;
private bool tip_used;
+ private Difficulty difficulty;
public Game ()
{
@@ -50,6 +59,7 @@
default_background = new Color (1, 1, 1);
won = false;
tip_used = false;
+ difficulty = Difficulty.Medium;
}
public abstract string Question {
@@ -62,6 +72,23 @@
}
}
+ // Stores how difficult the game is
+ public virtual Difficulty GameDifficulty {
+ get {
+ return Difficulty.Master | Difficulty.Medium | Difficulty.Easy;
+ }
+ }
+
+ // The level of difficulty selected for the current game
+ public virtual Difficulty CurrentDifficulty {
+ set {
+ difficulty = value;
+ }
+ get {
+ return difficulty;
+ }
+ }
+
public abstract string Name {
get;
}
Modified: trunk/src/GameManager.cs
==============================================================================
--- trunk/src/GameManager.cs (original)
+++ trunk/src/GameManager.cs Wed Jan 30 21:45:58 2008
@@ -77,6 +77,7 @@
private ArrayListIndicesRandom list;
private IEnumerator enumerator;
private Type[] games;
+ private Game.Difficulty difficulty;
static GameManager ()
{
@@ -88,6 +89,7 @@
public GameManager ()
{
game_type = GameSession.Types.None;
+ difficulty = Game.Difficulty.Medium;
}
public GameSession.Types GameType {
@@ -101,6 +103,16 @@
}
}
+ public Game.Difficulty Difficulty {
+ set {
+ difficulty = value;
+ BuildGameList ();
+ }
+ get {
+ return difficulty;
+ }
+ }
+
public Type[] Games {
get { return games; }
set {
@@ -164,6 +176,7 @@
puzzle = (Game) Activator.CreateInstance (games [(int) enumerator.Current], true);
//puzzle = (Game) Activator.CreateInstance (MemoryTrainers [2], true);
puzzle.App = app;
+ puzzle.CurrentDifficulty = Difficulty;
puzzle.Initialize ();
return puzzle;
}
Modified: trunk/src/GameSession.cs
==============================================================================
--- trunk/src/GameSession.cs (original)
+++ trunk/src/GameSession.cs Wed Jan 30 21:45:58 2008
@@ -102,7 +102,8 @@
session.total_score = total_score;
session.games_played = games_played;
session.games_won = games_won;
- session.game_time = game_time;
+ session.game_time = game_time;
+ session.Difficulty = Difficulty;
return session;
}
@@ -110,6 +111,11 @@
get {return game_manager.GameType; }
set {game_manager.GameType = value; }
}
+
+ public Game.Difficulty Difficulty {
+ get {return game_manager.Difficulty; }
+ set {game_manager.Difficulty = value; }
+ }
public TimeSpan GameTime {
get {return game_time; }
Modified: trunk/src/MemoryColouredFigures.cs
==============================================================================
--- trunk/src/MemoryColouredFigures.cs (original)
+++ trunk/src/MemoryColouredFigures.cs Wed Jan 30 21:45:58 2008
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007-2008 Jordi Mas i HernÃndez <jmas softcatala org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -34,15 +34,16 @@
Length
}
- private const int columns = 6, rows = 6;
- private const int squares = columns * rows;
- private const double rect_w = 0.3 / rows;
- private const double rect_h = 0.3 / columns;
+ private int columns, rows;
+ private int squares;
+ private double rect_w;
+ private double rect_h;
private SquareColor []squares_colours;
private ArrayListIndicesRandom answers_order;
private const int answers = 4;
private ColorPalette palette;
private int color_sheme;
+ private const double block_space = 0.35;
public override string Name {
get {return Catalog.GetString ("Colored Figures");}
@@ -60,6 +61,21 @@
public override void Initialize ()
{
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ columns = rows = 5;
+ break;
+ case Difficulty.Medium:
+ columns = rows = 6;
+ break;
+ case Difficulty.Master:
+ columns = rows = 7;
+ break;
+ }
+
+ squares = columns * rows;
+ rect_w = 0.3 / rows;
+ rect_h = 0.3 / columns;
squares_colours = new SquareColor [squares * answers];
color_sheme = random.Next (2);
palette = new ColorPalette(ColorPalette.Id.PrimarySecundaryColors);
@@ -125,21 +141,20 @@
public override void DrawPossibleAnswers (Cairo.Context gr, int area_width, int area_height)
{
- double x = DrawAreaX + 0.05, y = DrawAreaY;
+ double x = DrawAreaX, y = DrawAreaY;
palette.Alpha = alpha;
- //gr.Color = palette.Cairo(DefaultDrawingColor);
for (int i = 0; i < answers_order.Count; i++) {
if (i == 2) {
- y += 0.4;
- x = DrawAreaX + 0.05;
+ y += 0.45;
+ x = DrawAreaX;
}
DrawSquare (gr, x, y, squares_colours, squares * (int) answers_order[i]);
- gr.MoveTo (x, y + 0.34);
+ gr.MoveTo (x, y + block_space + 0.02);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
gr.Stroke ();
- x += 0.35;
+ x += block_space + 0.08;
}
}
Modified: trunk/src/MemoryColouredText.cs
==============================================================================
--- trunk/src/MemoryColouredText.cs (original)
+++ trunk/src/MemoryColouredText.cs Wed Jan 30 21:45:58 2008
@@ -29,6 +29,7 @@
private ColorPalette palette;
private int question;
private string question_colorname;
+ private int colors_shown;
public override string Name {
get {return Catalog.GetString ("Colored text");}
@@ -45,12 +46,24 @@
public override void Initialize ()
{
- palette = new ColorPalette(ColorPalette.Id.PrimarySecundaryColors);
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ colors_shown = 3;
+ break;
+ case Difficulty.Medium:
+ colors_shown = 4;
+ break;
+ case Difficulty.Master:
+ colors_shown = 6;
+ break;
+ }
+
+ palette = new ColorPalette (colors_shown);
palette.Initialize ();
- question = random.Next ( palette.Count );
- right_answer = palette.Name( question );
- question_colorname = palette.Name( (ColorPalette.Id) question );
+ question = random.Next (palette.Count);
+ right_answer = palette.Name (question);
+ question_colorname = palette.Name ((ColorPalette.Id) question);
base.Initialize ();
}
@@ -84,4 +97,3 @@
}
}
-
Modified: trunk/src/MemoryCountDots.cs
==============================================================================
--- trunk/src/MemoryCountDots.cs (original)
+++ trunk/src/MemoryCountDots.cs Wed Jan 30 21:45:58 2008
@@ -27,9 +27,9 @@
public class MemoryCountDots : Memory
{
private const int NUMCOLUMNS = 7;
- private const int MINDOTS = 3;
- private const int MAXDOTSCOLOR = 7;
+ private const int MINDOTS = 1;
private const int MAXDOTS = 25;
+ private int maxdotscolor;
private ArrayListIndicesRandom location_order;
private ColorPalette palette;
@@ -45,12 +45,24 @@
}
public override string MemoryQuestion {
- get { return String.Format(Catalog.GetString ("How many {0} dots were in the previous image?"),
- palette.Name(0)) ; }
+ get { return String.Format(Catalog.GetString ("How many {0} dots were in the previous image? (answer using numbers)"),
+ palette.Name(0)); }
}
public override void Initialize ()
{
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ maxdotscolor = 2;
+ break;
+ case Difficulty.Medium:
+ maxdotscolor = 5;
+ break;
+ case Difficulty.Master:
+ maxdotscolor = 8;
+ break;
+ }
+
location_order = new ArrayListIndicesRandom (NUMCOLUMNS*NUMCOLUMNS);
location_order.Initialize();
@@ -61,7 +73,7 @@
// have to substract 1 to make dotsPerColor contents 0 based.
dotsPerColor = new int [palette.Count];
for (int i=0,before=-1; i< palette.Count; i++) {
- dotsPerColor[i] = before + MINDOTS + random.Next(MAXDOTSCOLOR-MINDOTS+1) ;
+ dotsPerColor[i] = before + MINDOTS + random.Next(maxdotscolor-MINDOTS+1);
before = dotsPerColor[i];
}
Modified: trunk/src/MemoryNumbers.cs
==============================================================================
--- trunk/src/MemoryNumbers.cs (original)
+++ trunk/src/MemoryNumbers.cs Wed Jan 30 21:45:58 2008
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007-2008 Jordi Mas i HernÃndez <jmas softcatala org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -26,12 +26,11 @@
public class MemoryNumbers : Memory
{
private int [] numbers;
- private const int rows = 3, columns = 3;
- private const double rect_w = 0.3 / rows;
- private const double rect_h = 0.3 / columns;
- private const int squares = rows * columns;
+ private int rows, columns, squares;
+ private double rect_w, rect_h;
private ArrayListIndicesRandom answers_order;
private const int answers = 4;
+ private const double block_space = 0.35;
public override string Name {
get {return Catalog.GetString ("Memorize numbers");}
@@ -47,6 +46,21 @@
public override void Initialize ()
{
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ columns = rows = 2;
+ break;
+ case Difficulty.Medium:
+ columns = rows = 3;
+ break;
+ case Difficulty.Master:
+ columns = rows = 4;
+ break;
+ }
+
+ rect_w = 0.3 / rows;
+ rect_h = 0.3 / columns;
+ squares = rows * columns;
numbers = new int [squares * 4];
for (int n = 0; n < rows; n++)
@@ -111,18 +125,18 @@
public override void DrawPossibleAnswers (Cairo.Context gr, int area_width, int area_height)
{
- double x = DrawAreaX + 0.05, y = DrawAreaY;
+ double x = DrawAreaX , y = DrawAreaY;
gr.Color = DefaultDrawingColor;
for (int i = 0; i < answers_order.Count; i++) {
if (i == 2) {
- y += 0.4;
- x = DrawAreaX + 0.05;
+ y += 0.45;
+ x = DrawAreaX;
}
DrawSquare (gr, x, y, numbers, squares * (int) answers_order[i]);
- gr.MoveTo (x, y + 0.34);
+ gr.MoveTo (x, y + block_space + 0.02);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
gr.Stroke ();
- x += 0.35;
+ x += block_space + 0.08;
}
}
@@ -137,8 +151,8 @@
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
- gr.MoveTo (x + 0.04 + column * rect_w, (rect_h / 2) + y + row * rect_h);
- gr.ShowText ((nums[index + column + (row * columns)]).ToString() );
+ DrawingHelpers.DrawTextCentered (gr, x + (rect_w / 2) + column * rect_w, y + (rect_h / 2) + row * rect_h,
+ (nums[index + column + (row * columns)]).ToString ());
}
}
gr.Stroke ();
Modified: trunk/src/MemoryWords.cs
==============================================================================
--- trunk/src/MemoryWords.cs (original)
+++ trunk/src/MemoryWords.cs Wed Jan 30 21:45:58 2008
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007-2008 Jordi Mas i HernÃndez <jmas softcatala org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -29,7 +29,7 @@
private ArrayListIndicesRandom words_order;
private ArrayList words;
private const int total_words = 35;
- private const int showed = 9;
+ private int showed;
private int answer;
public override string Name {
@@ -99,6 +99,18 @@
words.Add (Catalog.GetString ("bear"));
words.Add (Catalog.GetString ("wolf"));
+ switch (CurrentDifficulty) {
+ case Difficulty.Easy:
+ showed = 6;
+ break;
+ case Difficulty.Medium:
+ showed = 9;
+ break;
+ case Difficulty.Master:
+ showed = 12;
+ break;
+ }
+
words_order = new ArrayListIndicesRandom (total_words);
words_order.Initialize ();
answer = random.Next (showed);
@@ -109,7 +121,7 @@
public override void DrawPossibleAnswers (Cairo.Context gr, int area_width, int area_height)
{
- double x= DrawAreaX + 0.125, y = DrawAreaY + 0.2;
+ double x= DrawAreaX + 0.125, y = DrawAreaY + 0.1;
int cnt = 0;
for (int i = 0; i < showed; i++)
@@ -121,7 +133,7 @@
gr.ShowText ((string) words[(int)words_order[i]]);
gr.Stroke ();
- if (cnt == 2 || cnt == 5) {
+ if ((cnt + 1) % 3 == 0) {
y += 0.2;
x = DrawAreaX + 0.125;
} else {
@@ -139,14 +151,14 @@
private void DrawObject (Cairo.Context gr, int area_width, int area_height)
{
- double x= DrawAreaX + 0.125, y = DrawAreaY + 0.2;
+ double x= DrawAreaX + 0.125, y = DrawAreaY + 0.1;
for (int i = 0; i < showed; i++)
{
gr.MoveTo (x, y);
gr.ShowText ((string) words[(int)words_order[i]]);
gr.Stroke ();
- if (i == 2 || i == 5) {
+ if ((i + 1) % 3 == 0) {
y += 0.2;
x = DrawAreaX + 0.125;
} else {
Modified: trunk/src/PreferencesDialog.cs
==============================================================================
--- trunk/src/PreferencesDialog.cs (original)
+++ trunk/src/PreferencesDialog.cs Wed Jan 30 21:45:58 2008
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007-2008 Jordi Mas i HernÃndez <jmas softcatala org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -30,6 +30,9 @@
private const string dialog_name = "preferences";
[Glade.Widget] Gtk.SpinButton prefspinbutton;
[Glade.Widget] Gtk.CheckButton prefcheckbutton;
+ [Glade.Widget] Gtk.RadioButton rb_easy;
+ [Glade.Widget] Gtk.RadioButton rb_medium;
+ [Glade.Widget] Gtk.RadioButton rb_master;
public PreferencesDialog ()
{
@@ -48,6 +51,31 @@
set { prefcheckbutton.Active = value;}
}
+ public virtual Game.Difficulty Difficulty {
+ get {
+ if (rb_easy.Active)
+ return Game.Difficulty.Easy;
+
+ if (rb_master.Active)
+ return Game.Difficulty.Master;
+
+ return Game.Difficulty.Medium;
+ }
+ set {
+ switch (value) {
+ case Game.Difficulty.Easy:
+ rb_easy.Active = rb_easy.HasFocus = true;
+ break;
+ case Game.Difficulty.Medium:
+ rb_medium.Active = rb_medium.HasFocus = true;
+ break;
+ case Game.Difficulty.Master:
+ rb_master.Active = rb_master.HasFocus = true;
+ break;
+ }
+ }
+ }
+
public Gtk.Dialog Dialog {
get {
if (dialog == null)
Modified: trunk/src/PuzzleCirclesRectangle.cs
==============================================================================
--- trunk/src/PuzzleCirclesRectangle.cs (original)
+++ trunk/src/PuzzleCirclesRectangle.cs Wed Jan 30 21:45:58 2008
@@ -43,6 +43,12 @@
}
}
+ public override Difficulty GameDifficulty {
+ get {
+ return Difficulty.Master;
+ }
+ }
+
public override void Initialize ()
{
right_answer = "68";
Modified: trunk/src/gbrainy.cs
==============================================================================
--- trunk/src/gbrainy.cs (original)
+++ trunk/src/gbrainy.cs Wed Jan 30 21:45:58 2008
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Jordi Mas i HernÃndez <jmas softcatala org>
+ * Copyright (C) 2007-2008 Jordi Mas i HernÃndez <jmas softcatala org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -46,6 +46,7 @@
ToolButton pause_tbbutton;
int memquestion_time = 4;
bool memquestion_warn = true;
+ Game.Difficulty difficulty = Game.Difficulty.Medium;
public gbrainy (string [] args, params object [] props)
: base ("gbrainy", Defines.VERSION, Modules.UI, args, props)
@@ -118,14 +119,18 @@
//OnMemoryOnly (this, EventArgs.Empty); // temp
}
- public virtual int MemQuestionTime {
+ public int MemQuestionTime {
get { return memquestion_time;}
}
- public virtual bool MemQuestionWarn {
+ public bool MemQuestionWarn {
get { return memquestion_warn;}
}
+ public Game.Difficulty Difficulty {
+ get { return difficulty;}
+ }
+
public void UpdateStatusBar ()
{
statusbar.Push (0, session.StatusText);
@@ -338,9 +343,12 @@
dialog = new PreferencesDialog ();
dialog.MemQuestionTime = MemQuestionTime;
dialog.MemQuestionWarn = MemQuestionWarn;
+ dialog.Difficulty = Difficulty;
if (dialog.Run () == ok_buttonid) {
memquestion_warn = dialog.MemQuestionWarn;
memquestion_time = dialog.MemQuestionTime;
+ difficulty = dialog.Difficulty;
+ session.GameManager.Difficulty = difficulty;
}
dialog.Dialog.Destroy ();
}
Modified: trunk/src/gbrainy.glade
==============================================================================
--- trunk/src/gbrainy.glade (original)
+++ trunk/src/gbrainy.glade Wed Jan 30 21:45:58 2008
@@ -893,6 +893,104 @@
</child>
<child>
+ <widget class="GtkVBox" id="vbox11">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkLabel" id="label27">
+ <property name="height_request">25</property>
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Difficulty Level</b></property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">True</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkRadioButton" id="rb_easy">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Easy</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkRadioButton" id="rb_medium">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Medium</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">rb_easy</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkRadioButton" id="rb_master">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Master</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">rb_easy</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
<widget class="GtkVBox" id="vbox9">
<property name="visible">True</property>
<property name="homogeneous">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]