sc_rock_paper_scissors 0.0.1
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/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sc_rock_paper_scissors/computer.rb +9 -0
- data/lib/sc_rock_paper_scissors/human.rb +39 -0
- data/lib/sc_rock_paper_scissors/player.rb +5 -0
- data/lib/sc_rock_paper_scissors/version.rb +3 -0
- data/lib/sc_rock_paper_scissors.rb +143 -0
- data/sc_rock_paper_scissors.gemspec +32 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b57c4d40a677c287612cc4b9934b0269eea70f16
|
4
|
+
data.tar.gz: cf872e901d9a1af7b0b02204963862ada60c655b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 573e7286429621d16f341f67e8f1d89702e4e2003cc20dcd1d13710162d1fa25b5fb90e527f29421c80b392e17ee0b73c319caac8d0ab65d253bc7bdaf9d79d5
|
7
|
+
data.tar.gz: f5934b90f3f824b69b6533677ce4fc7a65c52fc19d1439770ab1041932c13f6e6d6ec04ed5edaaa463357f09f0becb40f36e74af4815e9d77a684cff7cd083e4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Steven Chang
|
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,41 @@
|
|
1
|
+
# ScRockPaperScissors
|
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/sc_rock_paper_scissors`. 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 'sc_rock_paper_scissors'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sc_rock_paper_scissors
|
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. Then, run `rake false` to run the tests. 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]/sc_rock_paper_scissors.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sc_rock_paper_scissors"
|
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,39 @@
|
|
1
|
+
module ScRockPaperScissors
|
2
|
+
class Human < Player
|
3
|
+
|
4
|
+
def ask_for_response
|
5
|
+
print "Type r, p or s then press enter (or q to quit): "
|
6
|
+
response = gets.chomp.downcase
|
7
|
+
until response_is_valid?(response)
|
8
|
+
puts "Invalid decision!"
|
9
|
+
print "Type 'r' for rock, 'p' for paper or 's' for scissors then enter (or q to quit): "
|
10
|
+
response = gets.chomp.downcase
|
11
|
+
end
|
12
|
+
response
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_mode
|
16
|
+
print "Type 1 to play against computer or 2 to play against another person (or q to quit) and then press enter: "
|
17
|
+
response = gets.chomp
|
18
|
+
until mode_is_valid?(response)
|
19
|
+
puts "Invalid decision!"
|
20
|
+
print "Type 1 to play against computer or 2 to play against another person (or q to quit) and then press enter: "
|
21
|
+
response = gets.chomp
|
22
|
+
end
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def mode_is_valid?(response)
|
29
|
+
exit if response == 'q'
|
30
|
+
['1', '2'].include? response
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_is_valid?(response)
|
34
|
+
exit if response == 'q'
|
35
|
+
@@valid_answers.include? response
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require "sc_rock_paper_scissors/version"
|
2
|
+
require "sc_rock_paper_scissors/player"
|
3
|
+
require "sc_rock_paper_scissors/human"
|
4
|
+
require "sc_rock_paper_scissors/computer"
|
5
|
+
|
6
|
+
module ScRockPaperScissors
|
7
|
+
class RockPaperScissors
|
8
|
+
GameName = "Rock! Paper! Scissors!"
|
9
|
+
Underline = "----------------------"
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@human = Human.new
|
13
|
+
@human2 = Human.new
|
14
|
+
@computer = Computer.new
|
15
|
+
@mode = '1'
|
16
|
+
@wins = 0
|
17
|
+
@losses = 0
|
18
|
+
@draws = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_game
|
22
|
+
puts GameName
|
23
|
+
puts Underline
|
24
|
+
puts "by Steven Chang"
|
25
|
+
puts ""
|
26
|
+
puts ""
|
27
|
+
puts "The Rules:"
|
28
|
+
puts Underline
|
29
|
+
puts "ROCK beats SCISSORS"
|
30
|
+
puts "SCISSORS beats PAPER"
|
31
|
+
puts "PAPER beats ROCK"
|
32
|
+
puts ""
|
33
|
+
puts ""
|
34
|
+
puts "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
|
35
|
+
puts "IT'S TIME TO BATTLE!"
|
36
|
+
puts "////////////////////"
|
37
|
+
puts ""
|
38
|
+
@mode = @human.set_mode
|
39
|
+
if @mode == '1'
|
40
|
+
one_player_mode
|
41
|
+
else
|
42
|
+
two_player_mode
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def one_player_mode
|
49
|
+
loop do
|
50
|
+
puts ""
|
51
|
+
human_response = @human.ask_for_response
|
52
|
+
computer_response = @computer.get_response
|
53
|
+
puts ""
|
54
|
+
puts GameName
|
55
|
+
puts ""
|
56
|
+
puts "YOU ::::: #{change_response_to_word(human_response)} #{result(human_response, computer_response)} #{change_response_to_word(computer_response)} ::::: COMPUTER"
|
57
|
+
puts ""
|
58
|
+
score
|
59
|
+
puts ""
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def two_player_mode
|
64
|
+
loop do
|
65
|
+
puts ""
|
66
|
+
puts "PLAYER 1"
|
67
|
+
human_response = @human.ask_for_response
|
68
|
+
puts ""
|
69
|
+
puts "PLAYER 2"
|
70
|
+
human2_response = @human2.ask_for_response
|
71
|
+
puts ""
|
72
|
+
puts GameName
|
73
|
+
puts ""
|
74
|
+
puts "PLAYER 1 ::::: #{change_response_to_word(human_response)} #{result(human_response, human2_response)} #{change_response_to_word(human2_response)} ::::: PLAYER 2"
|
75
|
+
puts ""
|
76
|
+
score_for_two
|
77
|
+
puts ""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def change_response_to_word(response)
|
82
|
+
if response == 'r'
|
83
|
+
word = "ROCK"
|
84
|
+
elsif response == 'p'
|
85
|
+
word = "PAPER"
|
86
|
+
else
|
87
|
+
word = "SCISSORS"
|
88
|
+
end
|
89
|
+
word
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_to_scoreboard(message)
|
93
|
+
if message == "DRAW!"
|
94
|
+
@draws += 1
|
95
|
+
elsif message == "You LOSE!"
|
96
|
+
@losses += 1
|
97
|
+
else
|
98
|
+
@wins += 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def draw?(human_response, computer_response)
|
103
|
+
human_response == computer_response
|
104
|
+
end
|
105
|
+
|
106
|
+
def lose?(human_response, computer_response)
|
107
|
+
return true if human_response == 'r' && computer_response == 'p'
|
108
|
+
return true if human_response == 'p' && computer_response == 's'
|
109
|
+
return true if human_response == 's' && computer_response == "r"
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
113
|
+
def result(human_response, computer_response)
|
114
|
+
if draw?(human_response, computer_response)
|
115
|
+
message = "DRAW!"
|
116
|
+
elsif lose?(human_response, computer_response)
|
117
|
+
message = "You LOSE!"
|
118
|
+
else
|
119
|
+
message = "You WIN!"
|
120
|
+
end
|
121
|
+
add_to_scoreboard(message)
|
122
|
+
message
|
123
|
+
end
|
124
|
+
|
125
|
+
def score
|
126
|
+
score_board = "Wins: #{@wins} Losses: #{@losses} Draws #{@draws}"
|
127
|
+
score_board.split('').size.times {print '='}
|
128
|
+
puts ""
|
129
|
+
puts score_board
|
130
|
+
score_board.split('').size.times {print '='}
|
131
|
+
end
|
132
|
+
|
133
|
+
def score_for_two
|
134
|
+
score_board = "PLAYER 1: #{@wins} PLAYER 2: #{@losses} Draws #{@draws}"
|
135
|
+
score_board.split('').size.times {print '='}
|
136
|
+
puts ""
|
137
|
+
puts score_board
|
138
|
+
score_board.split('').size.times {print '='}
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sc_rock_paper_scissors/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sc_rock_paper_scissors"
|
8
|
+
spec.version = ScRockPaperScissors::VERSION
|
9
|
+
spec.authors = ["Steven Chang"]
|
10
|
+
spec.email = ["prime_pork@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rock Paper Scissors}
|
13
|
+
spec.description = %q{One or Two Player Rock Paper Scissors made during Viking Code School}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
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.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sc_rock_paper_scissors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Chang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-13 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: One or Two Player Rock Paper Scissors made during Viking Code School
|
42
|
+
email:
|
43
|
+
- prime_pork@hotmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/sc_rock_paper_scissors.rb
|
57
|
+
- lib/sc_rock_paper_scissors/computer.rb
|
58
|
+
- lib/sc_rock_paper_scissors/human.rb
|
59
|
+
- lib/sc_rock_paper_scissors/player.rb
|
60
|
+
- lib/sc_rock_paper_scissors/version.rb
|
61
|
+
- sc_rock_paper_scissors.gemspec
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata:
|
66
|
+
allowed_push_host: https://rubygems.org
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Rock Paper Scissors
|
87
|
+
test_files: []
|