Boy2Man 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe8409cb3b5a4c95cb050b83c4ab25002a399a8a
4
- data.tar.gz: f6df36a22794641a1e54cad2787bd1b94f7cbd71
3
+ metadata.gz: cf09c31b373b25cb9019efd9b20a4b1699713a1f
4
+ data.tar.gz: 9fa59a0c7cfb78b4fa28ce9dde125766aa48f1a8
5
5
  SHA512:
6
- metadata.gz: 116dd50cfd17a702ecd6f0cb18706ee24d157e21db3dc38fd47d7f245bdd4acc18601c8b74ce10b7e951e5f6967f0996c8785fedf9f6e249b4ac73e2bb4b9eb5
7
- data.tar.gz: e7375f8243412dfd702c0f4902e38345732074d2d5f81b7290976c05085824304689b85299ba33f62eb8d449cbe078826876ef083b1ddba99040c559436a74f4
6
+ metadata.gz: 4838e5d2da32e34c6540bd13993043af74f1b0dda751c5feb347f326dcd0b74e3fa6e0368e3f663605e325f4457be54469e0275b8d70a0f480fde9ea159acef2
7
+ data.tar.gz: 3c86dd5dce8505b9c1158d0b0f3a20d73da68aa7658e9ce5b892d3e24c8236048917f153354a4a38d367d24ce62f6850ba17c90fba189449a4f7da4ba2bc3073
data/README.md CHANGED
@@ -17,6 +17,17 @@ Or install it yourself as:
17
17
 
18
18
  $ gem install Boy2Man
19
19
 
20
+ ## Usage
21
+ ### As a CLI
22
+
23
+ $ Boy2Man
24
+
25
+ and then game will start.
26
+
27
+ ### As a Library
28
+
29
+ see <http://rubydoc.info/gems/Boy2Man>
30
+
20
31
  ## Rule
21
32
 
22
33
  あと出しはその場で負け!
File without changes
@@ -8,20 +8,24 @@ module Boy2Man
8
8
  stand = Boy2Man.new
9
9
  loop do
10
10
  print '> '
11
- hand = gets
11
+ hand = gets.chomp
12
12
  case hand
13
- when "\n", "bye\n", "exit\n"
13
+ when "", "bye", "exit"
14
14
  exit
15
- when "グー\n", "チョキ\n", "パー\n"
16
- puts stand.match(hand.chomp)
17
- when "history\n"
15
+ when "グー", "チョキ", "パー"
16
+ puts stand.match(hand)
17
+ when "history"
18
18
  puts stand.history
19
+ when "reset"
20
+ stand.reset
19
21
  else
20
22
  puts stand.select_hand
21
23
  end
22
24
  end
23
25
  end
24
26
 
27
+ # @!attribute [r] history
28
+ # @return [Array] the history of player's hand
25
29
  class Boy2Man
26
30
  attr_reader :history
27
31
 
@@ -33,18 +37,32 @@ module Boy2Man
33
37
  # retrun deep copy of history, to prevent history to be changed.
34
38
  Marshal.load(Marshal.dump(@history))
35
39
  end
36
-
40
+
41
+ # @return [Array] resets history
42
+ def reset
43
+ @history.clear
44
+ end
45
+
46
+ # @return [String]
37
47
  def match(hand)
38
48
  case hand
39
49
  when "グー", "チョキ", "パー"
40
50
  # 先に手を決めておかないと後出しになる
41
51
  selected = select_hand
42
52
  @history.push hand
43
- selected
53
+ case judge(hand, selected)
54
+ when hand
55
+ selected + "\nYou Win!"
56
+ when selected
57
+ selected + "\nYou Lose!"
58
+ else
59
+ selected + "\nDraw!"
60
+ end
44
61
  else
45
62
  end
46
63
  end
47
64
 
65
+ # @return [String]
48
66
  def select_hand
49
67
  case predict
50
68
  when "グー" then "パー"
@@ -57,5 +75,35 @@ module Boy2Man
57
75
  def predict
58
76
  @history.empty? ? %w(グー チョキ パー).sample : @history.sample
59
77
  end
78
+
79
+ def judge(a, b)
80
+ case a
81
+ when "グー"
82
+ if b == "チョキ"
83
+ return a
84
+ elsif b == "パー"
85
+ return b
86
+ else
87
+ return nil
88
+ end
89
+ when "チョキ"
90
+ if b == "パー"
91
+ return a
92
+ elsif b == "グー"
93
+ return b
94
+ else
95
+ return nil
96
+ end
97
+ when "パー"
98
+ if b == "グー"
99
+ return a
100
+ elsif b == "チョキ"
101
+ return b
102
+ else
103
+ return nil
104
+ end
105
+ end
106
+ end
107
+
60
108
  end
61
109
  end
@@ -1,3 +1,3 @@
1
1
  module Boy2Man
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -26,5 +26,15 @@ class TestBoy2Man < MiniTest::Unit::TestCase
26
26
  assert_equal(["グー"], @stand.history)
27
27
  @stand.match("チョキ")
28
28
  assert_equal(["グー", "チョキ"], @stand.history)
29
+
30
+ @stand.history.push("something")
31
+ assert_equal(["グー", "チョキ"], @stand.history)
32
+ end
33
+
34
+ def test_reset
35
+ assert_respond_to @stand, :reset
36
+ @stand.match("チョキ")
37
+ @stand.reset
38
+ assert_equal([], @stand.history)
29
39
  end
30
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Boy2Man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zakuni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-07 00:00:00.000000000 Z
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.0.2
137
+ rubygems_version: 2.0.3
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Rock Paper Scissors