Skip to content

Instantly share code, notes, and snippets.

@willnet
Created September 12, 2011 04:45
Show Gist options
  • Save willnet/1210602 to your computer and use it in GitHub Desktop.
Save willnet/1210602 to your computer and use it in GitHub Desktop.
devquiz2011webgame用コード
click = (id) ->
element = document.getElementById('card' + id)
myevent = document.createEvent('MouseEvents')
myevent.initEvent('click', false, true)
element.dispatchEvent(myevent)
element
size = $('.card').size() - 1
ary = new Array(size)
i = 0
while i < size
elem = click(i)
ary[i] = $(elem).css('background-color')
elem = click(i + 1)
ary[i+1] = $(elem).css('background-color')
if ary[i] is ary[i+1]
ary[i] = null
ary[i+1] = null
i = i + 2
answer = (i) ->
if ary[i] isnt null
click(i)
for j in [(i+1)..size]
if ary[i] is ary[j]
click(j)
# alert("#{i+1}枚目と#{j+1}枚目が同じ!")
ary[i] = null
ary[j] = null
return
for i in [0..size]
answer(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment