Commits

Anonymous committed c583f0e

"glue" works

  • Participants
  • Parent commits 7272dc8

Comments (0)

Files changed (2)

 * Message location is fixed, should be deducted from screen size
-* "glue" don't work when there are two emtpy colums next to each other
 * Give a way to rotate the borad
 * Find a better message than "Game Over"
 * Make the message div nicer (round, colors ...)
     return 1;
 }
 
-function one_glue() {
-    var moved = 0;
-    for (var col = 1; col < LEVEL.cols -1; ++col) {
-        if (is_empty_col(col)) {
-            for (var row = 0; row < LEVEL.rows; ++row) {
-                var color = cell_color(row, col + 1);
-                moved = (color != BLANK);
-                cell_color(row, col, color);
-                cell_color(row, col + 1, BLANK);
-            }
+function next_full_col(col) {
+    for (col = col + 1; col < LEVEL.cols; ++col) {
+        if (! is_empty_col(col)) {
+            return col;
         }
     }
 
-    return moved;
+    return -1;
+}
+
+function move_col(from, to) {
+    for (var row = 0; row < LEVEL.rows; ++row) {
+        var tmp = cell_color(row, to);
+        cell_color(row, to, cell_color(row, from));
+        cell_color(row, from, tmp);
+    }
 }
 
 function glue_cols() {
-    while (one_glue()) {
-        ;
+    for (var col = 0; col < LEVEL.cols - 1; ++col) {
+        if (is_empty_col(col)) {
+            var full = next_full_col(col);
+            if (full == -1) {
+                return;
+            }
+            move_col(full, col);
+        }
     }
 }