-
-
Save tompng/5949809 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
class Te | |
attr_accessor :te_num | |
def initialize num=nil | |
self.te_num = num ? num % 3 : rand(3) | |
end | |
def > te | |
(te_num + 1) % 3 == te.te_num | |
end | |
def < te | |
te > self | |
end | |
def == te | |
te_num == te.te_num | |
end | |
def to_s | |
%w(グー チョキ パー)[te_num] | |
end | |
def self.all | |
3.times.map{|te_num|Te.new te_num} | |
end | |
end | |
results = [] | |
3.times do | |
pc_te = Te.all.sample | |
my_te = Te.new gets.to_i | |
puts "人間の手は「#{my_te}」、コンピュータの手は「#{pc_te}」" | |
if my_te < pc_te | |
result = 'コンピュータの勝ち' | |
elsif my_te > pc_te | |
result = '人間の勝ち' | |
else | |
result = 'あいこ' | |
end | |
puts "勝敗結果は・・・「#{result}」です。" | |
results << result | |
end | |
puts "******************************************" | |
results.each.with_index(1) do |result, count| | |
puts "#{count}回戦の結果は・・・#{result}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment