[gbrainy] Help, allgames pages plus some fixes and refactoring for the web client



commit 8e6fb1447eedc0b17fc534b0d390190601d23cfb
Author: Jordi Mas <jmas softcatala org>
Date:   Mon Jul 11 20:18:17 2011 +0200

    Help, allgames pages plus some fixes and refactoring for the web client

 src/Clients/WebForms/AllGames.aspx             |   40 ++++++
 src/Clients/WebForms/AllGames.aspx.cs          |  149 ++++++++++++++++++++
 src/Clients/WebForms/AllGames.aspx.designer.cs |   22 +++
 src/Clients/WebForms/Default.aspx              |    7 +-
 src/Clients/WebForms/Game.aspx                 |   32 ++---
 src/Clients/WebForms/Game.aspx.cs              |  173 +++++++++---------------
 src/Clients/WebForms/Game.aspx.designer.cs     |    2 +
 src/Clients/WebForms/GameImage.cs              |  145 ++++++++++++++++++++
 src/Clients/WebForms/GameImageAreaShape.cs     |   37 +++++
 src/Clients/WebForms/Global.asax.cs            |    4 +-
 src/Clients/WebForms/Help.aspx                 |   81 +++++++++++
 src/Clients/WebForms/Help.aspx.cs              |   11 ++
 src/Clients/WebForms/Help.aspx.designer.cs     |   15 ++
 src/Clients/WebForms/MasterPage.master         |   12 +-
 src/Clients/WebForms/WebForms.csproj           |   19 +++-
 src/Clients/WebForms/jscripts.js               |    8 +
 src/Clients/WebForms/package.sh                |    1 +
 src/Clients/WebForms/styles.css                |   17 ++-
 src/Core/Main/Game.cs                          |    2 +-
 19 files changed, 629 insertions(+), 148 deletions(-)
