- # TODO make this apply eavenly to neighbors
- # TODO different range for different word lengths
- for nei in [neighbors, nneighbors]
- if unsink > 0
- for i in nei
- if i.hp is 0 and unsink >= 10
- i.new_hp = 10
- unsink -= 10
- i.text = new_letter()
- i.dom.html i.text
- for nei in [neighbors, nneighbors]
- if unsink > 0
- for i in nei
- if i.hp > 0 and unsink > 0
- unsink -= 10 - i.hp
- i.new_hp = 10
+ 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
+ while b.flips > 0 and b.down.length > 0
+ b.flips -= 1
+ flipper = Math.floor(Math.random() * b.down.length)
+ unsink b.down[flipper]
+ b.down = [b.down[0...flipper]..., b.down[flipper+1...b.down.length]...]
+ if b.force > 0
+ for t in b.up
+ t.new_hp = t.hp + b.force