# program.rb

[[ RAW TEXT(DOWNLOAD here) ]]

    #!/usr/bin/env ruby
    # -*- coding: utf-8 -*-

    #初期設定

    require 'curses'
    include Curses

    init_screen
    cbreak
    noecho

    rt = []

    begin
      sleep(0)

      10.times do
        system("display -geometry +0+0 before.jpg&")
        sleep(2)
        system('pkill magick -U `whoami`')
        srand
        i = rand(3)+1
        if i == 1
          system("display -geometry +0+0 after1.jpg&")
        elsif i == 2
          system("display -geometry +0+0 after2.jpg&")
        elsif i == 3
          system("display -geometry +0+0 after3.jpg&")
        end
        setpos(0,0)
        addstr("\n 1:安全 2:危険")
        refresh
        start = Time.now
        answer = getch
        stop = Time.now
        rt << [i,answer,stop.to_f - start.to_f]
        refresh

        system('pkill magick -U `whoami`')
        setpos(0,0)
        addstr("\n ")
        refresh
        sleep(2)
      end

      correct = 0
      total = 0
      for j in rt
        total += j[2]
        if (j[0] == 1 && j[1] == "1") || (j[0] != 1 && j[1] == "2")
          correct += 1
        end
      end

    ensure
      close_screen
    end

    printf("正答%d回　　反応時間%5.3f秒\n", correct, total/10)