alexvishalrps 0.1.2

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: 398f428dbbb507febecde6a1f61d80603c1ffed8
4
+ data.tar.gz: a4972692b0d3cb70cfc0ad41e1bb8972f50250ad
5
+ SHA512:
6
+ metadata.gz: 502fb56a8eff495d37e6bfd2c9034d09c8b3c21cf17148a1cb8688eee076f7919c305e7f303b6f4de2fb8bd86147ce962e78e284adad492d065728ac386b6a36
7
+ data.tar.gz: 44c0e7366c98416e20806b5c3a8d4a760909e8dc7c08f527bbe5e79de043d03d43b87edf1f35f6310b7ecc1146082c1a17b1d07232fa2a01338251a18da6f1d1
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 alexvishalrps.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Alexvishalrps
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/alexvishalrps`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'alexvishalrps'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install alexvishalrps
22
+
23
+ ## Usage
24
+
25
+ TODO: Just write `alexvishalrps` on your command line and go from there!
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alexvishalrps.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alexvishalrps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alexvishalrps"
8
+ spec.version = AlexVishalRPS::VERSION
9
+ spec.authors = ["Alex Lach"]
10
+ spec.email = ["alexglach@gmail.com"]
11
+
12
+ spec.summary = %q{"This is a simple rock-paper-scissors game"}
13
+ spec.description = %q{"Play against another human or the computer. Choose rock paper or scissors."}
14
+ spec.homepage = "https://github.com/alexglach/alexvishalrps"
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://www.rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alexvishalrps"
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/exe/alexvishalrps ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'alexvishalrps'
4
+
5
+ AlexVishalRPS.play
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,10 @@
1
+ require "alexvishalrps/version"
2
+ require "alexvishalrps/player"
3
+ require "alexvishalrps/comp_player"
4
+ require "alexvishalrps/game"
5
+
6
+ module AlexVishalRPS
7
+ def self.play
8
+ Game.new.play
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module AlexVishalRPS
2
+ class CompPlayer < Player
3
+
4
+ def initialize
5
+ super("computer")
6
+ end
7
+
8
+ def gather_choice
9
+ choices = [:rock, :paper, :scissors]
10
+ throw(choices[rand(3)])
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ module AlexVishalRPS
2
+ class Game
3
+
4
+ def initialize
5
+ end
6
+
7
+ def play
8
+ assign_players
9
+ quit = false
10
+
11
+ until quit
12
+ @player_one.gather_choice
13
+ @player_two.gather_choice
14
+ print_choices
15
+ determine_winner
16
+
17
+ puts "Play again?"
18
+ choice = gets.chomp
19
+
20
+ if choice.downcase != "yes"
21
+ quit = true
22
+ end
23
+ end
24
+ end
25
+
26
+ def assign_players
27
+ num_of_human_players = nil
28
+ until num_of_human_players
29
+ puts "How many human players?"
30
+ num_of_human_players = gets.chomp.to_i
31
+ if num_of_human_players == 1
32
+ @player_one = Player.new(Player.get_name)
33
+ @player_two = CompPlayer.new
34
+ elsif num_of_human_players == 2
35
+ @player_one = Player.new(Player.get_name)
36
+ @player_two = Player.new(Player.get_name)
37
+ end
38
+ end
39
+ end
40
+
41
+ def determine_winner
42
+ winners = {:rock => :scissors, :paper => :rock, :scissors => :paper}
43
+ if winners[@player_one.status] == @player_two.status
44
+ puts "#{@player_one.name} wins!"
45
+ elsif winners[@player_two.status] == @player_one.status
46
+ puts "#{@player_two.name} wins!"
47
+ else
48
+ puts "It was a tie!"
49
+ end
50
+ end
51
+
52
+ def print_choices
53
+ puts "#{@player_one.name} chose: #{@player_one.status.to_s}."
54
+ puts "#{@player_two.name} chose: #{@player_two.status.to_s}."
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ module AlexVishalRPS
2
+ class Player
3
+ attr_reader :status, :name
4
+ def initialize(name = "mister_no_name")
5
+ @name = name
6
+ @status = nil
7
+ end
8
+
9
+ def throw(choice)
10
+ @status = choice
11
+ end
12
+
13
+ def self.get_name
14
+ puts "What's your name?"
15
+ gets.chomp
16
+ end
17
+
18
+ def gather_choice
19
+ puts "#{@name}, enter your choice"
20
+ choice = gets.strip
21
+ case choice
22
+ when "rock"
23
+ throw(:rock)
24
+ when "paper"
25
+ throw(:paper)
26
+ when "scissors"
27
+ throw(:scissors)
28
+ else
29
+ puts "Incorrect input"
30
+ gather_choice
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module AlexVishalRPS
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,11 @@
1
+ class CompPlayer < Player
2
+
3
+ def initialize
4
+ super("computer")
5
+ end
6
+
7
+ def gather_choice
8
+ choices = [:rock, :paper, :scissors]
9
+ throw(choices[rand(3)])
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexvishalrps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Alex Lach
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: '"Play against another human or the computer. Choose rock paper or scissors."'
42
+ email:
43
+ - alexglach@gmail.com
44
+ executables:
45
+ - alexvishalrps
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".DS_Store"
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - alexvishalrps.gemspec
55
+ - bin/console
56
+ - bin/setup
57
+ - exe/alexvishalrps
58
+ - lib/.DS_Store
59
+ - lib/alexvishalrps.rb
60
+ - lib/alexvishalrps/comp_player.rb
61
+ - lib/alexvishalrps/game.rb
62
+ - lib/alexvishalrps/player.rb
63
+ - lib/alexvishalrps/version.rb
64
+ - lib/comp_player.rb
65
+ homepage: https://github.com/alexglach/alexvishalrps
66
+ licenses: []
67
+ metadata:
68
+ allowed_push_host: https://www.rubygems.org
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: '"This is a simple rock-paper-scissors game"'
89
+ test_files: []