[gbrainy] Support for personal records
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Support for personal records
- Date: Sun, 29 Nov 2009 14:49:43 +0000 (UTC)
commit 404fc0bf756963128667f00ffb9f8cbb0ef76b97
Author: Jordi Mas <jmas softcatala org>
Date: Sun Nov 29 15:46:14 2009 +0100
Support for personal records
src/Clients/Classical/gbrainy.cs | 6 +-
src/Core/Main/PlayerHistory.cs | 70 +++++++++++++++++++++++++++++++--
src/Core/Views/FinishView.cs | 79 +++++++++++++++++++++++++++++++------
3 files changed, 135 insertions(+), 20 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index f781b33..013856e 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -79,7 +79,7 @@ namespace gbrainy.Clients.Classical
session.UpdateUIElement += SessionUpdateUIElement;
session.SynchronizingObject = new GtkSynchronize ();
- session.GameManager.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
+ session.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
drawing_area = new DrawingArea ();
drawing_area.ExposeEvent += OnDrawingAreaExposeEvent;
GameSensitiveUI ();
@@ -418,7 +418,7 @@ namespace gbrainy.Clients.Classical
dialog = new PreferencesDialog (session.PlayerHistory);
if (dialog.Run () == ResponseType.Ok) {
- session.GameManager.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
+ session.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
}
dialog.Dialog.Destroy ();
}
@@ -428,7 +428,7 @@ namespace gbrainy.Clients.Classical
ResponseType rslt;
CustomGameDialog dialog;
- dialog = new CustomGameDialog (session.GameManager);
+ dialog = new CustomGameDialog (session.GameManager);
rslt = dialog.Run ();
dialog.Dialog.Destroy ();
diff --git a/src/Core/Main/PlayerHistory.cs b/src/Core/Main/PlayerHistory.cs
index 7da06ae..903be5c 100644
--- a/src/Core/Main/PlayerHistory.cs
+++ b/src/Core/Main/PlayerHistory.cs
@@ -27,8 +27,9 @@ namespace gbrainy.Core.Main
{
public class PlayerHistory
{
- private string file, config_path;
- private List <GameHistory> games;
+ string file, config_path;
+ List <GameHistory> games;
+ int last_game;
[Serializable]
public class GameHistory
@@ -42,11 +43,26 @@ namespace gbrainy.Core.Main
public int verbal_score;
}
+ public class PersonalRecord
+ {
+ public Game.Types GameType { get; set; }
+ public int PreviousScore { get; set; }
+ public int NewScore { get; set; }
+
+ public PersonalRecord (Game.Types type, int previous_score, int new_score)
+ {
+ GameType = type;
+ PreviousScore = previous_score;
+ NewScore = new_score;
+ }
+ }
+
public PlayerHistory ()
{
config_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
config_path = Path.Combine (config_path, Defines.CONFIG_DIR);
file = Path.Combine (config_path, "PlayerHistory.xml");
+ last_game = -1;
}
public List <GameHistory> Games {
@@ -69,8 +85,10 @@ namespace gbrainy.Core.Main
public void SaveGameSession (GameSession session)
{
- if (session.GamesPlayed < Preferences.GetIntValue (Preferences.MinPlayedGamesKey))
+ if (session.GamesPlayed < Preferences.GetIntValue (Preferences.MinPlayedGamesKey)) {
+ last_game = -1;
return;
+ }
GameHistory history = new GameHistory ();
@@ -86,13 +104,57 @@ namespace gbrainy.Core.Main
Games.RemoveAt (0);
Games.Add (history);
+ last_game = Games.Count - 1;
Save ();
}
+ // Check if the last recorded game has been a personal record
+ public List <PersonalRecord> GetLastGameRecords ()
+ {
+ List <PersonalRecord> records = new List <PersonalRecord> ();
+ GameHistory higher;
+
+ // We can start to talk about personal records after 5 plays
+ if (last_game == -1 || Games.Count < 5)
+ return records;
+
+ higher = new GameHistory ();
+
+ // Find the higher record for every type of game
+ for (int i = 0; i < last_game; i++)
+ {
+ if (Games[i].logic_score > higher.logic_score)
+ higher.logic_score = Games[i].logic_score;
+
+ if (Games[i].math_score > higher.math_score)
+ higher.math_score = Games[i].math_score;
+
+ if (Games[i].memory_score > higher.memory_score)
+ higher.memory_score = Games[i].memory_score;
+
+ if (Games[i].verbal_score > higher.verbal_score)
+ higher.verbal_score = Games[i].verbal_score;
+ }
+
+ // It is a record?
+ if (Games[last_game].logic_score > higher.logic_score)
+ records.Add (new PersonalRecord (Game.Types.LogicPuzzle, higher.logic_score, Games[last_game].logic_score));
+
+ if (Games[last_game].math_score > higher.math_score)
+ records.Add (new PersonalRecord (Game.Types.MathTrainer, higher.math_score, Games[last_game].math_score));
+
+ if (Games[last_game].memory_score > higher.memory_score)
+ records.Add (new PersonalRecord (Game.Types.MemoryTrainer, higher.memory_score, Games[last_game].memory_score));
+
+ if (Games[last_game].verbal_score > higher.verbal_score)
+ records.Add (new PersonalRecord (Game.Types.VerbalAnalogy, higher.verbal_score, Games[last_game].verbal_score));
+
+ return records;
+ }
+
private void Save ()
{
try {
-
if (!Directory.Exists (config_path))
Directory.CreateDirectory (config_path);
diff --git a/src/Core/Views/FinishView.cs b/src/Core/Views/FinishView.cs
index ab49bb4..0ffc788 100644
--- a/src/Core/Views/FinishView.cs
+++ b/src/Core/Views/FinishView.cs
@@ -20,6 +20,7 @@
using System;
using Cairo;
using Mono.Unix;
+using System.Collections.Generic;
using gbrainy.Core.Main;
using gbrainy.Core.Libraries;
@@ -117,6 +118,7 @@ namespace gbrainy.Core.Views
{
double y = 0.04, x = 0.05;
const double space_small = 0.02;
+ List <PlayerHistory.PersonalRecord> records;
string s;
gr.Scale (area_width, area_height);
@@ -158,19 +160,70 @@ namespace gbrainy.Core.Views
DrawGraphicBar (gr, x, y);
y += 0.4;
- gr.MoveTo (x, y);
- gr.ShowPangoText (Catalog.GetString ("Tips for your next games"), false, -1, 0);
- DrawBand (gr, 0.03, y - 0.01);
-
- y += 0.08;
-
- for (int i = 0; i < tips_shown; i++)
- {
- y = gr.DrawStringWithWrapping (x, y, "- " + GameTips.Tip);
- if (y > 0.88)
- break;
-
- y += space_small;
+ records = session.PlayerHistory.GetLastGameRecords ();
+ gr.MoveTo (x, y);
+
+ Console.WriteLine ("Records {0}", records.Count);
+ if (records.Count == 0) {
+ gr.ShowPangoText (Catalog.GetString ("Tips for your next games"), false, -1, 0);
+ DrawBand (gr, 0.03, y - 0.01);
+
+ y += 0.08;
+
+ for (int i = 0; i < tips_shown; i++)
+ {
+ y = gr.DrawStringWithWrapping (x, y, "- " + GameTips.Tip);
+ if (y > 0.88)
+ break;
+
+ y += space_small;
+ }
+ }
+ else {
+ gr.ShowPangoText (Catalog.GetString ("Congratulations! New personal record"), false, -1, 0);
+ DrawBand (gr, 0.03, y - 0.01);
+
+ y += 0.08;
+
+ for (int i = 0; i < records.Count; i++)
+ {
+
+ switch (records[i].GameType) {
+ case Game.Types.LogicPuzzle:
+ s = String.Format (Catalog.
+ GetString ("By scoring {0}% in logic puzzle games you have established a new personal record. Your previous record was {1}%."),
+ records[i].NewScore,
+ records[i].PreviousScore);
+ break;
+ case Game.Types.MathTrainer:
+ s = String.Format (Catalog.
+ GetString ("By scoring {0}% in calculation games you have established a new personal record. Your previous record was {1}%."),
+ records[i].NewScore,
+ records[i].PreviousScore);
+ break;
+ case Game.Types.MemoryTrainer:
+ s = String.Format (Catalog.
+ GetString ("By scoring {0}% in memory games you have established a new personal record. Your previous record was {1}%."),
+ records[i].NewScore,
+ records[i].PreviousScore);
+ break;
+ case Game.Types.VerbalAnalogy:
+ s = String.Format (Catalog.
+ GetString ("By scoring {0}% in verbal analogies you have established a new personal record. Your previous record was {1}%."),
+ records[i].NewScore,
+ records[i].PreviousScore);
+ break;
+ default:
+ break;
+ }
+
+ Console.WriteLine (s);
+ y = gr.DrawStringWithWrapping (x, y, "- " + s);
+ if (y > 0.88)
+ break;
+
+ y += space_small;
+ }
}
gr.Stroke ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]