rockpaperscissors 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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +2 -0
- data/lib/rockpaperscissors.rb +7 -0
- data/lib/rockpaperscissors/ai.rb +7 -0
- data/lib/rockpaperscissors/game.rb +72 -0
- data/lib/rockpaperscissors/player.rb +28 -0
- data/lib/rockpaperscissors/version.rb +3 -0
- data/rockpaperscissors.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d95e40ce355d89dc432281dbfe65606fd56e9a63
|
4
|
+
data.tar.gz: 64722731d5a2f3f56a47b75d49e40bc2e1b323c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0440eb092d416e2b06d7b842c801bf5add336357363fc05cdcf96f1aafb08658a6ff5fc2004bb912a61ccbe704da8651e1694f3a23a9d9129d2716b2d7d16df8
|
7
|
+
data.tar.gz: 8681b3df026c20dcf62ce1763e65925607852ebd28d0548de96d0761fb2b01186b307291d2d663dfdf22e5ceb8c1f72a3411db7ebf6112b264ddd3d292da9d92
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dan Berger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rockpaperscissors
|
2
|
+
class Game
|
3
|
+
attr_reader :player_quits, :player_one, :player_two
|
4
|
+
attr_accessor :player_one_wins
|
5
|
+
|
6
|
+
# Set up the game initially
|
7
|
+
def initialize
|
8
|
+
@player_quits = false
|
9
|
+
@player_one_wins = false
|
10
|
+
@player_one = Player.new(1)
|
11
|
+
puts "Welcome to Rock Paper Scissors!"
|
12
|
+
puts "One player or two?"
|
13
|
+
number_of_players = gets.chomp.to_i
|
14
|
+
|
15
|
+
if number_of_players == 1
|
16
|
+
@player_two = AI.new
|
17
|
+
else
|
18
|
+
@player_two = Player.new(2)
|
19
|
+
end
|
20
|
+
|
21
|
+
play
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def play
|
27
|
+
until player_quits
|
28
|
+
player_one_move = player_one.move
|
29
|
+
player_two_move = player_two.move
|
30
|
+
if is_draw?(player_one_move,player_two_move)
|
31
|
+
puts "It's a draw"
|
32
|
+
else
|
33
|
+
pick_winner(player_one_move,player_two_move)
|
34
|
+
display_winner_message player_two_move
|
35
|
+
end
|
36
|
+
ask_player_to_continue
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def pick_winner(move1,move2)
|
41
|
+
case
|
42
|
+
when move1 == "R" && move2 == "S"
|
43
|
+
self.player_one_wins = true
|
44
|
+
when move1 == "S" && move2 == "P"
|
45
|
+
self.player_one_wins = true
|
46
|
+
when move1 == "P" && move2 == "R"
|
47
|
+
self.player_one_wins = true
|
48
|
+
else
|
49
|
+
self.player_one_wins = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_draw?(move1,move2)
|
54
|
+
move1 == move2
|
55
|
+
end
|
56
|
+
|
57
|
+
def ask_player_to_continue
|
58
|
+
puts "Enter 'q' to quit, or anything else to play again: "
|
59
|
+
quit_prompt = gets.chomp.upcase
|
60
|
+
@player_quits = (quit_prompt == 'Q')
|
61
|
+
end
|
62
|
+
|
63
|
+
def display_winner_message player_two_move
|
64
|
+
puts "Player two chose #{player_two_move}"
|
65
|
+
if player_one_wins
|
66
|
+
puts "Player one wins!"
|
67
|
+
else
|
68
|
+
puts "Player two wins!"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rockpaperscissors
|
2
|
+
class Player
|
3
|
+
attr_accessor :choice
|
4
|
+
attr_reader :player_id
|
5
|
+
|
6
|
+
def initialize(player_id)
|
7
|
+
@player_id = player_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def move
|
11
|
+
self.choice = nil
|
12
|
+
until valid_input?
|
13
|
+
print "Player #{player_id}, choose rock ('R'), paper ('P') or scissors ('S')\n > "
|
14
|
+
self.choice = gets.chomp.upcase
|
15
|
+
unless valid_input?
|
16
|
+
print "That's not an allowed move!\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
self.choice
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def valid_input?
|
25
|
+
["R","P","S"].include? self.choice
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rockpaperscissors/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rockpaperscissors"
|
8
|
+
spec.version = Rockpaperscissors::VERSION
|
9
|
+
spec.authors = ["Dan Berger"]
|
10
|
+
spec.email = ["dsberger@gmail.com"]
|
11
|
+
spec.summary = %q{Rock. Paper. Scissors. Destiny.}
|
12
|
+
spec.description = %q{Battle it out with the most fearsome weapons known to humanity.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rockpaperscissors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-29 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: Battle it out with the most fearsome weapons known to humanity.
|
42
|
+
email:
|
43
|
+
- dsberger@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rockpaperscissors.rb
|
54
|
+
- lib/rockpaperscissors/ai.rb
|
55
|
+
- lib/rockpaperscissors/game.rb
|
56
|
+
- lib/rockpaperscissors/player.rb
|
57
|
+
- lib/rockpaperscissors/version.rb
|
58
|
+
- rockpaperscissors.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
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.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Rock. Paper. Scissors. Destiny.
|
83
|
+
test_files: []
|