From: Jason Woofenden Date: Mon, 4 Nov 2013 01:37:55 +0000 (-0500) Subject: Merge remote-tracking branch 'sbd/master' X-Git-Url: https://jasonwoof.com/gitweb/?p=hexbog.git;a=commitdiff_plain;h=6efb82ed2f52b2567a7e7c5d42ff0ea4c3b3a615;hp=3003890232b44be7ceaedd00963092a27b6f9535 Merge remote-tracking branch 'sbd/master' --- diff --git a/.gitignore b/.gitignore index 71ea8f6..1d6409b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 962d6ff..929563b 100644 --- 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 diff --git a/main.coffee b/main.coffee index e19481f..ce67983 100644 --- a/main.coffee +++ b/main.coffee @@ -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 = $("
#{letter}
") + hp = 1 + Math.floor(Math.random() * (HP_MAX - 1)) + + html_tile = $("
#{letter}
") $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() diff --git a/style.less b/style.less index ee67ce3..ac8d122 100644 --- a/style.less +++ b/style.less @@ -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 --- 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 diff --git a/template.html b/template.html index efc4d56..2f9849d 100644 --- a/template.html +++ b/template.html @@ -6,7 +6,7 @@ @@ -79,7 +79,7 @@ cat style.css