rpsshoot 1.0.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: e9a6469771c67653a23185fe8513055b032473d4
4
+ data.tar.gz: 99b132b86607ca2585c0d29ace31336e1e0801c9
5
+ SHA512:
6
+ metadata.gz: 6f6697fb41c96cfee3862f5b23edaa61606b5317fc99c095b041982f2aacaeee23db3bdcd82a3dc02cae5b54a2e4aa0140af76027d1771a586a96eb269029b44
7
+ data.tar.gz: 72b53b697d07fcf49859cced51fcef97bbcbef1e42bb5038666428e789e76c315fe38a304047ffc3448294e1e4453d9a6de108ee973d35b78e8f593226b334e2
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/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mariah.acacia@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpsshoot.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Rpsshoot
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/rpsshoot`. 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 'rpsshoot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rpsshoot
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
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]/rpsshoot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
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 "rpsshoot"
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
data/lib/rpsshoot.rb ADDED
@@ -0,0 +1,155 @@
1
+ require "rpsshoot/version"
2
+ require "io/console"
3
+ require "rpsshoot/player"
4
+
5
+ module Rpsshoot
6
+
7
+ # Controls main game function
8
+ class RockPaperScissors
9
+
10
+ def initialize
11
+ @player1 = Player.new(1, "Player 1")
12
+ @player2 = Computer.new(2, "Computer")
13
+ @score = []
14
+ @instructions = instructions
15
+ end
16
+
17
+ # Starts game loop
18
+ def play
19
+ round = 0
20
+ 5.times do
21
+ round += 1
22
+ p1_selection = @player1.shoot
23
+ p2_selection = @player2.shoot
24
+ results(round, p1_selection, p2_selection)
25
+ @score << round_winner(p1_selection, p2_selection)
26
+ end
27
+ determine_winner(@score)
28
+ play_again? ? @score.clear && play : exit
29
+ end
30
+
31
+ # Instructions on how to play
32
+ def instructions
33
+ puts "Welcome to Rock, Paper, Scissors"
34
+ puts "This is a two player game where:"
35
+ puts "* Rock smashes Scissors"
36
+ puts "* Scissors cut Paper"
37
+ puts "* Paper covers Rock"
38
+ puts "* Best out of five wins"
39
+ pick_players
40
+ end
41
+
42
+ # Pick the number of players you would like to play with
43
+ def pick_players
44
+ puts "Would you like to play with 1 or 2 players?"
45
+ puts "Choose 1 player to play against the computer"
46
+ number_of_players = gets.chomp.to_i
47
+ if number_of_players == 1
48
+ play
49
+ elsif number_of_players == 2
50
+ @player2 = Player.new(2, "Player 2")
51
+ play
52
+ else
53
+ puts "That was not a valid selection, please try again..."
54
+ pick_players
55
+ end
56
+ end
57
+
58
+ # Determine the winner of each round
59
+ def round_winner(rps1, rps2)
60
+ case rps1
61
+ when "rock"
62
+ rock(rps2)
63
+ when "scissors"
64
+ scissors(rps2)
65
+ when "paper"
66
+ paper(rps2)
67
+ end
68
+ end
69
+
70
+ # Display results after each round
71
+ def results(round, first, second)
72
+ puts ">> Round #{round} results:"
73
+ puts ">> #{@player1.name}: #{first}"
74
+ puts ">> #{@player2.name}: #{second}"
75
+ end
76
+
77
+ # Rock beats Scissors, Scissors beats Paper, Paper beats Rock
78
+ def rock(selection)
79
+ if selection == "rock"
80
+ puts ">> It's a tie!"
81
+ 0
82
+ elsif selection == "scissors"
83
+ puts ">> #{@player1.name} takes this round!"
84
+ @player1.symbol
85
+ elsif selection == "paper"
86
+ puts ">> #{@player2.name} takes this round!"
87
+ @player2.symbol
88
+ end
89
+ end
90
+
91
+ def scissors(selection)
92
+ if selection == "rock"
93
+ puts ">> #{@player2.name} takes this round!"
94
+ @player2.symbol
95
+ elsif selection == "scissors"
96
+ 0
97
+ elsif selection == "paper"
98
+ puts ">> #{@player1.name} takes this round!"
99
+ @player1.symbol
100
+ end
101
+ end
102
+
103
+ def paper(selection)
104
+ if selection == "rock"
105
+ puts ">> #{@player1.name} takes this round!"
106
+ @player1.symbol
107
+ elsif selection == "scissors"
108
+ puts ">> #{@player2.name} takes this round!"
109
+ @player2.symbol
110
+ elsif selection == "paper"
111
+ 0
112
+ end
113
+ end
114
+
115
+ # Determines who wins after five rounds
116
+ def determine_winner(array)
117
+ p1 = array.count(@player1.symbol)
118
+ p2 = array.count(@player2.symbol)
119
+ if p1 > p2
120
+ puts "Congrats! #{@player1.name} wins!"
121
+ score
122
+ elsif p1 < p2
123
+ puts "Congrats! #{@player2.name} wins!"
124
+ score
125
+ else
126
+ puts "You both win, it's a tie!"
127
+ score
128
+ end
129
+ end
130
+
131
+ # Displays final score
132
+ def score
133
+ puts ">> #{@player1.name}: #{@score.count(@player1.symbol)} wins"
134
+ puts ">> #{@player2.name}: #{@score.count(@player2.symbol)} wins"
135
+ puts ">> Ties: #{@score.count(0)}"
136
+ end
137
+
138
+ #Once game has finished, asks if they would like to play another round
139
+ def play_again?
140
+ puts "Would you like to play again? y/n?"
141
+ answer = gets.chomp
142
+ case answer
143
+ when "n"
144
+ false
145
+ when "y"
146
+ true
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ end
153
+
154
+ game = Rpsshoot::RockPaperScissors.new
155
+ game.play
@@ -0,0 +1,45 @@
1
+ # Player class manages user interactions
2
+ module Rpsshoot
3
+
4
+ class Player
5
+
6
+ attr_reader :symbol, :name
7
+
8
+ def initialize(symbol, name)
9
+ @symbol = symbol
10
+ @name = name
11
+ end
12
+
13
+ # Each player takes a turn
14
+ def shoot
15
+ options = ["rock", "paper", "scissors"]
16
+ puts "#{@name} please enter rock, paper or scissors: (or 'quit' to exit)"
17
+ selection = STDIN.noecho(&:gets).chomp
18
+ if options.include?(selection)
19
+ selection
20
+ elsif selection.downcase == "quit"
21
+ exit
22
+ else
23
+ puts "I'm sorry, that wasn't a valid selection."
24
+ shoot
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ # Computer class manages AI player in one player mode
31
+ class Computer < Player
32
+
33
+ def initialize(symbol, name)
34
+ super
35
+ end
36
+
37
+ # Computer takes a turn
38
+ def shoot
39
+ options = ["rock", "paper", "scissors"]
40
+ shoot = options.sample
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ module Rpsshoot
2
+ VERSION = "1.0.0"
3
+ end
data/rpsshoot.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 'rpsshoot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rpsshoot"
8
+ spec.version = Rpsshoot::VERSION
9
+ spec.authors = ["Mariah Schneeberger"]
10
+ spec.email = ["mariah.acacia@gmail.com"]
11
+
12
+ spec.summary = %q{Command Line Rock Paper Scissors game}
13
+ spec.description = %q{Command Line Rock Paper Scissors game}
14
+ spec.homepage = "https://github.com/MariahAcacia/rpsshoot.git"
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.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpsshoot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mariah Schneeberger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-18 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: Command Line Rock Paper Scissors game
42
+ email:
43
+ - mariah.acacia@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/rpsshoot.rb
56
+ - lib/rpsshoot/player.rb
57
+ - lib/rpsshoot/version.rb
58
+ - rpsshoot.gemspec
59
+ homepage: https://github.com/MariahAcacia/rpsshoot.git
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.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Command Line Rock Paper Scissors game
83
+ test_files: []