---
diff --git a/src/Clients/WebForms/AllGames.aspx b/src/Clients/WebForms/AllGames.aspx
new file mode 100644
index 0000000..7d91f9f
--- /dev/null
+++ b/src/Clients/WebForms/AllGames.aspx
@@ -0,0 +1,40 @@
+<%@ Page Language="C#" MasterPageFile = "MasterPage.master" Inherits="gbrainy.Clients.WebForms.AllGames" %>
+<%@ Import Namespace="System.Data" %>
+<%@ Import Namespace="gbrainy.Clients.WebForms" %>
+
+<asp:content id="main_content" ContentPlaceHolderID ="main_placeholder" runat="server">
+<p>This page shows all the gbrainy's games. To play a game use the <a href="Default.aspx">main page</a></p>
+<hr/>
+<asp:Repeater id="games_repeater" runat="server" EnableViewState = false>
+<asp:ItemTemplate>
+	     <p><%#  ((GameContainer) Container.DataItem).Question %> </p>
+	     <img src = "<%#  ((GameContainer) Container.DataItem).Image %>"/>
+	     <br/>
+	     
+	     <asp:Panel Visible = "<%#  ((GameContainer) Container.DataItem).TipVisible %>" runat="server">
+	     <a onclick="toggleVisibleById('<%#  ((GameContainer) Container.DataItem).ID%>_tip');return false;" href="">See Tip</a>
+	     <div id = "<%#  ((GameContainer) Container.DataItem).ID%>_tip" style = "display:none">
+	     	<br/>
+	     	<%#  ((GameContainer) Container.DataItem).Tip %>
+	     </div>
+	     </asp:Panel>
+	     
+	     <a onclick="toggleVisibleById('<%#  ((GameContainer) Container.DataItem).ID%>_solution');return false;" href="">See Solution</a>
+	     <div id = "<%#  ((GameContainer) Container.DataItem).ID%>_solution" style = "display:none">
+	     	<br/>
+	     	<%#  ((GameContainer) Container.DataItem).Solution %>
+	     </div>
+	     
+	     <hr/>
+</asp:ItemTemplate>
+</asp:Repeater>
+
+More games 
+<asp:Repeater id="nexts_repeater" runat="server" EnableViewState = false>
+<asp:ItemTemplate>
+		<a href ="?page=<%# Container.DataItem %>"><%# Container.DataItem %></a> &nbsp;
+</asp:ItemTemplate>
+</asp:Repeater>
+
+</asp:content>
+
diff --git a/src/Clients/WebForms/AllGames.aspx.cs b/src/Clients/WebForms/AllGames.aspx.cs
new file mode 100644
index 0000000..f1c9c28
--- /dev/null
+++ b/src/Clients/WebForms/AllGames.aspx.cs
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2011 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;
+using System.Web;
+using System.Web.UI;
+using System.IO;
+using System.Collections.Generic;
+
+using gbrainy.Core.Main;
+
+namespace gbrainy.Clients.WebForms
+{	
+	public struct GameContainer
+	{
+		public string Question;
+		public string Solution;
+		public string Image;
+		public string Tip;
+		public int ID;
+		
+		public bool TipVisible { 
+			get {
+				return String.IsNullOrEmpty (Tip) == false; 
+			}
+		}
+		
+		public GameContainer (string question, string solution, string image, string tip, int id)
+		{
+			Question = question;
+			Solution = solution;
+			Image = image;
+			Tip = tip;
+			ID = id;
+		}
+	};
+	
+	public partial class AllGames : System.Web.UI.Page
+	{
+		const string images_dir = "allgames_images";
+		const int elements_per_page = 10;
+		
+		static GameManager manager;
+		static bool created_games;
+		static List <GameContainer> game_container = new List<GameContainer> ();
+		static List <int> nexts = new List<int> ();
+		
+		List <GameContainer> games_container_page = new List<GameContainer> ();
+		int ShowPage {set; get; }
+		
+		void Page_Load (Object sender, EventArgs e)
+		{
+			SetPageToShow ();
+			CreateGames ();
+			CreatePageView ();
+			Bindings ();
+		}
+		
+		void CreatePageView ()
+		{
+			int start = ShowPage *  elements_per_page;
+			int end = start + Math.Min (game_container.Count, elements_per_page);
+			
+			for (int i = start; i < end; i++)
+				games_container_page.Add (game_container [i]);			
+		}
+		
+		void SetPageToShow ()
+		{
+			string page;
+			page = Request.QueryString ["page"];
+			
+			if (String.IsNullOrEmpty (page))
+				return;			
+			
+			int rslt;			
+			if (int.TryParse (page, out rslt) == true)			
+				ShowPage = rslt;			
+		}
+		
+		void Bindings ()
+		{
+			games_repeater.DataSource = games_container_page;
+			games_repeater.DataBind ();			
+			nexts_repeater.DataSource = nexts;
+			nexts_repeater.DataBind ();
+		}
+		
+		void CreateGames ()
+		{
+			if (created_games == true)
+				return;
+			
+			manager = Game.CreateManager ();
+			GameImage.CreateDirectory (images_dir);	
+			
+			GameManager.GameLocator [] games;
+			gbrainy.Core.Main.Game game;
+			
+			games = manager.AvailableGames;
+			
+			for (int i = 0; i < games.Length; i++)
+			{
+				if (games [i].IsGame == false)
+					continue;
+				
+				if (games [i].GameType == GameTypes.Memory)
+					continue;
+		
+				game = (gbrainy.Core.Main.Game) Activator.CreateInstance (games [i].TypeOf, true);
+				game.Variant = games [i].Variant;
+				game.Begin ();								
+				string file = CreateImage (game, i);
+				
+				game_container.Add (new  GameContainer (game.Question, game.AnswerText, file, game.TipString,
+				                                        game_container.Count));
+			}
+			
+			for (int i = 0; i < game_container.Count / elements_per_page; i++)
+				nexts.Add (i);
+			
+			created_games = true;
+		}
+		
+		static public string CreateImage (gbrainy.Core.Main.Game game, int i)
+		{
+			string file = images_dir + "/" + i.ToString () + ".png";
+			GameImage image = new GameImage (game);
+			image.CreateImage (file);
+			return file;
+		}
+	}
+}
diff --git a/src/Clients/WebForms/AllGames.aspx.designer.cs b/src/Clients/WebForms/AllGames.aspx.designer.cs
new file mode 100644
index 0000000..786bf7b
--- /dev/null
+++ b/src/Clients/WebForms/AllGames.aspx.designer.cs
@@ -0,0 +1,22 @@
+// ------------------------------------------------------------------------------
+//  <autogenerated>
+//      This code was generated by a tool.
+//      Mono Runtime Version: 2.0.50727.1433
+// 
+//      Changes to this file may cause incorrect behavior and will be lost if 
+//      the code is regenerated.
+//  </autogenerated>
+// ------------------------------------------------------------------------------
+
+namespace gbrainy.Clients.WebForms {
+	
+	
+	public partial class AllGames {
+		
+		protected System.Web.UI.WebControls.Content main_content;
+		
+		protected System.Web.UI.WebControls.Repeater games_repeater;
+		
+		protected System.Web.UI.WebControls.Repeater nexts_repeater;
+	}
+}
diff --git a/src/Clients/WebForms/Default.aspx b/src/Clients/WebForms/Default.aspx
index 7e3a43b..7b2ddf0 100644
--- a/src/Clients/WebForms/Default.aspx
+++ b/src/Clients/WebForms/Default.aspx
@@ -8,7 +8,7 @@
 
 	<br/>
 	<br/>
-		gbrainy is a brain teaser game and trainer to have fun and to keep your brain trained. gbrainy includes the following games:
+		gbrainy is a brain teaser game and trainer to have fun and to keep your brain trained. It is enjoyable for kids, adults or senior citizens. gbrainy includes the following games:
 	<br/>
 	<br/>
 
@@ -50,9 +50,4 @@
 	<asp:DropDownList id = "languages_drop" ViewStateMode="Enabled" runat="server">
 	</asp:DropDownList>
 	language
