rubypaperscissors 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7feb629d11b066ef72e917f3697cb5474c32d1b
4
+ data.tar.gz: a330150619d91d6bdd6a7b607e4eb0bc99455615
5
+ SHA512:
6
+ metadata.gz: 864e72fa53b3280b1eae67dc2002684efef98cefd583f506961c7e7252f711b3a3a6a846ef6ea56abeae036c5750ce120ddff323db86241ff012a0dd05c9ccb2
7
+ data.tar.gz: dcada840b14d1fe41c145c59113ec5ff46bd9fea3fbc52ab1582366e5e1da18641557e08544a08a88489a3178cb959f21bec892c8e6c89b4214bb72da76da01f
@@ -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 rubypaperscissors.gemspec
4
+ gemspec
@@ -0,0 +1,38 @@
1
+ # Rubypaperscissors
2
+
3
+
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubypaperscissors'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rubypaperscissors
20
+
21
+ ## Usage
22
+
23
+ The game takes two players, can be human or computer. To start type:
24
+ ```ruby
25
+ Game.new(Player.new(human: true), Player.new).play
26
+ ```
27
+ Player defaults to computer so you must pass in human = true.
28
+
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubypaperscissors.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubypaperscissors"
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
@@ -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,73 @@
1
+ require "rubypaperscissors/version"
2
+
3
+ module Rubypaperscissors
4
+ class Player
5
+
6
+ CHOICES = ["r", "p", "s"]
7
+
8
+ def initialize(human=false)
9
+ @human = human
10
+ end
11
+
12
+ # players make moves
13
+ def choice
14
+ if @human
15
+ puts "Enter 'r', 'p', or 's' to make your choice:"
16
+ input = gets.chomp.downcase
17
+ else
18
+ input = CHOICES.sample
19
+ end
20
+ input
21
+ end
22
+
23
+ def is_valid?(input)
24
+ CHOICES.include?(input)
25
+ end
26
+ end
27
+
28
+ # game class
29
+ class Game
30
+ COMPARISONS = {"r" => "s", "s" => "p", "p" => "r"}
31
+
32
+ def initialize(player1, player2)
33
+ @winner = nil
34
+ @player1 = player1
35
+ @player2 = player2
36
+ end
37
+
38
+ # player interactions
39
+ def play
40
+ while !@winner
41
+ # get player choices
42
+ human_input = @player1.choice
43
+ computer_input = @player2.choice
44
+
45
+ # check for winner
46
+ @winner = check_winner(human_input, computer_input)
47
+
48
+ # render
49
+ render(human_input, computer_input)
50
+ end
51
+ end
52
+
53
+
54
+ def check_winner(human_input, computer_input)
55
+ puts "human says: #{human_input}"
56
+ puts "computer says: #{computer_input}"
57
+ return "human" if COMPARISONS[human_input] == computer_input
58
+ return "computer" if COMPARISONS[computer_input] == human_input
59
+ nil
60
+ end
61
+
62
+ def render(human_input, computer_input)
63
+ puts "You chose #{human_input}."
64
+ puts "The computer chose #{computer_input}."
65
+ if @winner
66
+ puts "The winner is #{@winner}."
67
+ else
68
+ puts "No winner yet!"
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Rubypaperscissors
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'rubypaperscissors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubypaperscissors"
8
+ spec.version = Rubypaperscissors::VERSION
9
+ spec.authors = ["Jonathan Popenuck", "Alexa Anderson"]
10
+ spec.email = ["john.popenuck@gmail.com", "alexa.anderson@outlook.com"]
11
+
12
+ spec.summary = %q{Ruby driven Rock Paper Scissors game.}
13
+ spec.description = %q{Ruby driven Rock Paper Scissors game.}
14
+ spec.homepage = "https://github.com/popenuj/rubypaperscissors"
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,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubypaperscissors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Popenuck
8
+ - Alexa Anderson
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.13'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description: Ruby driven Rock Paper Scissors game.
43
+ email:
44
+ - john.popenuck@gmail.com
45
+ - alexa.anderson@outlook.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/rubypaperscissors.rb
57
+ - lib/rubypaperscissors/version.rb
58
+ - rubypaperscissors.gemspec
59
+ homepage: https://github.com/popenuj/rubypaperscissors
60
+ licenses: []
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.7
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Ruby driven Rock Paper Scissors game.
83
+ test_files: []