Skip to content

Instantly share code, notes, and snippets.

@tompng
Forked from webcrafts/gist:5948862
Last active December 19, 2015 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tompng/5949809 to your computer and use it in GitHub Desktop.
Save tompng/5949809 to your computer and use it in GitHub Desktop.
#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