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

puts"どれを学習しますか?"
puts"1:国語"
puts"2:数学"
puts"3:社会"
puts"4:理科"
puts"5:英語"

kotae = gets.to_i

if kotae == 1
  require 'curses'
include Curses

init_screen
cbreak
noecho

rt = []

begin
  sleep(0)

    10.times do
    system("display -geometry +0+0 mondai.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)
end
