- 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()
- for above in aboves
- tiles[dest] = tiles[above]
- tiles[dest].id = dest
- tiles[dest].dom.data 'tile_number', dest
- sliders[dest] = true
- --dest
- sliders[col_top] = true # the new tile needs to be slid down too
-
- new_tile col_top, board_left_px[col_top], next_new_y
- next_new_y -= tile_width + 50
-
- for slide, i in sliders
- if slide
- tiles[i].dom.animate {top: "#{tile_top_px[i]}px"}, slide_ms
- sliders[i] = false
+ 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 s in spaces
+ if s.tile.hp is 0
+ unsink s.tile
+ else
+ s.tile.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 s in spaces
+ s.tile.new_hp ?= s.tile.hp - 1
+ if s.tile.new_hp < 0
+ s.tile.new_hp = 0
+ else if s.tile.new_hp > HP_MAX
+ s.tile.new_hp = HP_MAX
+ if s.tile.new_hp isnt s.tile.hp
+ s.tile.dom.removeClass "hp#{s.tile.hp}"
+ s.tile.dom.addClass "hp#{s.tile.new_hp}"
+ s.tile.hp = s.tile.new_hp
+ delete s.tile.new_hp
+ timeout fade_ms + 1, ->
+ # delete old tiles, mark where tiles are moving
+ for fader in faders
+ fader.space.column.fader_count += 1
+ fader.dom.remove()
+ fader.removed = true
+ for above in fader.space.aboves
+ if above.tile.dest?
+ above.tile.dest += 1
+ else
+ above.tile.dest = above.id + 1
+
+ # move tiles down (graphically and in data structure)
+ rspaces = []
+ for s in spaces
+ rspaces.unshift s
+ for space in rspaces
+ tile = space.tile
+ if tile.dest? and not (tile.removed?)
+ dest_space = spaces[tile.dest]
+ delete tile.dest
+ tile.dom.animate {top: "#{dest_space.top_px}px"}, slide_ms
+ tile.space = dest_space
+ dest_space.tile = tile
+
+ # create new tiles
+ for column in columns
+ dest = 0
+ while column.fader_count > 0
+ column.fader_count -= 1
+ slide_from = -10 - tile_width
+ slide_from -= (50 + tile_width) * column.fader_count
+ space = column.spaces[dest++]
+ tile = new_tile space, slide_from
+ tile.dom.animate {top: "#{space.top_px}px"}, slide_ms
+