# -*- coding: utf-8 -*- puts"|PK対決ゲーム|" puts"" sum = -1 while true plus = [] i = 0 open("title.txt", "r") do |hen| while line = hen.gets if/..\s(\d+)/ =~ line plus[i] = $1.to_i i += 1 end end end open("title.txt", "w") do |outfile| outfile.puts " 得点" i = 0 while i < 3 do if sum > plus[i] outfile.printf("%s位 %d\n", i + 1, sum) i += 1 while i < 3 outfile.printf("%s位 %d\n", i + 1, plus[i - 1]) i += 1 end elsif sum <= plus[i] outfile.printf("%s位 %d\n", i + 1, plus[i]) i += 1 if sum == plus[i-1] while i < 3 outfile.printf("%s位 %d\n", i + 1, plus[i]) i += 1 end end end end end try = 0 tumi = 0 attack = 0 defence = 0 puts "" puts"-- メニュー --" puts"0: このゲームの説明" puts"1: コンピューターと対戦" puts"2: ランキングを表示" puts"3: ゲームを終わる" puts"" select = gets.to_i if select < 0 or select > 3 puts"0から3までの整数を入力しよう" redo end if select == 0 puts"このゲームはコンピューターとPK対決をするゲーム。" puts"左、真ん中、右の 中から1つの方向を選んでシュートを打ったり、" puts"自分のゴールを守ろう。" puts"それを5回繰り返して、シュートを入れた回数とゴールを守った回数が得点になる。 " puts"高得点を目指そう!" end if select == 1 until try == 5 tumi = 0 puts "ゴールを決めろ!!!" print "1.左, 2.真ん中, 3.右 :" input2 = gets.chomp.to_i if input2 < 1 or input2 > 3 puts"1から3までの整数を入力しよう" redo end hazusu = rand(10) g =rand(3) + 1 puts"" if input2 != g and hazusu != 4 sleep 1 print "\e[31m" puts "ごーる" print "\e[m" attack += 1 else sleep 1 print"\e[34m" puts "はずれ" print "\e[m" end puts"" while tumi < 1 puts "ゴールを守れ!!!" print "1. 左, 2. 真ん中, 3. 右 :" input2 = gets.chomp.to_i if input2 < 1 or input2 > 3 puts"1から3までの整数を入力しよう" redo end hazusu = rand(10) k = rand(3) + 1 tumi = 1 end puts"" if hazusu == 4 or input2 == k sleep 1 print "\e[31m" puts "まもれた" print "\e[m" defence += 1 else sleep 1 print "\e[34m" puts "はずれ" print "\e[m" end try += 1 puts"" end sum = attack + defence puts"" printf("シュート成功回数: %s回\n", attack) printf("ゴール防衛回数: %s回\n", defence) printf("合計%s点でした\n", sum) end if select == 2 open("title.txt", "r") do |yomu| while line = yomu.gets puts line end end end if select == 3 break end end