Module: Boy2Man
- Defined in:
- lib/Boy2Man/cli.rb,
lib/Boy2Man/janken.rb,
lib/Boy2Man/version.rb
Defined Under Namespace
Classes: Janken
Constant Summary collapse
- HANDS =
["グー", "チョキ", "パー"]
- VERSION =
"0.2.2"
Class Method Summary collapse
Class Method Details
.judge(a, b) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Boy2Man/janken.rb', line 4 def self.judge(a, b) case a when "グー" if b == "チョキ" return a elsif b == "パー" return b else return nil end when "チョキ" if b == "パー" return a elsif b == "グー" return b else return nil end when "パー" if b == "グー" return a elsif b == "チョキ" return b else return nil end end end |
.play ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/Boy2Man/cli.rb', line 3 def self.play janken = Janken.new loop do print '> ' hand = gets.chomp case hand when "", "bye", "exit" exit when *HANDS puts opponent = janken.pon(hand) winner = Boy2Man.judge(hand, opponent) if winner == hand puts "You Win!" elsif winner == opponent puts "You Lose!" else puts "Draw!" end when "history" puts janken.history when "reset" janken.reset else puts janken.select_hand end end end |