[four-in-a-row] Multi-blink.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row] Multi-blink.
- Date: Sun, 22 Dec 2019 23:57:39 +0000 (UTC)
commit 243177ae84d6d6cdd0dc44ad00589bc2cd4436a3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Dec 23 00:27:24 2019 +0100
Multi-blink.
src/four-in-a-row.vala | 61 +++++++++++++++++++++++++++++---------------------
src/game-board.vala | 37 ++++++++++++++++++++++++------
2 files changed, 66 insertions(+), 32 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 0ab2245..0c11a4d 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -78,10 +78,8 @@ private class FourInARow : Gtk.Application
// animation
private static AnimID anim = AnimID.NONE;
- private int blink_r1 = 0;
- private int blink_c1 = 0;
- private int blink_r2 = 0;
- private int blink_c2 = 0;
+ private int [,] blink_lines = {{}};
+ private uint8 blink_line = 0; // index of currenly blinking line in blink_lines
private int blink_t = 0;
private int blink_n = 0;
private bool blink_on = false;
@@ -360,14 +358,13 @@ private class FourInARow : Gtk.Application
blink_t = winner;
- if (game_board.is_line_at ((Tile) winner, row, column,
- out blink_r1, out blink_c1,
- out blink_r2, out blink_c2))
+ if (game_board.is_line_at ((Tile) winner, row, column, out blink_lines))
{
anim = AnimID.BLINK;
blink_on = false;
blink_n = n;
- var temp = new Animate (0, this);
+ blink_line = 0;
+ var temp = new Animate (0, this, n);
timeout = Timeout.add (SPEED_BLINK, temp.exec);
while (timeout != 0)
main_iteration ();
@@ -379,18 +376,22 @@ private class FourInARow : Gtk.Application
/* draw a line of 'tile' from r1,c1 to r2,c2 */
bool done = false;
- int d_row = 0;
- int d_col = 0;
+ int d_row;
+ int d_col;
if (r1 < r2)
d_row = 1;
else if (r1 > r2)
d_row = -1;
+ else
+ d_row = 0;
if (c1 < c2)
d_col = 1;
else if (c1 > c2)
d_col = -1;
+ else
+ d_col = 0;
do
{
@@ -635,30 +636,30 @@ private class FourInARow : Gtk.Application
moves = 0;
}
- private inline void blink_tile (int r, int c, int t, int n)
+ private inline void blink_tile (int row, int col, int t, int n)
{
if (timeout != 0)
return;
- blink_r1 = r;
- blink_c1 = c;
- blink_r2 = r;
- blink_c2 = c;
+ blink_lines = {{ row, col, row, col }};
+ blink_line = 0;
blink_t = t;
blink_n = n;
blink_on = false;
anim = AnimID.BLINK;
- var temp = new Animate (0, this);
+ var temp = new Animate (0, this, n);
timeout = Timeout.add (SPEED_BLINK, temp.exec);
}
private class Animate
{
- int c;
- FourInARow application;
- internal Animate (int c, FourInARow application)
+ private int c;
+ private FourInARow application;
+ private int blink_n_times;
+ internal Animate (int c, FourInARow application, int blink_n_times = 0)
{
this.c = c;
this.application = application;
+ this.blink_n_times = blink_n_times;
}
internal bool exec ()
@@ -701,15 +702,25 @@ private class FourInARow : Gtk.Application
return true;
case AnimID.BLINK:
- application.draw_line (application.blink_r1, application.blink_c1,
- application.blink_r2, application.blink_c2,
- application.blink_on ? application.blink_t : Tile.CLEAR);
+ application.draw_line (/* row 1 */ application.blink_lines [application.blink_line, 0],
+ /* col 1 */ application.blink_lines [application.blink_line, 1],
+ /* row 2 */ application.blink_lines [application.blink_line, 2],
+ /* col 2 */ application.blink_lines [application.blink_line, 3],
+ /* tile */ application.blink_on ? application.blink_t :
Tile.CLEAR);
application.blink_n--;
if (application.blink_n <= 0 && application.blink_on)
{
- anim = AnimID.NONE;
- application.timeout = 0;
- return false;
+ if (application.blink_line >= application.blink_lines.length [0] - 1)
+ {
+ anim = AnimID.NONE;
+ application.timeout = 0;
+ return false;
+ }
+ else
+ {
+ application.blink_line++;
+ application.blink_n += blink_n_times;
+ }
}
application.blink_on = !application.blink_on;
return true;
diff --git a/src/game-board.vala b/src/game-board.vala
index e801b0e..27a8a3f 100644
--- a/src/game-board.vala
+++ b/src/game-board.vala
@@ -54,13 +54,36 @@ private class Board : Object {
* * check if there is a line passing by a given point
\*/
- internal bool is_line_at(Tile p, int r, int c,
- out int r1 = null, out int c1 = null,
- out int r2 = null, out int c2 = null) {
- return is_hline_at (p, r, c, out r1, out c1, out r2, out c2) ||
- is_vline_at (p, r, c, out r1, out c1, out r2, out c2) ||
- is_dline1_at(p, r, c, out r1, out c1, out r2, out c2) ||
- is_dline2_at(p, r, c, out r1, out c1, out r2, out c2);
+ internal bool is_line_at(Tile tile, int row, int col, out int [,] lines = null) {
+ uint8 n_lines = 0;
+ int [,] lines_tmp = new int [4, 4];
+
+ if (is_hline_at (tile, row, col, out lines_tmp [0, 0],
+ out lines_tmp [0, 1],
+ out lines_tmp [0, 2],
+ out lines_tmp [0, 3]))
+ n_lines++;
+ if (is_vline_at (tile, row, col, out lines_tmp [n_lines, 0],
+ out lines_tmp [n_lines, 1],
+ out lines_tmp [n_lines, 2],
+ out lines_tmp [n_lines, 3]))
+ n_lines++;
+ if (is_dline1_at(tile, row, col, out lines_tmp [n_lines, 0],
+ out lines_tmp [n_lines, 1],
+ out lines_tmp [n_lines, 2],
+ out lines_tmp [n_lines, 3]))
+ n_lines++;
+ if (is_dline2_at(tile, row, col, out lines_tmp [n_lines, 0],
+ out lines_tmp [n_lines, 1],
+ out lines_tmp [n_lines, 2],
+ out lines_tmp [n_lines, 3]))
+ n_lines++;
+
+ lines = new int [n_lines, 4];
+ for (int x = 0; x < n_lines; x++)
+ for (int y = 0; y < 4; y++)
+ lines [x, y] = lines_tmp [x, y];
+ return n_lines != 0;
}
private inline bool is_hline_at(Tile p, int r, int c,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]