rps_game 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90437c49869038269dcc1d9e93d5e1a10767ad13
4
+ data.tar.gz: 31c9afca0e88043fdb8b7d48d51f9175856728c7
5
+ SHA512:
6
+ metadata.gz: 2c7a71e994161483375f5fbcaa6d2693296c2fb0bdec1c9dc86a9ba060740cb94b2029f5f9a9962cfa861c99cc2298111d2a079fc2de48abbdcb4bde7d86b492
7
+ data.tar.gz: 97647825594d0de81502714d03d65f8202e23e93660958491b0103037c8baf8f5da12c2975bde1dca4f662b517bd412ae153dfb44c12513a6cfec4a7622cb8d7
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rps_game.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # RpsGame
2
+
3
+ Test in creating a gem. Rock, paper, scissors 1 or 2 player game
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rps_game'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rps_game
20
+
21
+ ## Usage
22
+
23
+
24
+ To run this create a new Game object
25
+
26
+ RPS::Game.new.play
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andie5/rps_game.
37
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rps_game"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
data/lib/rps_game.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rps_game/version"
2
+ require "rps_game/game"
3
+ require "rps_game/player"
4
+ require "rps_game/computer"
5
+
6
+
7
+ # Includes the
8
+ # module into the global
9
+ # namespace
10
+ include RPSGame
11
+
Binary file
@@ -0,0 +1,8 @@
1
+ module RPSGame
2
+ class Computer
3
+ # Generate a random number to indicate the random item
4
+ def random_move
5
+ 1 + rand(3)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,101 @@
1
+
2
+ # Create a command line Rock-Paper-Scissors game, with 1 or 2 players modes
3
+ # All the actions relevant to the game
4
+ module RPSGame
5
+ class Game
6
+ attr_accessor :no_players, :player1, :player2, :p1_input, :p2_input
7
+
8
+ def initialize
9
+ # initialize the item options as 1,2,3
10
+ @items = {1=>"rock", 2=>"paper", 3=> "scissors"}
11
+ @game_play = true
12
+ end
13
+
14
+ def who_won(player1, player2)
15
+ if (player1 == 1 and player2 == 2)
16
+ result = "Player 2 wins"
17
+ elsif (player1 == 1 and player2 == 3)
18
+ result = "Player 1 wins"
19
+ elsif (player1 == 2 and player2 == 1)
20
+ result = "Player 1 wins"
21
+ elsif (player1 == 2 and player2 == 3)
22
+ result = "Player 2 wins"
23
+ elsif (player1 == 3 and player2 == 1)
24
+ result = "Player 2 wins"
25
+ elsif (player1 == 3 and player2 == 2)
26
+ result = "Player 1 wins"
27
+ else
28
+ result = "That was a draw"
29
+ end
30
+ result
31
+ end
32
+
33
+ def select_move
34
+ # binding.pry
35
+ puts "Player 1 enter move >"
36
+ @p1_input = gets.chomp.to_i
37
+
38
+ puts "Player 1 chose #{@p1_input} - #{@items[@p1_input]}"
39
+ puts "============================================================"
40
+
41
+ if(@no_players == 1)
42
+ @p2_input = @player2.random_move
43
+ puts "Computer chose #{@p2_input} - #{@items[@p2_input]}"
44
+ else
45
+ puts "Player 2 enter move >"
46
+ @p2_input = gets.chomp.to_i
47
+ puts "Player 2 chose #{@p2_input} - #{@items[@p2_input]}"
48
+ end
49
+
50
+ puts "============================================================"
51
+
52
+ player_won = who_won(@p1_input, @p2_input)
53
+ puts "#{player_won}"
54
+ puts "============================================================"
55
+ puts "Do you want to play again?"
56
+ puts "Y for yes"
57
+ puts "N for no"
58
+
59
+ user_input = gets.chomp
60
+ @game_play = @player1.play_again?(user_input)
61
+
62
+ if @game_play
63
+ select_move
64
+ else
65
+ puts "Game over. Thanks for playing!"
66
+ end
67
+ end
68
+
69
+ def play
70
+ initial_instructions
71
+
72
+ @no_players = gets.chomp.to_i
73
+
74
+ if(@no_players == 1)
75
+ @player1 = Player.new
76
+ @player2 = Computer.new
77
+ elsif(@no_players == 2)
78
+ @player1 = Player.new
79
+ @player2 = Player.new
80
+ else
81
+ puts "You didn't enter 1 or 2 for the number of players"
82
+ end
83
+
84
+ puts "You have chosen #{@no_players} player(s)"
85
+ puts "Enter 1 for Rock"
86
+ puts "Enter 2 for Paper"
87
+ puts "Enter 3 for Scissors"
88
+ puts "============================================================"
89
+
90
+ # Next move
91
+ select_move
92
+ end
93
+
94
+ def initial_instructions
95
+ puts "Hello, Let's play rock, paper, scissors!"
96
+ puts "============================================================"
97
+ puts "Instructions:"
98
+ puts "Enter the number of players 1 or 2, if you enter 1 you will play aginst the master computer"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,10 @@
1
+ module RPSGame
2
+ class Player
3
+ # store the users answer
4
+ attr_accessor :status
5
+
6
+ def play_again?(input)
7
+ @status = (input.strip.downcase == "n") ? false : true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RpsGame
2
+ VERSION = "0.0.2"
3
+ end
data/rps_game.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rps_game/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rps_game"
8
+ spec.version = RpsGame::VERSION
9
+ spec.authors = ["andie5"]
10
+ spec.email = ["andieasa@googlemail.com"]
11
+
12
+ spec.summary = %q{Rock, paper, scissors game}
13
+ spec.description = %q{Rock, paper, scissors command line game for 1 or 2 players}
14
+ spec.homepage = "https://github.com/andie5/rps_game"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rps_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - andie5
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Rock, paper, scissors command line game for 1 or 2 players
42
+ email:
43
+ - andieasa@googlemail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".DS_Store"
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/.DS_Store
56
+ - lib/rps_game.rb
57
+ - lib/rps_game/.DS_Store
58
+ - lib/rps_game/computer.rb
59
+ - lib/rps_game/game.rb
60
+ - lib/rps_game/player.rb
61
+ - lib/rps_game/version.rb
62
+ - rps_game.gemspec
63
+ homepage: https://github.com/andie5/rps_game
64
+ licenses: []
65
+ metadata:
66
+ allowed_push_host: https://rubygems.org
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Rock, paper, scissors game
87
+ test_files: []