rock_paper_scissors_gem 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3de7fb10cac11ed8a71025847e75956d35045e55
4
+ data.tar.gz: 278aa02b96c15fa58e9337acbc1fd7fd01d7944f
5
+ SHA512:
6
+ metadata.gz: 25bf2390d66b006d214892d9ba1e6d9a2157eb1d7715bc8680f230f655493a1213543e213fa32a6237abb319362b24b5e3ba46a11c452356578dae1cb1bcadd1
7
+ data.tar.gz: 60211697dfa40236759c9e9464143b7f8e562abcbe6b78054d357756d1eaa9abbbbdbf89c7900b573e576d98d6cf7e6a595e99cad2367f5af3387602efc0e153
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rock_paper_scissors_gem.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Daniel Au
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
@@ -0,0 +1,31 @@
1
+ # RockPaperScissorsGem
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rock_paper_scissors_gem'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rock_paper_scissors_gem
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/rock_paper_scissors_gem/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module RockPaperScissorsGem
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,116 @@
1
+ require "rock_paper_scissors_gem/version"
2
+
3
+ module RockPaperScissorsGem
4
+ #myrubycode
5
+
6
+ def self.play_rps
7
+ rps = RockPaperScissors.new
8
+ end
9
+
10
+ class RockPaperScissors
11
+ attr_reader :player_quits, :player_one, :player_two
12
+ attr_accessor :player_one_wins
13
+
14
+ def initialize
15
+ @player_quits = false
16
+ @player_one_wins = false
17
+ @player_one = Player.new(1)
18
+ puts "Welcome to Rock Paper Scissors!"
19
+ puts "One player or two?"
20
+ number_of_players = gets.chomp.to_i
21
+
22
+ if number_of_players == 1
23
+ @player_two = AI.new
24
+ else
25
+ @player_two = Player.new(2)
26
+ end
27
+
28
+ play
29
+ end
30
+
31
+
32
+
33
+ private
34
+
35
+ def play
36
+ until player_quits
37
+ player_one_move = player_one.move
38
+ player_two_move = player_two.move
39
+ if is_draw?(player_one_move,player_two_move)
40
+ puts "It's a draw"
41
+ else
42
+ pick_winner(player_one_move,player_two_move)
43
+ display_winner_message player_two_move
44
+ end
45
+ ask_player_to_continue
46
+ end
47
+ end
48
+
49
+ def pick_winner(move1,move2)
50
+ case
51
+ when move1 == "R" && move2 == "S"
52
+ self.player_one_wins = true
53
+ when move1 == "S" && move2 == "P"
54
+ self.player_one_wins = true
55
+ when move1 == "P" && move2 == "R"
56
+ self.player_one_wins = true
57
+ else
58
+ self.player_one_wins = false
59
+ end
60
+ end
61
+
62
+ def is_draw?(move1,move2)
63
+ move1 == move2
64
+ end
65
+
66
+ def ask_player_to_continue
67
+ puts "Enter 'q' to quit, or anything else to play again: "
68
+ quit_prompt = gets.chomp.upcase
69
+ @player_quits = (quit_prompt == 'Q')
70
+ end
71
+
72
+ def display_winner_message player_two_move
73
+ puts "Player two chose #{player_two_move}"
74
+ if player_one_wins
75
+ puts "Player one wins!"
76
+ else
77
+ puts "Player two wins!"
78
+ end
79
+ end
80
+ end
81
+
82
+ class Player
83
+ attr_accessor :choice
84
+ attr_reader :player_id
85
+
86
+ def initialize(player_id)
87
+ @player_id = player_id
88
+ end
89
+
90
+ def move
91
+ self.choice = nil
92
+ until valid_input?
93
+ print "Player #{player_id}, choose rock ('R'), paper ('P') or scissors ('S')\n > "
94
+ self.choice = gets.chomp.upcase
95
+ unless valid_input?
96
+ print "That's not an allowed move!\n"
97
+ end
98
+ end
99
+ self.choice
100
+ end
101
+
102
+ private
103
+
104
+ def valid_input?
105
+ ["R","P","S"].include? self.choice
106
+ end
107
+ end
108
+
109
+ class AI
110
+ def move
111
+ ["R","P","S"].sample
112
+ end
113
+ end
114
+
115
+
116
+ 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 'rock_paper_scissors_gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rock_paper_scissors_gem"
8
+ spec.version = RockPaperScissorsGem::VERSION
9
+ spec.authors = ["Daniel Au"]
10
+ spec.email = ["Daniel_Au@gmail.com"]
11
+ spec.summary = %q{Rock, paper, scissors!}
12
+ spec.description = %q{Some useful rock paper scissors methods}
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,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rock_paper_scissors_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Au
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-27 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: Some useful rock paper scissors methods
42
+ email:
43
+ - Daniel_Au@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/rock_paper_scissors_gem.rb
54
+ - lib/rock_paper_scissors_gem/version.rb
55
+ - rock_paper_scissors_gem.gemspec
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Rock, paper, scissors!
80
+ test_files: []