From 33354ef7e2ac273a04fdfa9287e706e344d2db57 Mon Sep 17 00:00:00 2001
From: Roman Konoval
Date: Sun, 17 Feb 2013 12:27:34 +0200
Subject: [PATCH 1/8] Added possibility to push jellies
---
src/index.html | 3 +--
src/jelly.coffee | 29 ++++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/index.html b/src/index.html
index b65b8b7..74538ea 100644
--- a/src/index.html
+++ b/src/index.html
@@ -118,7 +118,7 @@ jelly
diff --git a/src/jelly.coffee b/src/jelly.coffee
index c442517..506e1a4 100644
--- a/src/jelly.coffee
+++ b/src/jelly.coffee
@@ -61,6 +61,11 @@ levels = [
CELL_SIZE = 48
+Array::unique = ->
+ output = {}
+ output[@[key]] = @[key] for key in [0...@length]
+ value for key, value of output
+
moveToCell = (dom, x, y) ->
dom.style.left = x * CELL_SIZE + 'px'
dom.style.top = y * CELL_SIZE + 'px'
@@ -131,8 +136,16 @@ class Stage
cell.style[attr] = border unless other and other.tagName == 'TD'
return
- trySlide: (jelly, dir) ->
- return if @checkFilled(jelly, dir, 0)
+ canSlide: (jelly, dir) ->
+ obstacles = @checkFilled(jelly, dir, 0)
+ for obstacle in obstacles
+ return false unless @canSlide(obstacle, dir)
+ return true
+
+ slide: (jelly, dir) ->
+ obstacles = @checkFilled(jelly, dir, 0)
+ for obstacle in obstacles
+ @slide(obstacle, dir)
@busy = true
@move(jelly, jelly.x + dir, jelly.y)
jelly.slide dir, () =>
@@ -140,6 +153,10 @@ class Stage
@checkForMerges()
@busy = false
+ trySlide: (jelly, dir) ->
+ return unless @canSlide(jelly, dir)
+ @slide(jelly, dir)
+
move: (jelly, targetX, targetY) ->
@cells[y][x] = null for [x, y] in jelly.cellCoords()
jelly.updatePosition(targetX, targetY)
@@ -147,17 +164,19 @@ class Stage
return
checkFilled: (jelly, dx, dy) ->
+ obstacles = []
for [x, y] in jelly.cellCoords()
next = @cells[y + dy][x + dx]
- return next if next and next != jelly
- return false
+ if next and next != jelly
+ obstacles.push next
+ return obstacles.unique()
checkFall: ->
moved = true
while moved
moved = false
for jelly in @jellies
- if not @checkFilled(jelly, 0, 1)
+ if @checkFilled(jelly, 0, 1).length == 0
@move(jelly, jelly.x, jelly.y + 1)
moved = true
return
From 64e4d760d52f2a460a99745c252efbf01f2bf6f7 Mon Sep 17 00:00:00 2001
From: Roman Konoval
Date: Sun, 17 Feb 2013 13:35:46 +0200
Subject: [PATCH 2/8] Added check for level completion
---
src/jelly.coffee | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/jelly.coffee b/src/jelly.coffee
index 506e1a4..5cc07ec 100644
--- a/src/jelly.coffee
+++ b/src/jelly.coffee
@@ -182,9 +182,14 @@ class Stage
return
checkForMerges: ->
+ merged = false
while jelly = @doOneMerge()
+ merged = true
for [x, y] in jelly.cellCoords()
@cells[y][x] = jelly
+ if merged
+ colors = (@jellies.map (jelly) -> jelly.color).unique().length
+ alert("Congratulations! Level completed.") if colors == @jellies.length
return
doOneMerge: ->
From 7ad85bc8d77ee8c8191156e706754e4305ae1269 Mon Sep 17 00:00:00 2001
From: Roman Konoval
Date: Sun, 17 Feb 2013 13:39:01 +0200
Subject: [PATCH 3/8] Added check for level completion
---
src/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/index.html b/src/index.html
index 74538ea..dab7eb7 100644
--- a/src/index.html
+++ b/src/index.html
@@ -133,7 +133,7 @@ jelly
Here's the source.
To be implemented:
- - A "you win" screen when you win.
+ - Beautiful "you win" screen when you win.
* It is WebKit-only because CSS prefixes are dumb and I
From 830a5237f37eb2126571dc530b0f5a80d8a24050 Mon Sep 17 00:00:00 2001
From: Roman Konoval
Date: Sun, 17 Feb 2013 12:27:34 +0200
Subject: [PATCH 4/8] Added possibility to push jellies
---
src/index.html | 3 +--
src/jelly.coffee | 29 ++++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/index.html b/src/index.html
index b65b8b7..74538ea 100644
--- a/src/index.html
+++ b/src/index.html
@@ -118,7 +118,7 @@ jelly
diff --git a/src/jelly.coffee b/src/jelly.coffee
index c442517..506e1a4 100644
--- a/src/jelly.coffee
+++ b/src/jelly.coffee
@@ -61,6 +61,11 @@ levels = [
CELL_SIZE = 48
+Array::unique = ->
+ output = {}
+ output[@[key]] = @[key] for key in [0...@length]
+ value for key, value of output
+
moveToCell = (dom, x, y) ->
dom.style.left = x * CELL_SIZE + 'px'
dom.style.top = y * CELL_SIZE + 'px'
@@ -131,8 +136,16 @@ class Stage
cell.style[attr] = border unless other and other.tagName == 'TD'
return
- trySlide: (jelly, dir) ->
- return if @checkFilled(jelly, dir, 0)
+ canSlide: (jelly, dir) ->
+ obstacles = @checkFilled(jelly, dir, 0)
+ for obstacle in obstacles
+ return false unless @canSlide(obstacle, dir)
+ return true
+
+ slide: (jelly, dir) ->
+ obstacles = @checkFilled(jelly, dir, 0)
+ for obstacle in obstacles
+ @slide(obstacle, dir)
@busy = true
@move(jelly, jelly.x + dir, jelly.y)
jelly.slide dir, () =>
@@ -140,6 +153,10 @@ class Stage
@checkForMerges()
@busy = false
+ trySlide: (jelly, dir) ->
+ return unless @canSlide(jelly, dir)
+ @slide(jelly, dir)
+
move: (jelly, targetX, targetY) ->
@cells[y][x] = null for [x, y] in jelly.cellCoords()
jelly.updatePosition(targetX, targetY)
@@ -147,17 +164,19 @@ class Stage
return
checkFilled: (jelly, dx, dy) ->
+ obstacles = []
for [x, y] in jelly.cellCoords()
next = @cells[y + dy][x + dx]
- return next if next and next != jelly
- return false
+ if next and next != jelly
+ obstacles.push next
+ return obstacles.unique()
checkFall: ->
moved = true
while moved
moved = false
for jelly in @jellies
- if not @checkFilled(jelly, 0, 1)
+ if @checkFilled(jelly, 0, 1).length == 0
@move(jelly, jelly.x, jelly.y + 1)
moved = true
return
From 3a1e8701b78eba42a1767a53b2f249184f601dab Mon Sep 17 00:00:00 2001
From: Roman Konoval
Date: Fri, 22 Feb 2013 13:22:02 +0200
Subject: [PATCH 5/8] Added tests
---
.gitignore | 1 +
src/index.html | 1 +
src/jelly.coffee | 31 ++++++----
test/jellyTest.coffee | 112 ++++++++++++++++++++++++++++++++++++
test/test.html | 130 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 263 insertions(+), 12 deletions(-)
create mode 100644 test/jellyTest.coffee
create mode 100644 test/test.html
diff --git a/.gitignore b/.gitignore
index 722cb3e..f15aebb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/src/jelly.js
+/test/jellyTest.js
diff --git a/src/index.html b/src/index.html
index 74538ea..2d5ef10 100644
--- a/src/index.html
+++ b/src/index.html
@@ -140,5 +140,6 @@ jelly
don't have the patience to test on other browsers.
+