-	<p>
-		<small>
-		This web site is based on in the open source project called <a href="http://live.gnome.org/gbrainy";>gbrainy</a>. Contact e-mail address: jmas at softcatala dot org
-		</small>
-	</p>
 </asp:content>
diff --git a/src/Clients/WebForms/Game.aspx b/src/Clients/WebForms/Game.aspx
index b990709..12bb6a0 100644
--- a/src/Clients/WebForms/Game.aspx
+++ b/src/Clients/WebForms/Game.aspx
@@ -1,4 +1,5 @@
 <%@ Page Language="C#" MasterPageFile = "MasterPage.master" Inherits="gbrainy.Clients.WebForms.Game" %>
+<%@ Import Namespace="gbrainy.Clients.WebForms" %>
 
 <asp:content id="main_content" ContentPlaceHolderID ="main_placeholder" runat="server">
 
@@ -14,27 +15,9 @@
 			</div>
 		</td>
 	</tr>
-<!--	
-	<tr>
-		<td align = "center">
-			<asp:ImageButton ImageUrl = "images/logic-games-32.png" runat="server"></asp:ImageButton>
-		</td>
-	</tr>
 
 	<tr>
 		<td align = "center">
-			<asp:ImageButton ImageUrl = "images/math-games-32.png" runat="server"></asp:ImageButton>
-		</td>
-	</tr>
-
-	<tr>
-		<td align = "center">
-			<asp:ImageButton ImageUrl = "images/memory-games-32.png" runat="server"></asp:ImageButton>
-		</td>
-	</tr>
--->
-	<tr>
-		<td align = "center">
 			<asp:ImageButton ImageUrl = "images/endgame-32.png" id = "endgames_button" OnClick="OnClickEndGame" runat="server"></asp:ImageButton>
 			<div>
 				<asp:Label id="endgames_label" runat="server"/>
@@ -49,12 +32,21 @@
 	<table border="0px"  width = "500px" >	
 		<tr>
 			<td>
-				<asp:Label id="question" runat="server"></asp:Label>
+				<asp:Label id="question" runat="server"/>
 			</td>
 		</tr>
 		<tr>
 			<td>
-				 <asp:Image id="game_image" runat="server" />
+				<asp:Image id="game_image" runat="server" usemap="#mapname"/>
+				 
+				<map name="mapname">
+				<asp:Repeater id="areas_repeater" runat="server" EnableViewState = false>
+					<asp:ItemTemplate>					
+  					<area shape="rect" coords="<%#  ((GameImageAreaShape) Container.DataItem).Coords %>" 
+  					href="<%#  ((GameImageAreaShape) Container.DataItem).Url %>"/>
+					</asp:ItemTemplate>
+				</asp:Repeater>
+				</map>
 			</td>
 		</tr>
 		<tr>
diff --git a/src/Clients/WebForms/Game.aspx.cs b/src/Clients/WebForms/Game.aspx.cs
index 5775db5..9ca33c5 100644
--- a/src/Clients/WebForms/Game.aspx.cs
+++ b/src/Clients/WebForms/Game.aspx.cs
@@ -20,21 +20,22 @@
 using System;
 using System.IO;
 using System.Web.UI.HtmlControls;
