roshambo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/bin/roshambo +5 -0
- data/lib/roshambo/game.rb +8 -4
- data/roshambo.gemspec +1 -1
- data/spec/roshambo_spec.rb +6 -0
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/bin/roshambo
ADDED
data/lib/roshambo/game.rb
CHANGED
@@ -4,6 +4,9 @@ class Roshambo::Game
|
|
4
4
|
|
5
5
|
def initialize(players)
|
6
6
|
@players = players
|
7
|
+
|
8
|
+
# NOTE: The wins and loses are arrays, so the Lizard/Spock extension is obvious here.
|
9
|
+
# - Danny
|
7
10
|
@moves = {
|
8
11
|
rock: {
|
9
12
|
wins: [:scissors],
|
@@ -27,12 +30,11 @@ class Roshambo::Game
|
|
27
30
|
def run_game
|
28
31
|
winner = false
|
29
32
|
@players.each do |player|
|
33
|
+
player.move = random_move
|
34
|
+
|
30
35
|
if !winner
|
31
|
-
player.move = random_move
|
32
36
|
winner = player
|
33
|
-
else
|
34
|
-
player.move = random_move
|
35
|
-
|
37
|
+
else
|
36
38
|
if @moves[player.move][:wins].include?(winner.move)
|
37
39
|
winner = player
|
38
40
|
end
|
@@ -43,6 +45,8 @@ class Roshambo::Game
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def random_move
|
48
|
+
# NOTE: Don't forget to add Lizard and Spock if you are doing the extension.
|
49
|
+
# - Danny
|
46
50
|
[:rock, :paper, :scissors].sort_by{rand}.first
|
47
51
|
end
|
48
52
|
|
data/roshambo.gemspec
CHANGED
data/spec/roshambo_spec.rb
CHANGED
@@ -37,6 +37,12 @@ describe Roshambo do
|
|
37
37
|
it 'should have a winner' do
|
38
38
|
@roshambo = Roshambo.new(1)
|
39
39
|
@roshambo.winner.name.should_not be_empty
|
40
|
+
|
41
|
+
@roshambo = Roshambo.new(2)
|
42
|
+
@roshambo.winner.name.should_not be_empty
|
43
|
+
|
44
|
+
@roshambo = Roshambo.new(3, ['Kermit', 'Animal'])
|
45
|
+
@roshambo.winner.name.should_not be_empty
|
40
46
|
end
|
41
47
|
|
42
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roshambo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,13 +14,15 @@ dependencies: []
|
|
14
14
|
description: ''
|
15
15
|
email:
|
16
16
|
- bunny.rabbit@igotish.com
|
17
|
-
executables:
|
17
|
+
executables:
|
18
|
+
- roshambo
|
18
19
|
extensions: []
|
19
20
|
extra_rdoc_files: []
|
20
21
|
files:
|
21
22
|
- Gemfile
|
22
23
|
- Gemfile.lock
|
23
24
|
- README.md
|
25
|
+
- bin/roshambo
|
24
26
|
- lib/roshambo.rb
|
25
27
|
- lib/roshambo/game.rb
|
26
28
|
- lib/roshambo/player.rb
|