#! usr/bin/env ruby # -*- coding: utf-8 -*- require 'csv' data = CSV.read("j2106_intro.csv", :headers => true) def loading(time) if time == 2 printf("\e[%dmloading",90) 2.times do sleep(0.3) print "." end puts "" sleep(0.4) print "\e[0m" else printf("\e[%dmloading",90) 3.times do sleep (0.3) print "." end puts "" sleep(0.4) print "\e[0m" end end def levenshtein_distance(divide_input) ziten = [] file = CSV.read("j2106_intro.csv", :headers => true) ziten << file.each{|row|["単語"]} if divide_input.length == 0 printf "%s",ziten sleep(2) else for divide_ziten in ziten sleep(3) comparison_ziten = divide_ziten.split("") p comparison_ziten sleep(3) comparison_input = divide_input.split("") p comparison_input sleep(3) if comparison_ziten.length - comparison_input.length > 0 comparison_ziten.length - comparison_input.length > 0 elsif comparison_input.length - comparison_ziten.length > 0 distance =+ comparison_input.length - comparison_ziten.length end printf("ちがうのは%sだよ\n",different) end end printf("辞典にある単語との遠さ:%d",distance) end p "土門侑生とは" print "何について見る?\n" puts "番号を入力してね." puts "1.土門侑生とは\n2.好きなもの\n3.my中二病語辞典\n" choice = gets.chomp if choice == "1" loading(3) print "土門侑生とは\n山形県酒田市立第六中学校の2年生。部活?そんなもの知らないね。\nかわりに勉強頑張ってるからいいんだよ。\nあとは...自作PCを持っている。\nそれぐらいかなぁ。\nじゃあクイズ出します。\n番号で入力してね。\n" require 'curses' include Curses init_screen cbreak noecho begin correct = 0 setpos(0,0) addstr("私はなんと呼ばれているでしょうか。\n1.MP3\n2.ZIP\n3.PDF\n") refresh answer1 = getch if answer1 == "3" correct += 1 end setpos(0,0) addstr("私の得意な教科は何でしょうか。\n1.国語\n2.数学\n3.英語\n") refresh answer2 = getch if answer2 == "2" correct += 1 end setpos(0,0) addstr("私が寝る前に必ず行うことは何でしょうか。\n1.音楽を聴く\n2.アニメを見る\n3.漫画を読む\n") refresh answer3 = getch if answer3 == "1" correct += 1 end ensure close_screen end printf("正答数:%d\n",correct) correct_percent = correct * 100 * 1/3 printf("正答率:%dパーセント\n",correct_percent) elsif choice == "2" loading(3) like = CSV.read("j2106_intro_like.csv", :headers => true) lank = 1 puts "好きなもの\n私の好きなものをランキングにしたよ。\nどれ見る?" puts "1.音楽(アーティスト)\n2.ゲーム\n3.漫画\n" choice2 = gets.chomp if choice2 == "1" like.each{|row| printf("%d.%s\n",lank,row["音楽(アーティスト)"]) lank += 1 } elsif choice2 == "2" like.each{|row| printf("%d.%s\n",lank,row["ゲーム"]) lank += 1 } puts"slither.ioはフリーのブラウザゲームだからすぐに遊べるよ。\nやってみる?\nはいかいいえで答えてね。" yesno = gets.chomp if yesno == "はい" system("firefox","http://slither.io") elsif yesno == "いいえ" puts "今度やってみてね。" end elsif choice2 == "3" like.each{|row| printf("%d.%s\n",lank,row["漫画"]) lank += 1 } else puts "..." end elsif choice == "3" loading(3) puts "my中二病語辞典" puts "my中二病語辞典とは?\n---私の好きな中二病語が載ってるで。" puts "1.語とその意味を見る\n2.語だけ見る\n3.調べる\n番号を入力してな。" choice2 = gets.chomp if choice2 == "1" ziten.each{|row| printf("%s\n",row["単語"]) sleep(1) printf("---%s\n",row["意味"]) sleep(1) } elsif choice2 == "2" printf("%s\n",data["単語"]) sleep(1) elsif choice2 == "3" print "入力してください:" search_word = gets.chomp levenshtein_distance(search_word) else puts "そか。" end else end