+using System.Collections.Generic;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Services;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Clients.WebForms
 {
 	public partial class Game : System.Web.UI.Page
 	{
-		static GameManager manager;
-		const int image_width = 400;
-		const int image_height = 400;
+		static GameManager manager;	
 
 		gbrainy.Core.Main.Game _game;
 		gbrainy.Core.Main.GameSession session;
 		WebSession web_session;
+		GameImage image;
 
 		static public GameManager CreateManager ()
 		{
@@ -63,7 +64,7 @@ namespace gbrainy.Clients.WebForms
 		}
 
 		string GetLanguageFromSessionHandler ()
-		{
+		{			
 			return WebSession.LanguageCode;
 		}
 
@@ -88,6 +89,14 @@ namespace gbrainy.Clients.WebForms
 
 		private void Page_Load (Object sender, EventArgs e)
 		{
+			// If the Language has not been set the user has a expired
+			// session or does not come from the main page
+			if (String.IsNullOrEmpty (WebSession.LanguageCode))
+			{
+				Response.Redirect ("/");
+				return;
+			}			
+			
 			if (IsPostBack == false)
 				InitPage ();
 
@@ -96,6 +105,12 @@ namespace gbrainy.Clients.WebForms
 
 			HtmlForm form = (HtmlForm) Master.FindControl ("main_form");
 			form.DefaultButton = answer_button.UniqueID;
+			
+			string answer = Request.QueryString ["answer"];			
+			if (IsPostBack == false && string.IsNullOrEmpty (answer) == false)
+			{
+				ProcessAnswer (answer);
+			}
 
 			if (WebSession.GameState == null)
 			{
@@ -116,7 +131,8 @@ namespace gbrainy.Clients.WebForms
 			} else if (WebSession.GameState != null && WebSession.GameState.Status == GameSession.SessionStatus.Finished)
 			{
 				// Finished game
-				game_image.ImageUrl = Game.CreateImage (WebSession);
+				image = new GameImage (null);
+				game_image.ImageUrl = CreateImage (WebSession);
 				answer_button.Enabled = false;
 				answer_textbox.Text = string.Empty;
 				answer_textbox.Enabled = false;
@@ -126,8 +142,13 @@ namespace gbrainy.Clients.WebForms
 			}
 			else {
 				session = WebSession.GameState;
+				
+				if (_game == null)
+					_game = WebSession.GameState.CurrentGame;
+				
 				UpdateGame ();
-			}
+			}	
+			
 
 			if (IsPostBack == true) {
 				Logger.Debug ("Game.Page_Load. Ignoring postback");
@@ -142,55 +163,16 @@ namespace gbrainy.Clients.WebForms
 			TranslationsWeb service = (TranslationsWeb) ServiceLocator.Instance.GetService <ITranslations> ();
 			service.OnGetLanguageFromSession = GetLanguageFromSessionHandler;
 
-			game_image.Width = image_width;
-			game_image.Height = image_height;
+			game_image.Width = GameImage.IMAGE_WIDTH;
+			game_image.Height = GameImage.IMAGE_HEIGHT;
 
 			nextgame_link.Text = "Next Game";
 
 			// Toolbar
 			allgames_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("All");
-			endgames_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Finish");
-		}
-#if _IMAGEMAP_
-
-		string ProcessWidget (Widget widget)
-		{
-			string str;
+			endgames_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("End");
+		}		
 
-			str = String.Format ("<area shape=\"rect\" coords=\"{0},{1},{2},{3}\" href=http://en.wikipedia.org/ />",
-			                     widget.X, widget.Y, widget.Width, widget.Height);
-
-			return str;
-		}
-
-		public string ImageMap
-		{
-			get {
-				string str;
-
-				if (_game == null)
-					return "Nothing";
-
-				str = String.Format ("<img src={0}  usemap=\"#mapname\" />",
-					image.ImageUrl);
-
-				foreach (Widget widget in _game.Widgets)
-				{
-					if (widget is Container)
-					{
-						foreach (Widget child in _game.Widgets)
-						{
-							str += ProcessWidget (child);
-						}
-					}
-					else {
-						str += ProcessWidget (widget);
-					}
-				}
-				return str;
-			}
-		}
-#endif
 		void UpdateGame ()
 		{
 			if (_game == null)
@@ -198,7 +180,12 @@ namespace gbrainy.Clients.WebForms
 
 			status.Text = session.StatusText;
 			question.Text = _game.Question;
-		 	game_image.ImageUrl = CreateImage (WebSession);
+		 	
+			image = new GameImage (_game);
+			game_image.ImageUrl = CreateImage (WebSession);
+			
+			areas_repeater.DataSource = image.GetShapeAreas ();
+			areas_repeater.DataBind ();
 		}
 
 		public gbrainy.Core.Main.Game GetNextGame ()
@@ -212,50 +199,14 @@ namespace gbrainy.Clients.WebForms
 			}
 			return g;
 		}
-
-		//
-		static public string GetImageFileName (string sessionid)
-		{
-			string file;
-
-			file = "tmp/" + sessionid + ".png";
-			return file;
-		}
-
-		static public string CreateImage (WebSession _session)
+		
+		public string CreateImage (WebSession _session)
 		{
-			Cairo.ImageSurface cairo_image = null;
-			gbrainy.Core.Main.CairoContextEx cr = null;
-			string file = string.Empty;
-
-			try
-			{
-				cairo_image = new Cairo.ImageSurface (Cairo.Format.ARGB32, image_width, image_height);
-				cr = new gbrainy.Core.Main.CairoContextEx (cairo_image, "sans 12", 96);
-				file = GetImageFileName (_session.Session.SessionID);
-
-				// Draw Image
-				_session.GameState.Draw (cr, image_width, image_height, false);
-				cairo_image.WriteToPng (file);
-
-				if (File.Exists (file) == false)
-					Logger.Error ("Game.CreateImage. Error writting {0}", file);
-				else
-					Logger.Debug ("Game.CreateImage. Wrote image {0}", file);
-
-				// Prevent IE from caching the image
-				file += "?" + DateTime.Now.Ticks;
-			}
-
-			finally
-			{
-				if (cr != null)
-					((IDisposable) cr).Dispose ();
-
-				if (cairo_image != null)
-					((IDisposable) cairo_image).Dispose ();
-			}
-
+			string file = GameImage.GetImageFileName (_session.Session.SessionID);
+			image.CreateImage (_session.GameState, file);
+				
+			// Prevent IE from caching the image
+			file += "?" + DateTime.Now.Ticks;			
 		    	return file;
 		}
 
