[gnome-sudoku] Show puzzle completion time as hours, minutes, seconds
- From: Parin Porecha <parinporecha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Show puzzle completion time as hours, minutes, seconds
- Date: Tue, 10 Jun 2014 07:05:46 +0000 (UTC)
commit 15152160c840238e1ea7507ca44821cdac4991b2
Author: Parin Porecha <parinporecha gmail com>
Date: Tue Jun 10 16:09:31 2014 +0530
Show puzzle completion time as hours, minutes, seconds
src/gnome-sudoku.vala | 3 ++-
src/sudoku-game.vala | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index cc94e15..8950003 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -266,6 +266,7 @@ public class Sudoku : Gtk.Application
game.board.completed.connect (() => {
var time = game.get_total_time_played ();
+ var time_str = SudokuGame.seconds_to_hms_string (time);
for (var i = 0; i < game.board.rows; i++)
{
@@ -277,7 +278,7 @@ public class Sudoku : Gtk.Application
saver.add_game_to_finished (game, true);
- var dialog = new MessageDialog(window, DialogFlags.DESTROY_WITH_PARENT, MessageType.INFO,
ButtonsType.NONE, _("Well done, you completed the puzzle in %f seconds"), time);
+ var dialog = new MessageDialog(window, DialogFlags.DESTROY_WITH_PARENT, MessageType.INFO,
ButtonsType.NONE, _("Well done, you completed the puzzle in %s"), time_str);
dialog.add_button (_("Same difficulty again"), 0);
dialog.add_button (_("New difficulty"), 1);
diff --git a/src/sudoku-game.vala b/src/sudoku-game.vala
index fef75b7..31fc560 100644
--- a/src/sudoku-game.vala
+++ b/src/sudoku-game.vala
@@ -128,4 +128,36 @@ public class SudokuGame
{
return board.previous_played_time + timer.elapsed ();
}
+
+ public static string seconds_to_hms_string (double time_in_seconds)
+ {
+ var SECOND = _("second");
+ var SECONDS = _("seconds");
+ var MINUTE = _("minute");
+ var MINUTES = _("minutes");
+ var HOUR = _("hour");
+ var HOURS = _("hours");
+
+ string[] time_array = {};
+ var seconds = (int) time_in_seconds;
+ var hours = seconds / 3600;
+ var hour_string = (hours == 1) ? HOUR : HOURS;
+
+ seconds = seconds % 3600;
+
+ var minutes = seconds / 60;
+ var minute_string = (minutes == 1) ? MINUTE : MINUTES;
+
+ seconds = seconds % 60;
+ var second_string = (seconds == 1) ? SECOND : SECONDS;
+
+ if (hours != 0)
+ time_array += "%d %s".printf (hours, hour_string);
+ if (minutes != 0)
+ time_array += "%d %s".printf (minutes, minute_string);
+ if (seconds != 0)
+ time_array += "%d %s".printf (seconds, second_string);
+
+ return string.joinv (", ", time_array);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]