roshambo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ roshambo (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.11.0)
11
+ rspec-core (~> 2.11.0)
12
+ rspec-expectations (~> 2.11.0)
13
+ rspec-mocks (~> 2.11.0)
14
+ rspec-core (2.11.1)
15
+ rspec-expectations (2.11.2)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.11.1)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ roshambo!
24
+ rspec
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
1
  roshambo
2
2
  ========
3
3
 
4
- A little gem to play Rock Paper Scissors with
4
+ A little gem to play Rock Paper Scissors with.
5
+
6
+ FEATURES:
7
+
8
+ 1. Can be used as a console command.
9
+ 2. Can be used as a plugin to add a user interface in HTML5 or Javascript.
10
+ 3. Takes the number of players, and a list of names. Unnamed players will be A.I. players.
@@ -0,0 +1,49 @@
1
+ class Roshambo::Game
2
+
3
+ attr_reader :players, :winner
4
+
5
+ def initialize(players)
6
+ @players = players
7
+ @moves = {
8
+ rock: {
9
+ wins: [:scissors],
10
+ lose: [:paper]
11
+ },
12
+ paper: {
13
+ wins: [:rock],
14
+ lose: [:scissors]
15
+ },
16
+ scissors: {
17
+ wins: [:paper],
18
+ lose: [:rock]
19
+ }
20
+ }
21
+
22
+ @winner = run_game
23
+ end
24
+
25
+ private
26
+
27
+ def run_game
28
+ winner = false
29
+ @players.each do |player|
30
+ if !winner
31
+ player.move = random_move
32
+ winner = player
33
+ else
34
+ player.move = random_move
35
+
36
+ if @moves[player.move][:wins].include?(winner.move)
37
+ winner = player
38
+ end
39
+ end
40
+ end
41
+
42
+ return winner
43
+ end
44
+
45
+ def random_move
46
+ [:rock, :paper, :scissors].sort_by{rand}.first
47
+ end
48
+
49
+ end
@@ -0,0 +1,17 @@
1
+ class Roshambo::Player
2
+
3
+ attr_reader :name, :type
4
+ attr_accessor :move
5
+
6
+ def initialize(name='')
7
+ @type = name.empty? ? :computer : :human
8
+ @name = @type == :computer ? random_name : name
9
+ end
10
+
11
+ private
12
+
13
+ def random_name
14
+ ['Marvin', 'Data', 'R2D2', 'C3PO', 'Tik-Tok', 'Zat', 'Gort'].sort_by{rand}.first
15
+ end
16
+
17
+ end
data/lib/roshambo.rb ADDED
@@ -0,0 +1,34 @@
1
+ class Roshambo
2
+
3
+ attr_reader :player_count, :players
4
+ attr_accessor :winner
5
+
6
+ def initialize(player_count=2, player_names=[])
7
+ @player_count = player_count
8
+
9
+ create_players(player_names)
10
+ run_game
11
+ end
12
+
13
+ private
14
+
15
+ def create_players(player_names)
16
+ @players = []
17
+
18
+ player_names.each do |player_name|
19
+ @players << Roshambo::Player.new(player_name)
20
+ end
21
+
22
+ while @player_count > @players.size
23
+ @players << Roshambo::Player.new
24
+ end
25
+ end
26
+
27
+ def run_game
28
+ @winner = Roshambo::Game.new(@players).winner
29
+ end
30
+
31
+ end
32
+
33
+ require 'roshambo/player'
34
+ require 'roshambo/game'
data/roshambo.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'roshambo'
6
+ s.version = '0.0.2'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Daniel Owen van Dommelen']
9
+ s.email = ['bunny.rabbit@igotish.com']
10
+ s.homepage = 'http://rubygems.org/gems/roshambo'
11
+ s.summary = ''
12
+ s.description = ''
13
+
14
+ s.rubyforge_project = "roshambo"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
+ s.require_paths = ["lib"]
20
+ end
data/spec/game_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roshambo::Game do
4
+
5
+ it 'should have the players' do
6
+ @game = Roshambo::Game.new([
7
+ Roshambo::Player.new
8
+ ])
9
+
10
+ @game.players.should_not be_empty
11
+ end
12
+
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roshambo::Player do
4
+
5
+ it 'should have a type' do
6
+ @player = Roshambo::Player.new('Animal')
7
+ @player.type.should_not be_empty
8
+ end
9
+
10
+ it 'should be a computer player' do
11
+ @player = Roshambo::Player.new
12
+ @player.type.should == :computer
13
+ end
14
+
15
+ it 'should be a human player' do
16
+ @player = Roshambo::Player.new('Kermit')
17
+ @player.type.should == :human
18
+ end
19
+
20
+ it 'should have a name' do
21
+ @player = Roshambo::Player.new('Animal')
22
+ @player.name.should == 'Animal'
23
+ end
24
+
25
+ it 'should have a random name' do
26
+ @player1 = Roshambo::Player.new
27
+ @player2 = Roshambo::Player.new
28
+
29
+ @player1.name.should_not == @player2.name
30
+ end
31
+
32
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roshambo do
4
+
5
+ it 'should initialize' do
6
+ @roshambo = Roshambo.new
7
+ end
8
+
9
+ it 'should allow setting the player count' do
10
+ @roshambo = Roshambo.new(2)
11
+ end
12
+
13
+ it 'should have a default player count' do
14
+ @roshambo = Roshambo.new
15
+ @roshambo.player_count.should == 2
16
+ end
17
+
18
+ it 'should allow setting the players list' do
19
+ @roshambo = Roshambo.new(2, ['Kermit', 'Animal'])
20
+ end
21
+
22
+ it 'should have a list of players' do
23
+ @roshambo = Roshambo.new(2, ['Kermit', 'Animal'])
24
+ @roshambo.players.should_not be_empty
25
+ end
26
+
27
+ it 'should make player objects' do
28
+ @roshambo = Roshambo.new(2, ['Kermit', 'Animal'])
29
+ @roshambo.players.first.class.should == Roshambo::Player
30
+ end
31
+
32
+ it 'should add a computer player' do
33
+ @roshambo = Roshambo.new(2, ['Kermit'])
34
+ @roshambo.players.size.should == 2
35
+ end
36
+
37
+ it 'should have a winner' do
38
+ @roshambo = Roshambo.new(1)
39
+ @roshambo.winner.name.should_not be_empty
40
+ end
41
+
42
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'roshambo'
5
+ require 'roshambo/player'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ 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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,17 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - Gemfile
22
+ - Gemfile.lock
21
23
  - README.md
24
+ - lib/roshambo.rb
25
+ - lib/roshambo/game.rb
26
+ - lib/roshambo/player.rb
27
+ - roshambo.gemspec
28
+ - spec/game_spec.rb
29
+ - spec/player_spec.rb
30
+ - spec/roshambo_spec.rb
31
+ - spec/spec_helper.rb
22
32
  homepage: http://rubygems.org/gems/roshambo
23
33
  licenses: []
24
34
  post_install_message:
@@ -43,4 +53,8 @@ rubygems_version: 1.8.10
43
53
  signing_key:
44
54
  specification_version: 3
45
55
  summary: ''
46
- test_files: []
56
+ test_files:
57
+ - spec/game_spec.rb
58
+ - spec/player_spec.rb
59
+ - spec/roshambo_spec.rb
60
+ - spec/spec_helper.rb