@@ -275,22 +226,26 @@ namespace gbrainy.Clients.WebForms
 		{
 			Logger.Debug ("Game.OnClickAnswer");
 
-			string answer = answer_textbox.Text;
-
-			if (String.IsNullOrEmpty (answer) == false)
-			{
-				if (web_session.GameState.ScoreGame (answer) == true) {
-					result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Congratulations.");
-					result_label.CssClass = "CorrectAnswer";
-				}
-				else {
-					result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Incorrect answer.");
-					result_label.CssClass = null;
-				}
-
-				rationale_label.Text = WebSession.GameState.CurrentGame.AnswerText;
-				answer_button.Enabled = false;
+			ProcessAnswer (answer_textbox.Text);		
+		}
+		
+		void ProcessAnswer (string answer)
+		{
+			if (String.IsNullOrEmpty (answer) == true)
+				return;
+		
+			if (web_session.GameState.ScoreGame (answer) == true) {
+				result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Congratulations.");
+				result_label.CssClass = "CorrectAnswer";
+			}
+			else {
+				result_label.Text = ServiceLocator.Instance.GetService <ITranslations> ().GetString ("Incorrect answer.");
+				result_label.CssClass = null;
 			}
+
+			rationale_label.Text = WebSession.GameState.CurrentGame.AnswerText;
+			answer_button.Enabled = false;
+			areas_repeater.Visible = false;
 		}
 
 		protected void OnClickEndGame (Object sender, EventArgs e)
@@ -302,8 +257,6 @@ namespace gbrainy.Clients.WebForms
 			
 			Global.TotalEndedSessions++;			
 			Global.TotalGames += session.History.GamesPlayed;
-			Global.TotalTimeSeconds += session.GameTime.Seconds;
-
 			Response.Redirect ("Game.aspx");
 		}
 
diff --git a/src/Clients/WebForms/Game.aspx.designer.cs b/src/Clients/WebForms/Game.aspx.designer.cs
index 9122695..8165412 100644
--- a/src/Clients/WebForms/Game.aspx.designer.cs
+++ b/src/Clients/WebForms/Game.aspx.designer.cs
@@ -25,6 +25,8 @@ namespace gbrainy.Clients.WebForms {
 		
 		protected System.Web.UI.WebControls.Image game_image;
 		
+		protected System.Web.UI.WebControls.Repeater areas_repeater;
+		
 		protected System.Web.UI.WebControls.TextBox answer_textbox;
 		
 		protected System.Web.UI.WebControls.Button answer_button;
diff --git a/src/Clients/WebForms/GameImage.cs b/src/Clients/WebForms/GameImage.cs
new file mode 100644
index 0000000..5aba54c
--- /dev/null
+++ b/src/Clients/WebForms/GameImage.cs
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2011 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;
+using System.Collections.Generic;
+using System.IO;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Toolkit;
+
+namespace gbrainy.Clients.WebForms
+{
+	public class GameImage
+	{
+		public const int IMAGE_WIDTH = 400;
+		public const int IMAGE_HEIGHT = 400;
+		static public string IMAGES_DIR = "tmp/";
+		
+		gbrainy.Core.Main.Game game;	
+		
+		public GameImage (gbrainy.Core.Main.Game game)
+		{
+			this.game = game;
+		}
+		
+		public bool CreateImage (string file)
+		{
+			return CreateImage (game, file);
+		}
+
+		// TODO: We need a parameter here because not all the views are games
+		// we need to extend the concept of view to include Widgets
+		public bool CreateImage (IDrawable drawable, string file)
+		{
+			Cairo.ImageSurface cairo_image = null;
+			gbrainy.Core.Main.CairoContextEx cr = null;			
+
+			try
+			{
+				cairo_image = new Cairo.ImageSurface (Cairo.Format.ARGB32, IMAGE_WIDTH, IMAGE_HEIGHT);
+				cr = new gbrainy.Core.Main.CairoContextEx (cairo_image, "sans 12", 96);
+
+				// Draw Image
+				drawable.Draw (cr, IMAGE_WIDTH, IMAGE_WIDTH, false);
+				cairo_image.WriteToPng (file);
+
+				if (File.Exists (file) == false)
+					Logger.Error ("Game.CreateImage. Error writting {0}", file);
+				else
+					Logger.Debug ("Game.CreateImage. Wrote image {0}", file);
+			}
+			
+			catch (Exception)
+			{
+				Logger.Error ("Game.CreateImage. Error writting {0}", file);
+				return false;
+			}
+
+			finally
+			{
+				if (cr != null)
+					((IDisposable) cr).Dispose ();
+
+				if (cairo_image != null)
+					((IDisposable) cairo_image).Dispose ();
+			}
+
+		    	return true;
+		}
+
+		static public string GetImageFileName (string sessionid)
+		{
+			string file;
+
+			file = IMAGES_DIR + sessionid + ".png";
+			return file;
+		}		
+	
+		static string ProcessWidget (Widget widget)
+		{
+			return String.Format ("{0},{1},{2},{3}",
+			                      widget.X * IMAGE_WIDTH,
+			                      widget.Y * IMAGE_HEIGHT, 
+			                      (widget.X + widget.Width) * IMAGE_WIDTH,
+			                      (widget.Y + widget.Height) * IMAGE_HEIGHT);
+		}		
+			
+		public IList <GameImageAreaShape> GetShapeAreas ()
+		{
+			List <GameImageAreaShape> area_shapes = new List <GameImageAreaShape> ();
+	
+			if (game == null)
+				return area_shapes;
+	
+			foreach (Widget widget in game.Widgets)
+			{
+				Container container = widget as Container;
+				
+				if (container != null)
+				{					
+					foreach (Widget child in container.Children)
+					{
+						area_shapes.Add (new GameImageAreaShape (ProcessWidget (child),
+							"?answer=" + child.DataEx.ToString (),
+							area_shapes.Count));
+					}
+				}
+				else {
+					/*area_shapes.Add (new AreaShape (ProcessWidget (widget),
+							"?answer=" + child.DataEx.ToString ()));*/
+				}
+			}
+			
+			return area_shapes;
+		}
+			
+		static public void CreateDirectory (string images_dir)
+		{
+			try
+			{
+				Directory.CreateDirectory (images_dir);
+			}
+			catch (Exception e)
+			{
+				Logger.Error ("GameImage.CreateDirectory. Error creating {0} - {1}", images_dir, e.Message);
+			}			
+		}
+	}
+}
diff --git a/src/Clients/WebForms/GameImageAreaShape.cs b/src/Clients/WebForms/GameImageAreaShape.cs
new file mode 100644
index 0000000..cee7b2a
--- /dev/null
+++ b/src/Clients/WebForms/GameImageAreaShape.cs
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 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.Clients.WebForms
+{
+	public struct GameImageAreaShape
+	{
+		public string Url {set; get; }
+		public string Coords {set; get; }
+		public int ID {set; get; }
+		
+		public GameImageAreaShape (string coords, string url, int id)
+		{
+			Coords = coords;
+			Url = url;
+			ID = id;
+		}
+	};
+}
diff --git a/src/Clients/WebForms/Global.asax.cs b/src/Clients/WebForms/Global.asax.cs
index 8a2384c..b63e8c3 100644
--- a/src/Clients/WebForms/Global.asax.cs
+++ b/src/Clients/WebForms/Global.asax.cs
@@ -107,12 +107,12 @@ namespace gbrainy.Clients.WebForms
 
 				try
 				{
-					File.Delete (Game.GetImageFileName (Session.SessionID));
+					File.Delete (GameImage.GetImageFileName (Session.SessionID));
 				}
 				catch (Exception ex)
 				{
 					Logger.Error ("Global.Session_End. Could not delete {0}, exception: {1}",
-							Game.GetImageFileName (Session.SessionID), ex);
+							GameImage.GetImageFileName (Session.SessionID), ex);
 				}
 			}
 			else
