Class: JankenContoller
- Inherits:
-
Object
- Object
- JankenContoller
- Defined in:
- lib/cureutils/janken_controller.rb
Overview
Wrapper class of Pikarin Janken
Class Attribute Summary collapse
-
.io ⇒ Object
writeonly
Sets the attribute io.
Class Method Summary collapse
- .generated_te ⇒ Object
- .initialize ⇒ Object
- .input_te ⇒ Object
- .janken ⇒ Object
- .judge ⇒ Object
- .print_results(player_te, cure_te, result) ⇒ Object
- .puts(input) ⇒ Object
Class Attribute Details
.io=(value) ⇒ Object (writeonly)
Sets the attribute io
22 23 24 |
# File 'lib/cureutils/janken_controller.rb', line 22 def io=(value) @io = value end |
Class Method Details
.generated_te ⇒ Object
38 39 40 41 |
# File 'lib/cureutils/janken_controller.rb', line 38 def generated_te @buf.last =~ /(#{@te_idx.join('|')})/ @te_hash[Regexp.last_match(1)].to_i end |
.initialize ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cureutils/janken_controller.rb', line 7 def initialize # Set the sleep time 0 Rubicure::Girl.sleep_sec = 0 # 0: win, 1: lose, 2: aiko @result_table = [[2, 0, 1, 1], [1, 2, 0, 1], [0, 1, 2, 1], [0, 0, 0, 2]] @result_idx = %w(あなたのかち あなたのまけ あいこ) @te_idx = %w(グー チョキ パー グッチョッパー) @te_hash = Hash[[@te_idx, (0..3).map(&:to_s)].transpose] @buf = [] @io = $stdout end |
.input_te ⇒ Object
43 44 45 46 47 48 |
# File 'lib/cureutils/janken_controller.rb', line 43 def input_te @io.print("1...グー, 2...チョキ, 3...パー : ") # TODO: Check input and raise the error. player_te = $stdin.gets player_te.to_i - 1 end |
.janken ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/cureutils/janken_controller.rb', line 28 def janken initialize Cure.peace.io = self Cure.peace.janken @buf[0..1].each do |msg| @io.puts msg end judge end |
.judge ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/cureutils/janken_controller.rb', line 50 def judge cure_te = generated_te player_te = input_te result_num = @result_table[player_te][cure_te] result = @result_idx[result_num] print_results(@te_idx[player_te], @te_idx[cure_te], result) result_num end |
.print_results(player_te, cure_te, result) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/cureutils/janken_controller.rb', line 59 def print_results(player_te, cure_te, result) @io.puts @io.puts 'あなた: ' + player_te @io.puts 'キュアピース: ' + cure_te @io.puts @io.puts '[結果]' @io.puts result end |
.puts(input) ⇒ Object
24 25 26 |
# File 'lib/cureutils/janken_controller.rb', line 24 def puts(input) @buf << input end |