JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Merge remote-tracking branch 'sbd/master'
authorJason Woofenden <jason@jasonwoof.com>
Mon, 4 Nov 2013 01:37:55 +0000 (20:37 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 4 Nov 2013 01:37:55 +0000 (20:37 -0500)
.gitignore
Makefile
main.coffee
style.less
t
template.html

index 71ea8f6..1d6409b 100644 (file)
@@ -1,7 +1,7 @@
 index.html
 index.html.gz
-main.js
-main_min.js
-style.css
+index.js
+index_min.js
+index.css
 wordlist_compressed.js
 wordlist_min.js
index 962d6ff..929563b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,19 +6,19 @@ install: all
 wordlist_compressed.js: compress.coffee wordlist.txt
        coffee compress.coffee
 
-main.js: main.coffee
-       coffee -bc main.coffee
+index.js: main.coffee
+       coffee -bc -o .coffee-tmp main.coffee && mv .coffee-tmp/main.js index.js
 
-main_min.js: wordlist_compressed.js main.js
-       cat /usr/share/javascript/jquery/jquery.min.js main.js | uglifyjs -nc -o $@
+index_min.js: wordlist_compressed.js index.js
+       cat /usr/share/javascript/jquery/jquery.min.js index.js | uglifyjs -nc -o $@
 
-wordlist_min.js: wordlist_compressed.js main.js
+wordlist_min.js: wordlist_compressed.js index.js
        cat wordlist_compressed.js | uglifyjs -nc -o $@
 
-style.css: style.less
-       lessc style.less style.css
+index.css: style.less
+       lessc style.less index.css
 
-index.html: main_min.js wordlist_min.js template.html style.css
+index.html: index_min.js wordlist_min.js template.html index.css
        bash combine.bash template.html > $@ || (rm -f $@; exit 1)
 
 index.html.gz: index.html
@@ -26,4 +26,4 @@ index.html.gz: index.html
 
 
 clean:
-       rm -f main.js main_min.js wordlist_compressed.js wordlist_min.js style.css index.html index.html.gz
+       rm -f index.js index_min.js wordlist_compressed.js wordlist_min.js index.css index.html index.html.gz
index e19481f..ce67983 100644 (file)
@@ -26,6 +26,8 @@ slide_ms = 2000
 
 board_col_heights = [5, 6, 7, 8, 7, 6, 5]
 
+# code and css will need adjusting if you change HP_MAX
+HP_MAX = 10
 
 ##############################################################
 ##############    fix javascript some more    ################
@@ -231,7 +233,7 @@ init_board = ->
                encoded = get_cookie 'hexbog'
        if encoded? and encoded.length > board_tiles
                new_letter_queue = (encoded.substr 0, board_tiles).split ''
-               score = parseInt(encoded.substr(board_tiles), 10)
+               score = parseInt(encoded.substr(board_tiles), HP_MAX)
 
        # work out which grid spaces are connected
        # (neighbors, above, down)
@@ -306,17 +308,55 @@ save_game = ->
 
 # remove the selected tiles from the board, create new tiles, and slide everything into place
 blip_selection = ->
+       difficulty = 11 - Math.log(100 + score) # higher numbers are easier
+       unsink = difficulty * score_for selected_word() # how much tile restoration we have left to do
        faders = selected.num_sort()
        selected = []
        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)
+       # 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
        for i in tiles
-               unless i in faders
-                       unless i.hp < 1
-                               i.dom.removeClass "hp#{i.hp}"
-                               i.hp -= 1
-                               i.dom.addClass "hp#{i.hp}"
+               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)
@@ -402,15 +442,18 @@ select_tile = (num) ->
 new_tile = (num, x, y) ->
        letter = new_letter()
 
-       html_tile = $("<div class=\"tile hp10\" style=\"left: #{x}px; top: #{y}px\" unselectable=\"on\">#{letter}</div>")
+       hp = 1 + Math.floor(Math.random() * (HP_MAX - 1))
+
+       html_tile = $("<div class=\"tile hp#{hp}\" style=\"left: #{x}px; top: #{y}px\" unselectable=\"on\">#{letter}</div>")
        $board.append(html_tile)
 
        html_tile.data 'tile_number', num
-       tiles[num] = text: letter, dom: html_tile, hp: 10, id: num
+       tiles[num] = text: letter, dom: html_tile, hp: hp, id: num
 
        html_tile.click ->
                me = $(this)
                num = me.data 'tile_number'
+               return if tiles[num].hp < 1
                if num in selected
                        if selected.length > 2 and num is selected.last()
                                activate_selection()
@@ -607,14 +650,10 @@ init_keybinding = ->
                        when 27
                                unselect_all()
 
-$log = undefined
-init_log = ->
-       $log = $('#log')
 log = (msg) ->
-       console.log msg if console.log?
+       console.log msg if console?.log?
 
 init_game = ->
-       init_log()
        if $(window).height() >= 440
                $('#centerer').css('margin-top', '25px')
        init_keybinding()
index ee67ce3..ac8d122 100644 (file)
@@ -190,6 +190,7 @@ body {
                background-color: spin(lighten(desaturate(@tile-color, 70%), 9%), 100);
        }
        &.hp0 {
+               cursor: default;
                color: lighten(desaturate(@tile-color, 100%), 10%);
                background-color: lighten(desaturate(@tile-color, 100%), 10%);
        }
diff --git a/t b/t
index 8fd025c..711f21c 100755 (executable)
--- a/t
+++ b/t
@@ -3,5 +3,10 @@
 while true
 do
        inotifywait -q -e close_write -e delete_self `git ls-files` >/dev/null 2>&1 || exit
-       verbose make && dwb -x reload
+       if verbose make; then
+               notify-send "hexbog" "built"
+       else
+               notify-send "hexbog" "error building"
+       fi
+       #verbose make && dwb -x reload
 done
index efc4d56..2f9849d 100644 (file)
@@ -6,7 +6,7 @@
        <meta name="viewport" content="width=648">
        <link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAA/UlEQVQY02P4DwKnPYWFPU6BmQxAfOusJLu4ODvXk+tggecZLAn+7NLSHJYLmVOf/meo5mJgEG/msLXhyMliYOCqYmBwm5PJ0MLR3cwxy4RbigEIiv//5ZvBcfYExw7JpXeYgAJq4WaatzmevOC4wn/7vwlICUP6q28c339wfGT58v/3XwYGQQG2xv+cv39xfGH+qsDNx8BQ8v+6wEPuT+857nI/apEEaqj6/0dxD9/zJxzHhPb/1wAKGAcpMSzm2r2PY5mudwkrA0M1N1CwjqO8iqMkH+iwaob/L7JZZRLZjYw5HDeypD8De+7uDkWQ5wQ+3YT6FuJ9r7NgJgAB9nPOaCTI7QAAAABJRU5ErkJggg==" />
        <style>
-cat style.css
+cat index.css
        </style>
 </head>
 
@@ -79,7 +79,7 @@ cat style.css
                </div>
        </div>
        <script>
-cat main_min.js
+cat index_min.js
        </script>
        <script>
 cat wordlist_min.js