diff --git a/src/Clients/WebForms/Help.aspx b/src/Clients/WebForms/Help.aspx
new file mode 100644
index 0000000..ca88280
--- /dev/null
+++ b/src/Clients/WebForms/Help.aspx
@@ -0,0 +1,81 @@
+<%@ Page Language="C#" Inherits="gbrainy.Clients.WebForms.Download" MasterPageFile="~/MasterPage.master" %>
+<%@ MasterType VirtualPath="~/MasterPage.master" %>
+<asp:Content ContentPlaceHolderID="main_placeholder" ID="main_placeholderContent" runat="server">
+	
+	<h1>Introduction</h1>
+	<p>
+		<app>gbrainy</app> is a brain teaser game; the aim of the game is to have fun and keep 
+		your brain trained. 
+	</p>
+	<p>
+		It features different game types like logic puzzles, mental calculation games, 
+		memory trainers and verbal analogies, designed to test different cognitive skills.
+	</p>
+	<p>
+		<app>gbrainy</app> is enjoyable for kids, adults or senior citizens
+	</p>
+	<p>
+		<app>gbrainy</app> relies heavily on the work of previous puzzle masters, 
+		ranging from classic puzzles from ancient times to more recent works like 
+		<link href="http://en.wikipedia.org/wiki/Terry_Stickels";>Terry Stickels'</link> 
+		puzzles or the classic <link href="http://en.wikipedia.org/wiki/Dr._Brain";>Dr. Brain</link> 
+		game.
+	</p>
+	<p>
+		There have been recent discussions in the scientific community regarding whether 
+		brain training software improves cognitive performance. Most of the 
+		studies show that there is little or no improvement, but that doesn't mean 
+		you can't have a good time playing games like <app>gbrainy</app>!
+	</p>
+	<h1>Game types</h1>
+	<!-- Logic -->
+	<span class="WelcomeLeft">
+	 	<img src = "images/logic-games-32.png"/>
+	</span>
+
+	<span class="WelcomeRight">
+		Games designed to challenge your reasoning and thinking skills. These 
+            	games are based on sequences of elements, visual and spatial reasoning 
+           	or relationships between elements.
+	</span>
+	<br/>
+	<br/>
+
+	<!-- Calculation -->
+	<span class="WelcomeLeft">
+	 	<img src = "images/math-games-32.png"/>
+	</span>
+
+	<span class="WelcomeRight">
+		Games based on arithmetical operations designed to improve your mental
+            	calculation skills. Games that require the player to use multiplication,
+            	division, addition and subtraction combined in different ways.
+	</span>
+	<br/>
+	<br/>
+
+	<!-- Verbal -->
+	<span class="WelcomeLeft">
+	 	<img src = "images/verbal-games-32.png"/>
+	</span>
+
+	<span class="WelcomeRight">
+		Games that challenge your verbal aptitude. These games ask the player to identify cause and effect, use synonyms or antonyms, and use their vocabulary.
+	</span>	
+	
+	<h1>Tips</h1>
+	Some tips that may be useful when playing gbrainy:
+	<ul><li>Read the instructions carefully and identify the data and given clues.</li></ul>
+	<ul><li>To score the player gbrainy uses the time and tips needed to complete each game.</li></ul>
+	<ul><li>In logic games, elements that may seem irrelevant can be very important.</li></ul>
+	<ul><li>Try to approach a problem from different angles.</li></ul>
+	<ul><li>Do not be afraid of making mistakes, they are part of the learning process.</li></ul>
+	<ul><li>Do all the problems, even the difficult ones. Improvement comes from challeging yourself.</li></ul>
+	<ul><li>Play on a daily basis, you will notice progress soon.</li></ul>
+	<ul><li>Association of elements is a common technique for remembering things.</li></ul>
+	<ul><li>Grouping elements into categories is a common technique for remembering things.</li></ul>
+	<ul><li>Build acronyms using the first letter of each fact to be remembered.</li></ul>
+	<ul><li>The enjoyment obtained from a puzzle is proportional to the time spent on it.</li></ul>
+	<ul><li>Think of breaking down every problem into simpler components.</li></ul>
+	<ul><li>When answering verbal analogies pay attention to the verb tense.</li></ul>
+</asp:Content>
\ No newline at end of file
diff --git a/src/Clients/WebForms/Help.aspx.cs b/src/Clients/WebForms/Help.aspx.cs
new file mode 100644
index 0000000..fbc16ad
--- /dev/null
+++ b/src/Clients/WebForms/Help.aspx.cs
@@ -0,0 +1,11 @@
+
+using System;
+using System.Web;
+using System.Web.UI;
+
+namespace WebForms
+{	public partial class Help : System.Web.UI.Page
+	{
+	}
+}
+
diff --git a/src/Clients/WebForms/Help.aspx.designer.cs b/src/Clients/WebForms/Help.aspx.designer.cs
new file mode 100644
index 0000000..59b54f7
--- /dev/null
+++ b/src/Clients/WebForms/Help.aspx.designer.cs
@@ -0,0 +1,15 @@
+// ------------------------------------------------------------------------------
+//  <autogenerated>
+//      This code was generated by a tool.
+//      Mono Runtime Version: 2.0.50727.1433
+// 
+//      Changes to this file may cause incorrect behavior and will be lost if 
+//      the code is regenerated.
+//  </autogenerated>
+// ------------------------------------------------------------------------------
+
+namespace gbrainy.Clients.WebForms {
+
+	public partial class Download {
+	}
+}
diff --git a/src/Clients/WebForms/MasterPage.master b/src/Clients/WebForms/MasterPage.master
index 6524b74..dd2d540 100644
--- a/src/Clients/WebForms/MasterPage.master
+++ b/src/Clients/WebForms/MasterPage.master
@@ -2,10 +2,10 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
 <html>
 <head>
