[gbrainy] Update memory question



commit 97da58f5b06a4c5fb2079cce16f9468a091875a7
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Nov 21 18:12:40 2009 +0100

    Update memory question

 src/Clients/Classical/gbrainy.cs             |   10 ++++++-
 src/Core/Main/Game.cs                        |   10 +++++++
 src/Core/Main/GameSession.cs                 |    9 ++++++
 src/Core/Main/Memory.cs                      |   13 +++------
 src/Core/Main/UpdateGameQuestionEventArgs.cs |   37 ++++++++++++++++++++++++++
 src/Core/Makefile.am                         |    1 +
 src/Core/Views/CountDownView.cs              |    7 +---
 7 files changed, 72 insertions(+), 15 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 3bd79e4..b185d1b 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -67,7 +67,7 @@ namespace gbrainy.Clients.Classical
 		SimpleLabel question_label;
 		SimpleLabel solution_label;
 		bool margins = false;
-	
+
 		public static PlayerHistory history = null;
 
 		public GtkClient (string [] args, params object [] props)
@@ -84,6 +84,7 @@ namespace gbrainy.Clients.Classical
 			BuildToolBar ();
 			session = new GameSession ();
 			session.DrawRequest += SessionDrawRequest;
+			session.UpdateGameQuestion += SessionUpdateGameQuestion;
 			session.SynchronizingObject = new GtkSynchronize ();
 
 			if (history == null)
@@ -130,6 +131,13 @@ namespace gbrainy.Clients.Classical
 			ActiveInputControls (false);
 		}
 
+		// Gamesession has requested a question refresh
+		public void SessionUpdateGameQuestion (object o, UpdateGameQuestionEventArgs args)
+		{
+			UpdateQuestion (args.Question);
+			ActiveInputControls (true);
+		}
+
 		// Gamesession has requested a redraw of the drawingarea
 		public void SessionDrawRequest (object o, EventArgs args)
 		{
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index 552d5c2..bd9a4fa 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -57,6 +57,7 @@ namespace gbrainy.Core.Main
 		private ISynchronizeInvoke synchronize;
 
 		public event EventHandler DrawRequest;
+		public event EventHandler <UpdateGameQuestionEventArgs> UpdateGameQuestion;
 
 		protected Game ()
 		{
@@ -77,6 +78,15 @@ namespace gbrainy.Core.Main
 			DrawRequest (this, EventArgs.Empty);
 		}
 
+		// Used by games to request a question repaint
+		protected void UpdateQuestion (string question)
+		{
+			if (UpdateGameQuestion == null)
+				return;
+
+			UpdateGameQuestion (this, new UpdateGameQuestionEventArgs (question));
+		}
+
 		public abstract string Question {
 			get;
 		}
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 95fc618..3b5591d 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -78,6 +78,7 @@ namespace gbrainy.Core.Main
 		private ISynchronizeInvoke synchronize;
 
 		public event EventHandler DrawRequest;
+		public event EventHandler <UpdateGameQuestionEventArgs> UpdateGameQuestion;
 	
 		public GameSession ()
 		{
@@ -264,6 +265,8 @@ namespace gbrainy.Core.Main
 			CurrentGame = game_manager.GetPuzzle ();
 			CurrentGame.SynchronizingObject = SynchronizingObject;
 			CurrentGame.DrawRequest += GameDrawRequest;
+			CurrentGame.UpdateGameQuestion += GameUpdateGameQuestion;
+
 			CurrentGame.Initialize ();
 
 			CurrentGame.GameTime = TimeSpan.Zero;
@@ -341,6 +344,12 @@ namespace gbrainy.Core.Main
 			return fmt;
 		}
 
+		public void GameUpdateGameQuestion (object o, UpdateGameQuestionEventArgs args)
+		{
+			if (UpdateGameQuestion != null)
+				UpdateGameQuestion (this, args);
+		}
+
 		// A game has requested a redraw, scale the request to the object
 		// subscribed to GameSession.GameDrawRequest
 		public void GameDrawRequest (object o, EventArgs args)
diff --git a/src/Core/Main/Memory.cs b/src/Core/Main/Memory.cs
index 8efae47..6aafcf0 100644
--- a/src/Core/Main/Memory.cs
+++ b/src/Core/Main/Memory.cs
@@ -41,8 +41,6 @@ namespace gbrainy.Core.Main
 		private bool draw_timer;
 		CountDownView downview;
 
-		//public event EventHandler RequestRedraw;
-
 		public override bool ButtonsActive {
 			get { return buttons_active;}
 		}
@@ -77,7 +75,9 @@ namespace gbrainy.Core.Main
 			}
 
 			downview = new CountDownView (OnCountDownFinish);
+			downview.SynchronizingObject = SynchronizingObject;
 			downview.DrawRequest += OnCountDownRedraw;
+			downview.Start ();
 		}
 
 		public void OnCountDownRedraw (object o, EventArgs args)
@@ -141,12 +141,7 @@ namespace gbrainy.Core.Main
 					request_answer = true;
 					buttons_active = true;
 				}
-				/*if (App != null) {
-					Application.Invoke (delegate {
-						//App.UpdateQuestion (MemoryQuestion);
-						//App.ActiveInputControls (buttons_active);
-					});
-				}*/
+				UpdateQuestion (MemoryQuestion);
 			} else {
 				lock (this) {
 					time_left--;
@@ -165,7 +160,7 @@ namespace gbrainy.Core.Main
 		}		
 
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
-		{
+		{			
 			if (downview != null) {
 				downview.Draw (gr, area_width, area_height, rtl);
 				return;
diff --git a/src/Core/Main/UpdateGameQuestionEventArgs.cs b/src/Core/Main/UpdateGameQuestionEventArgs.cs
new file mode 100644
index 0000000..f43e0bf
--- /dev/null
+++ b/src/Core/Main/UpdateGameQuestionEventArgs.cs
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+
+namespace gbrainy.Core.Main
+{
+	public class UpdateGameQuestionEventArgs : EventArgs
+	{
+		string question;
+
+		public UpdateGameQuestionEventArgs (string question)
+		{			
+			this.question = question;
+		}
+
+		public string Question {
+			get { return question; }
+		}
+	}
+}
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 4f95992..778fa22 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -14,6 +14,7 @@ CSFILES =  \
 		Main/Memory.cs			\
 		Main/PlayerHistory.cs		\
 		Main/Preferences.cs		\
+		Main/UpdateGameQuestionEventArgs.cs \
 		Main/Verbal/Analogies.cs 	\
 		Main/Verbal/AnalogiesFactory.cs	\
 		Main/Verbal/AnalogiesMultipleOptions.cs	\
diff --git a/src/Core/Views/CountDownView.cs b/src/Core/Views/CountDownView.cs
index d49d44e..0d848c5 100644
--- a/src/Core/Views/CountDownView.cs
+++ b/src/Core/Views/CountDownView.cs
@@ -41,21 +41,18 @@ namespace gbrainy.Core.Views
 		{
 			timer = new System.Timers.Timer ();
 			timer.Elapsed += TimerUpdater;
-			timer.SynchronizingObject = SynchronizingObject;
 			timer.Interval = (1 * 1000); // 1 second
 			finish = OnFinish;
-			Start ();
 		}
 
 		public ISynchronizeInvoke SynchronizingObject { 
-			set { 
-				synchronize = value;
-			}
+			set { synchronize = value; }
 			get { return synchronize; }
 		}
 
 		public void Start ()
 		{
+			timer.SynchronizingObject = SynchronizingObject;
 			countdown_time = 3;
 			timer.Enabled = true;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]