[gnome-2048] Be stricter on allowed board size.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Be stricter on allowed board size.
- Date: Sun, 3 Feb 2019 07:04:35 +0000 (UTC)
commit 17701911dbc4d001e624f871a74131239bdc8d3b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Feb 3 08:04:16 2019 +0100
Be stricter on allowed board size.
I forgot to block the 1 by 1 one.
Block also numbers bigger than 9.
src/application.vala | 12 ++++++++----
src/grid.vala | 2 +-
2 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index ffb1144..cae37f5 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -429,13 +429,13 @@ private class Application : Gtk.Application
int rows = _settings.get_int ("rows");
int cols = _settings.get_int ("cols");
+ bool is_square = rows == cols;
bool disallowed_grid = is_disallowed_grid_size (ref rows, ref cols);
- if (disallowed_grid)
+ if (disallowed_grid && !is_square)
/* Translators: command-line warning displayed if the user manually sets a invalid grid size */
warning (_("Grids of size 1 by 2 are disallowed."));
- if (((rows != cols) && !disallowed_grid)
- || ((rows == cols) && rows != 4 && rows != 3 && rows != 5))
+ if (!disallowed_grid && (!is_square || (is_square && rows != 4 && rows != 3 && rows != 5)))
/* Translators: on main window, entry of the menu when clicking on the "New Game" button;
appears only if the user has set rows and cols manually */
_append_new_game_item (_("Custom"), /* rows */ rows, /* cols */ cols, ref menu);
@@ -449,8 +449,12 @@ private class Application : Gtk.Application
}
internal static bool is_disallowed_grid_size (ref int rows, ref int cols)
+ requires (rows >= 1)
+ requires (rows <= 9)
+ requires (cols >= 1)
+ requires (cols <= 9)
{
- return (rows == 1 && cols == 2) || (rows == 2 && cols == 1);
+ return (rows == 1 && cols == 1) || (rows == 1 && cols == 2) || (rows == 2 && cols == 1);
}
/*\
diff --git a/src/grid.vala b/src/grid.vala
index 80bf505..ed7841b 100644
--- a/src/grid.vala
+++ b/src/grid.vala
@@ -499,7 +499,7 @@ private class Grid : Object
rows = int.parse (tokens[0]);
cols = int.parse (tokens[1]);
- if ((rows < 1) || (cols < 1))
+ if ((rows < 1) || (cols < 1) || (rows > 9) || (cols > 9))
return false;
if (Application.is_disallowed_grid_size (ref rows, ref cols))
return false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]