- for num in faders
- html_tiles[num].unbind('click').fadeOut fade_ms
- timeout fade_ms, ->
- top_tile = -1
- new_px = 0
- new_slide = 0
- for fader in faders
- cur_top = board_aboves[fader][0]
- if cur_top is undefined
- cur_top = fader
- if top_tile isnt cur_top
- new_px = board_top_px[fader] - tile_width
- new_slide = 1
- top_tile = cur_top
- html_tiles[fader].remove()
- dest = fader
- aboves = board_aboves[fader].clone().reverse()
+ update_selection_display()
+ neighbors = {}
+ nneighbors = {}
+ for i in faders
+ tiles[i].dom.unbind('click').fadeOut fade_ms
+ tiles[i].new_hp = tiles[i].hp
+ for n in board_neighbors[i]
+ neighbors[n] = tiles[n]
+ for nn in board_neighbors[n]
+ nneighbors[nn] = tiles[nn]
+ for i in faders
+ delete nneighbors[i]
+ delete neighbors[i]
+ for k, v of neighbors
+ delete nneighbors[k]
+ # convert to arrays so we can sort, etc
+ nneighbors = (v for k, v of nneighbors)
+ neighbors = (v for k, v of neighbors)
+ boom = [
+ {
+ tiles: neighbors,
+ up: [],
+ down: []
+ },
+ {
+ tiles: nneighbors,
+ up: [],
+ down: []
+ }
+ ]
+ for n in boom
+ for t in n.tiles
+ if t.hp is 0
+ n.down.push t
+ else
+ n.up.push t
+ switch word_length
+ when 3
+ boom[0].flips = 1
+ boom[0].force = 2
+ boom[1].flips = 0
+ boom[1].force = 0
+ when 4
+ boom[0].flips = 'all'
+ boom[0].force = 4
+ boom[1].flips = 0
+ boom[1].force = 2
+ when 5
+ boom[0].flips = 'all'
+ boom[0].force = 6
+ boom[1].flips = 2
+ boom[1].force = 4
+ when 6
+ boom[0].flips = 'all'
+ boom[0].force = 10
+ boom[1].flips = 5
+ boom[1].force = 6
+ when 7
+ boom[0].flips = 'all'
+ boom[0].force = 10
+ boom[1].flips = 'all'
+ boom[1].force = 10
+ else
+ boom[0].flips = 0
+ boom[0].force = 0
+ boom[1].flips = 0
+ boom[1].force = 0
+ # unsink/heal the whole board
+ for t in tiles
+ if t.hp is 0
+ unsink t
+ else
+ t.new_hp = 10
+ for b in boom
+ if b.flips is 'all' or b.flips >= b.down.length
+ for t in b.down
+ unsink t
+ else
+ down_count = b.down.length
+ while b.flips > 0 and down_count
+ b.flips -= 1
+ flipper = Math.floor(Math.random() * down_count)
+ unsink b.down[flipper]
+ down_count -= 1
+ # move the last tile back into range
+ b.down[flipper] = b.down[down_count]
+ if b.force > 0
+ for t in b.up
+ t.new_hp = t.hp + b.force
+ for i in tiles
+ i.new_hp ?= i.hp - 1
+ if i.new_hp < 0
+ i.new_hp = 0
+ else if i.new_hp > HP_MAX
+ i.new_hp = HP_MAX
+ if i.new_hp isnt i.hp
+ i.dom.removeClass "hp#{i.hp}"
+ i.dom.addClass "hp#{i.new_hp}"
+ i.hp = i.new_hp
+ delete i.new_hp
+ timeout fade_ms + 1, ->
+ # which tiles need to be slid down
+ sliders = (false for i in tiles)
+
+ prev_col_top = null
+ next_new_y = null
+ for deleted in faders
+ # find the tile number of the top tile in this column
+ if board_aboves[deleted].length is 0
+ col_top = deleted
+ else
+ col_top = board_aboves[deleted][0]
+
+ # reset location where new tiles appear when we change columns
+ if prev_col_top isnt col_top
+ next_new_y = -10 - tile_width
+ prev_col_top = col_top
+
+ tiles[deleted].dom.remove()
+
+ # For each each tile above the one we've deleted:
+ # 1. move it down one slot in the data scructures
+ # 2. mark it as needing to slide
+ dest = deleted
+ aboves = board_aboves[deleted].clone().reverse()