vcs_bk_tdr_rps 0.3.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 605999407f5697972c3fbe0a8ea7ff78c71a4818
4
+ data.tar.gz: 2868922c26373ef24bce84be4771f7e4d404d914
5
+ SHA512:
6
+ metadata.gz: ddcb388b6b5e20ab6df3f1a051fd50f029152c23e93cb23757fe59c7ad26210edca671c62f26fff37054b6fa85c0e0088c2af9877b8620b17802d8006f155cc2
7
+ data.tar.gz: 2f10d36141494e4374a1af9ed178d0ce38be83b777edb3a7436664ece09379278d8847d7d869f233e5381781e8f2d6fb478ba03158c8f63d257fc8c06b3f0c75
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vcs_bk_tdr_rps.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ben Kautt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # VcsBkTdrRps
2
+
3
+ A simple CLI for Rock, Paper, Scissors vs. the computer.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vcs_bk_tdr_rps'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vcs_bk_tdr_rps
20
+
21
+ ## Usage
22
+
23
+ VcsBkTdrRps#create_player(name): create & return a player obj with a given name (String)
24
+
25
+ VcsBkTdrRps#create_game(player): create & return a game obj with a given player obj
26
+
27
+ VcsBkTdrRps::Game#play: runs through the game against the computer
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vcs_bk_tdr_rps"
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(__FILE__)
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
@@ -0,0 +1,60 @@
1
+ require_relative "player"
2
+
3
+ module VcsBkTdrRps
4
+ class Game
5
+ attr_reader :players
6
+
7
+ def initialize(user_player)
8
+ @winner = nil
9
+ @user_player = user_player
10
+ @comp_player = VcsBkTdrRps::Player.new("Computer", true)
11
+ @players = [@user_player, @comp_player]
12
+ end
13
+
14
+ def throw_hands
15
+ @players.each(&:set_hand)
16
+ end
17
+
18
+ def show_hands
19
+ @players.each do |player|
20
+ puts "#{player.name}'s hand was #{player.hand}"
21
+ end
22
+ end
23
+
24
+ def show_winner
25
+ if @winner == 'tie'
26
+ puts 'It was a tie!'
27
+ else
28
+ puts "#{@winner} won!"
29
+ end
30
+ end
31
+
32
+ def find_winner
33
+ compare_hands(@user_player, @comp_player)
34
+ end
35
+
36
+ def play
37
+ throw_hands
38
+ @winner = find_winner
39
+ show_hands
40
+ show_winner
41
+ end
42
+
43
+ private
44
+
45
+ def compare_hands(p1, p2)
46
+ if p1.hand == p2.hand
47
+ 'tie'
48
+ else
49
+ case p1.hand
50
+ when 'rock'
51
+ p2.hand == 'paper' ? p2.name : p1.name
52
+ when 'paper'
53
+ p2.hand == 'scissors' ? p2.name : p1.name
54
+ when 'scissors'
55
+ p2.hand == 'rock' ? p2.name : p1.name
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ module VcsBkTdrRps
2
+ class Player
3
+ CHOICES = %w[rock paper scissors].freeze
4
+ attr_accessor :hand
5
+ attr_reader :name
6
+
7
+ def initialize(name, comp = false)
8
+ @name = name
9
+ @hand = false
10
+ @comp = comp
11
+ end
12
+
13
+ def display_choices
14
+ CHOICES.each_with_index { |choice, i| puts "#{i}: #{choice}" }
15
+ end
16
+
17
+ def set_hand
18
+ @comp ? @hand = CHOICES.sample : @hand = throw_hand
19
+ end
20
+
21
+ private
22
+
23
+ def valid_hand?(hand)
24
+ CHOICES.include? hand.downcase
25
+ end
26
+
27
+ def throw_hand
28
+ hand = 'wrong'
29
+ until valid_hand?(hand)
30
+ puts "Please choose the hand you want to throw..."
31
+ display_choices
32
+ hand = gets.chomp
33
+ end
34
+ hand
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module VcsBkTdrRps
2
+ VERSION = "0.3.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "vcs_bk_tdr_rps/version"
2
+ require_relative "vcs_bk_tdr_rps/player"
3
+ require_relative "vcs_bk_tdr_rps/game"
4
+
5
+ module VcsBkTdrRps
6
+
7
+ def self.create_player(name)
8
+ VcsBkTdrRps::Player.new(name)
9
+ end
10
+
11
+ def self.create_game(player)
12
+ VcsBkTdrRps::Game.new(player)
13
+ end
14
+ end
15
+
16
+
17
+
18
+ # create new interface to game
19
+ # create player w/ name
20
+ # create game w/ player (vs comp)
21
+ # play game
22
+ #
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vcs_bk_tdr_rps/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vcs_bk_tdr_rps"
8
+ spec.version = VcsBkTdrRps::VERSION
9
+ spec.authors = ["Ben Kautt"]
10
+ spec.email = ["bkautt73@gmail.com"]
11
+
12
+ spec.summary = %q{Basic rock, paper, scissors game}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against " \
20
+ "public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.16"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcs_bk_tdr_rps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Kautt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-07 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - bkautt73@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/vcs_bk_tdr_rps.rb
72
+ - lib/vcs_bk_tdr_rps/game.rb
73
+ - lib/vcs_bk_tdr_rps/player.rb
74
+ - lib/vcs_bk_tdr_rps/version.rb
75
+ - vcs_bk_tdr_rps.gemspec
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.12
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Basic rock, paper, scissors game
101
+ test_files: []