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

puts"なんの学習をしますか?"
puts"1:理科"
puts"2:社会"

kotae = gets.to_i

if kotae == 1
  require 'curses'
include Curses

init_screen
cbreak
noecho

rt = []

begin
  sleep(0)

  10.times do
    pid = spawn"display -geometry +15+15 gazou.jpg"
    sleep(0)
    system('pkill magick -U whoami')
    srand
    i = rand(3)+1
    if i  == 1
      pid = spawn"display -geometry +15+15 gazou1.jpg"
      sleep(0)
      Process.kill(:INT, pid)
    elsif i  == 2
      pid = spawn"display -geometry +15+15 gazou2.jpg"
    elsif i  == 3
      pid = spawn"display -geometry +15+15 gazou3.jpg"

      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
  end

  ensure
    close_screen
end
