Ruby/Opal サンプル


コード。Ruby 部分のみ。

require 'native'

d = Native(`document`)
area = d.getElementById("text")
button = d.getElementById("start")
interval = Native(`window.setInterval`)

z, d = zd = ["ズン", "ドコ"]
st = ""
line = []
f = false

zundoko = ->{
  return if f
  line << zd[rand(2)]
  line = line.last(5)
  st += line.last
  area.textContent = st
  if line == [z, z, z, z, d]
    area.textContent = st + " キ・ヨ・シ!"
    f = true
  end
}

start = ->{interval.call(zundoko, 1000)}
button.addEventListener("click", start)