-	<title>Welcome to gbrainy.com main page</title>
+	<title>Welcome to gbrainy.com - A brain teaser game for fun and to keep your brain trained</title>
 	<link href="styles.css" rel="stylesheet" type="text/css"/>
 	<link rel="shortcut icon" href="images/gbrainy.ico" />
-	
+	<script type="text/javascript" src="jscripts.js"></script>
 	<asp:ContentPlaceHolder Id="analytics" runat="server" Visible = "false">
 		<script type="text/javascript">
 	
@@ -21,7 +21,7 @@
 		     var s = document.getElementsByTagName('script')[0]; 
 		s.parentNode.insertBefore(ga, s);
 		   })();
-		</script>
+		</script>		
 	</asp:ContentPlaceHolder>
 	
 </head>
@@ -30,7 +30,8 @@
 <div class="Header">
 			<asp:HyperLink class="HeaderText" text ="Home" NavigateUrl ="Default.aspx" runat="server"/>
 			<asp:HyperLink class="HeaderText" text ="Download" NavigateUrl ="Download.aspx" runat="server"/>
-			<span class="HeaderText">Help</span>
+			<asp:HyperLink class="HeaderText" text ="Games" NavigateUrl ="AllGames.aspx" runat="server"/>
+			<asp:HyperLink class="HeaderText" text ="Help" NavigateUrl ="Help.aspx" runat="server"/>
 			<span class="HeaderText">About</span>
 			<span class="HeaderText">
 			</span>
@@ -39,6 +40,9 @@
 <div class="MainContent">
     <asp:contentplaceholder id="main_placeholder" runat="server" />
 </div>
+<p class="Footer">
+	This web site is based on in the open source project called <a href="http://live.gnome.org/gbrainy";>gbrainy</a>. Contact e-mail address: jmas at softcatala dot org
+</p>
 </form>
 </body>
 </html>
diff --git a/src/Clients/WebForms/WebForms.csproj b/src/Clients/WebForms/WebForms.csproj
index d09bcca..c2d30d3 100644
--- a/src/Clients/WebForms/WebForms.csproj
+++ b/src/Clients/WebForms/WebForms.csproj
@@ -32,7 +32,7 @@
     <Reference Include="System.Web" />
     <Reference Include="System.Web.Extensions" />
     <Reference Include="Mono.Posix" />
-    <Reference Include="Mono.Cairo, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+    <Reference Include="Mono.Cairo" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="web.config" />
@@ -46,6 +46,9 @@
     <Content Include="..\..\..\data\verbal_analogies.xml">
       <Link>data\verbal_analogies.xml</Link>
     </Content>
+    <Content Include="Help.aspx" />
+    <Content Include="AllGames.aspx" />
+    <Content Include="jscripts.js" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Download.aspx.cs">
@@ -86,6 +89,20 @@
     <Compile Include="WebSession.cs" />
     <Compile Include="TranslationsWeb.cs" />
     <Compile Include="Defines.cs" />
+    <Compile Include="Help.aspx.cs">
+      <DependentUpon>Help.aspx</DependentUpon>
+    </Compile>
+    <Compile Include="Help.aspx.designer.cs">
+      <DependentUpon>Help.aspx</DependentUpon>
+    </Compile>
+    <Compile Include="AllGames.aspx.cs">
+      <DependentUpon>AllGames.aspx</DependentUpon>
+    </Compile>
+    <Compile Include="AllGames.aspx.designer.cs">
+      <DependentUpon>AllGames.aspx</DependentUpon>
+    </Compile>
+    <Compile Include="GameImage.cs" />
+    <Compile Include="GameImageAreaShape.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" />
diff --git a/src/Clients/WebForms/jscripts.js b/src/Clients/WebForms/jscripts.js
new file mode 100644
index 0000000..9e7545a
--- /dev/null
+++ b/src/Clients/WebForms/jscripts.js
@@ -0,0 +1,8 @@
+toggleVisibleById = function (elementId) {
+    toggleVisible(document.getElementById(elementId));
+};
+
+toggleVisible = function (element) {
+    element.style.display == 'none' ? 'block' : 'none';
+};
+
diff --git a/src/Clients/WebForms/package.sh b/src/Clients/WebForms/package.sh
index a92047a..00f6f0c 100755
--- a/src/Clients/WebForms/package.sh
+++ b/src/Clients/WebForms/package.sh
@@ -16,6 +16,7 @@ mkdir themes
 cp ../*.aspx .
 cp ../*.master .
 cp ../*.css .
+cp ../*.js .
 cp ../*.asax .
 cp ../web.config .
 
diff --git a/src/Clients/WebForms/styles.css b/src/Clients/WebForms/styles.css
index c4b8082..2bb34a2 100644
--- a/src/Clients/WebForms/styles.css
+++ b/src/Clients/WebForms/styles.css
@@ -1,7 +1,7 @@
 .Header
 {
 	width: 80%;
-	background-color: rgb(90%, 90%, 90%);
+	background-color: rgb(93%, 93%, 93%);
 	font-size: 24px;
 	margin-bottom: 30px;
 	margin-left: 30px;
@@ -9,10 +9,18 @@
 
 body
 {
-	font: Arial,Helvetica,sans-serif;
+	font-family: Arial,Helvetica,sans-serif;
 	font-size: 14px;
 }
 
+.Footer
+{
+	font-family: Arial,Helvetica,sans-serif;
+	font-size: 12px;
+	margin-left: 30px;
+	font-style:italic;
+}
+
 
 .CorrectAnswer
 {
@@ -22,17 +30,18 @@ body
 
 .HeaderText
 {
+	color: #3366CC;	
 	margin-right: 20px;
 }
 
 .WelcomeLeft
 {
-	width = 30%;
+	width: 30%;
 }
 
 .WelcomeRight
 {
-	width = 70%;
+	width: 70%;
 }
 
 .MainContent
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index bd1a3bb..3b84f69 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -206,7 +206,7 @@ namespace gbrainy.Core.Main
 			get { return Main.Score.GameExpectedTime (Type, CurrentDifficulty); }
 		}
 
-		protected Widget [] Widgets {
+		public Widget [] Widgets {
 			get { return containers.ToArray (); }
 		}
 



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