rps_ing 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rps_ing +7 -0
- data/lib/rps_ing.rb +11 -0
- data/lib/rps_ing/computer.rb +9 -0
- data/lib/rps_ing/display.rb +33 -0
- data/lib/rps_ing/game.rb +58 -0
- data/lib/rps_ing/human.rb +17 -0
- data/lib/rps_ing/player.rb +11 -0
- data/lib/rps_ing/version.rb +3 -0
- data/rps_ing.gemspec +31 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4501369d340cd1e69a49d02d05b445db7ed976e
|
4
|
+
data.tar.gz: 11a06a12c517921bb5ce6cdaab783e228bcf7621
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d279c7db8943ad87589ab713a9aef499d122dc092d7efb4b3f5c8a068a62e0f13f7c0e58b08dce9ce98bc5260c4ee8cad2fec82c5cf2c860f95bf7d8ae91e83
|
7
|
+
data.tar.gz: 09ee677242aef2915240fa67a1a39ca318a5d0f5b24c0a2a55cf6f630240e8b62df1d9235c14eed10609f3f451062bffa3a7e0793d9ced0e1ba708ec4b0e279d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# RpsIng
|
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/rps_ing`. 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 'rps_ing'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rps_ing
|
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]/rps_ing.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rps_ing"
|
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
data/exe/rps_ing
ADDED
data/lib/rps_ing.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module RpsIng
|
2
|
+
|
3
|
+
module Display
|
4
|
+
|
5
|
+
def intro
|
6
|
+
puts "Welcome to Rock, Paper, Scissors"
|
7
|
+
end
|
8
|
+
|
9
|
+
def choice_message
|
10
|
+
puts "Please make your choice"
|
11
|
+
end
|
12
|
+
|
13
|
+
def win_message(comp_pick)
|
14
|
+
puts "You win!"
|
15
|
+
puts "the computer chose #{comp_pick}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def lose_message(comp_pick)
|
19
|
+
puts "Sorry, you lose."
|
20
|
+
puts "the computer chose #{comp_pick}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def tie_message(comp_pick)
|
24
|
+
puts "It's a draw"
|
25
|
+
puts "the computer chose #{comp_pick}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def quitting_msg
|
29
|
+
puts "Want to quit?"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/rps_ing/game.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module RpsIng
|
2
|
+
|
3
|
+
class Game
|
4
|
+
include Display
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@player = Human.new
|
8
|
+
@pick_arr = %w[r p s]
|
9
|
+
@computer = Computer.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def play
|
13
|
+
intro
|
14
|
+
loop do
|
15
|
+
@player.get_input
|
16
|
+
victory?
|
17
|
+
break if quitting?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def victory?
|
22
|
+
comp_pick = @computer.get_input
|
23
|
+
# player_pick = @player.get_input
|
24
|
+
win?(comp_pick) || lose?(comp_pick) || tie?(comp_pick)
|
25
|
+
end
|
26
|
+
|
27
|
+
def index_finder(player)
|
28
|
+
@pick_arr.find_index(player.player_input)
|
29
|
+
end
|
30
|
+
|
31
|
+
def win?(comp_pick)
|
32
|
+
if comp_pick == @pick_arr[(index_finder(@player) - 1)]
|
33
|
+
win_message(comp_pick)
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def lose?(comp_pick)
|
40
|
+
if comp_pick == @pick_arr[(index_finder(@player) + 1) % 3]
|
41
|
+
lose_message(comp_pick)
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def tie?(comp_pick)
|
48
|
+
tie_message(comp_pick)
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def quitting?
|
53
|
+
quitting_msg
|
54
|
+
input = gets.strip.downcase
|
55
|
+
input == 'quit' || input == 'q'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RpsIng
|
2
|
+
class Human < Player
|
3
|
+
attr_reader :player_input
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@player_input = ""
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_input
|
10
|
+
loop do
|
11
|
+
choice_message
|
12
|
+
@player_input = gets.strip.downcase
|
13
|
+
break if valid_input?(@player_input)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/rps_ing.gemspec
ADDED
@@ -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 'rps_ing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rps_ing"
|
8
|
+
spec.version = RpsIng::VERSION
|
9
|
+
spec.authors = ["Graham Turner"]
|
10
|
+
spec.email = ["turnertgraham@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rock paper scissors game gem}
|
13
|
+
spec.description = %q{blah}
|
14
|
+
spec.homepage = "https://www.google.com"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem 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 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.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rps_ing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Graham Turner
|
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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: blah
|
42
|
+
email:
|
43
|
+
- turnertgraham@gmail.com
|
44
|
+
executables:
|
45
|
+
- rps_ing
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- exe/rps_ing
|
56
|
+
- lib/rps_ing.rb
|
57
|
+
- lib/rps_ing/computer.rb
|
58
|
+
- lib/rps_ing/display.rb
|
59
|
+
- lib/rps_ing/game.rb
|
60
|
+
- lib/rps_ing/human.rb
|
61
|
+
- lib/rps_ing/player.rb
|
62
|
+
- lib/rps_ing/version.rb
|
63
|
+
- rps_ing.gemspec
|
64
|
+
homepage: https://www.google.com
|
65
|
+
licenses: []
|
66
|
+
metadata:
|
67
|
+
allowed_push_host: https://rubygems.org
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.8
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Rock paper scissors game gem
|
88
|
+
test_files: []
|