Newer
Older
Ruby / hope.rb
@ABE Koshun ABE Koshun on 2 Feb 2022 612 bytes 2022-02-02 19:56:11
#!/usr/bin/env ruby
# coding: utf-8
score = 0
main_time = Thread.new do
  sleep 10
  puts"タイムアップ!"
  puts"あなたの得点は"
  3.times do
  sleep 1
  print"."
end
  puts"#{score}点です。"
  exit(1)
end

  while true
    srand
  x = rand(10)
  y = rand(10)
  sum = x+ y


  t = Thread.new do
    puts"#{x}+#{y}は?"
    sleep 5
    puts"時間切れ"
    exit(1)
  end


  x = gets.chomp!.to_i


  if x ==sum
    puts"正解です"
    puts""
    score += 1
    Thread.kill(t)
  else
    puts"不正解です"
    puts""
    score -=1
    Thread.kill(t)
  end
  t.join
end

main_time.join