[swell-foop/arnaudb/two-tiles: 4/4] Avoid unclickable boards.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [swell-foop/arnaudb/two-tiles: 4/4] Avoid unclickable boards.
- Date: Tue, 2 Jun 2020 07:06:13 +0000 (UTC)
commit a706dc3312a457dc1517b561d4dc8d376a84a266
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Jun 1 09:21:12 2020 +0200
Avoid unclickable boards.
src/game.vala | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 0a76775..b6821ec 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -131,7 +131,8 @@ private class Game : Object
/* populate with the requested number of colors */
do (populate_new_game (ref initial_board, color_num));
- while (bad_colors_number (ref initial_board, color_num));
+ while (bad_colors_number (ref initial_board, color_num)
+ || unclickable_board (ref initial_board));
/* create the board of Tile instances */
for (uint8 x = 0; x < columns; x++)
@@ -181,6 +182,20 @@ private class Game : Object
}
return true;
}
+ private static bool unclickable_board (ref uint8 [,] initial_board)
+ {
+ uint8 rows = (uint8) initial_board.length [0];
+ uint8 columns = (uint8) initial_board.length [1];
+ for (uint8 x = 1; x < columns; x++)
+ for (uint8 y = 0; y < rows; y++)
+ if (initial_board [y, x] == initial_board [y, x - 1])
+ return false;
+ for (uint8 x = 0; x < columns; x++)
+ for (uint8 y = 1; y < rows; y++)
+ if (initial_board [y, x] == initial_board [y - 1, x])
+ return false;
+ return true;
+ }
/* Recursively find all the connected tile from given_tile */
private static List<Tile> _connected_tiles_real (Tile? given_tile, ref Tile? [,] current_board)
@@ -448,7 +463,8 @@ private class Game : Object
}
}
- if (bad_colors_number (ref initial_board, color_num))
+ if (bad_colors_number (ref initial_board, color_num)
+ || unclickable_board (ref initial_board))
return false;
Tile? [,] current_board = new Tile? [rows, columns];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]