rockpaperscissorsschwad 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81a656be90c4e42ef2067f6e2c3506374a57a725
4
+ data.tar.gz: 369dc55ee9ed1e606479ca53b639a11f6d029531
5
+ SHA512:
6
+ metadata.gz: 8073e40df0a3b761de9088fcc2061d3010d8c08ccf0cb1af1ad124dfb68adc374c16815b1b3cc8f1348af57468efda083c146eef127772a95abb1498753557ed
7
+ data.tar.gz: 700d13aff97491cb1256c23e4c90cf5023437b75a372fd80d003510640aa1c10368471ec3818e67157b99d55cd0a84f41180385382c8c69412ef9be39f7a1a03
@@ -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 rockpaperscissorsschwad.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Schwad
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.
@@ -0,0 +1,31 @@
1
+ # Rockpaperscissorsschwad
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 'rockpaperscissorsschwad'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rockpaperscissorsschwad
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/rockpaperscissorsschwad/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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,110 @@
1
+ require "rockpaperscissorsschwad/version"
2
+
3
+ module Rockpaperscissorsschwad
4
+ #myrubycode
5
+ class RockPaperScissors
6
+ attr_reader :player_quits, :player_one, :player_two
7
+ attr_accessor :player_one_wins
8
+
9
+ def initialize
10
+ @player_quits = false
11
+ @player_one_wins = false
12
+ @player_one = Player.new(1)
13
+ puts "Welcome to Rock Paper Scissors!"
14
+ puts "One player or two?"
15
+ number_of_players = gets.chomp.to_i
16
+
17
+ if number_of_players == 1
18
+ @player_two = AI.new
19
+ else
20
+ @player_two = Player.new(2)
21
+ end
22
+
23
+ play
24
+ end
25
+
26
+ private
27
+
28
+ def play
29
+ until player_quits
30
+ player_one_move = player_one.move
31
+ player_two_move = player_two.move
32
+ if is_draw?(player_one_move,player_two_move)
33
+ puts "It's a draw"
34
+ else
35
+ pick_winner(player_one_move,player_two_move)
36
+ display_winner_message player_two_move
37
+ end
38
+ ask_player_to_continue
39
+ end
40
+ end
41
+
42
+ def pick_winner(move1,move2)
43
+ case
44
+ when move1 == "R" && move2 == "S"
45
+ self.player_one_wins = true
46
+ when move1 == "S" && move2 == "P"
47
+ self.player_one_wins = true
48
+ when move1 == "P" && move2 == "R"
49
+ self.player_one_wins = true
50
+ else
51
+ self.player_one_wins = false
52
+ end
53
+ end
54
+
55
+ def is_draw?(move1,move2)
56
+ move1 == move2
57
+ end
58
+
59
+ def ask_player_to_continue
60
+ puts "Enter 'q' to quit, or anything else to play again: "
61
+ quit_prompt = gets.chomp.upcase
62
+ @player_quits = (quit_prompt == 'Q')
63
+ end
64
+
65
+ def display_winner_message player_two_move
66
+ puts "Player two chose #{player_two_move}"
67
+ if player_one_wins
68
+ puts "Player one wins!"
69
+ else
70
+ puts "Player two wins!"
71
+ end
72
+ end
73
+ end
74
+
75
+ class Player
76
+ attr_accessor :choice
77
+ attr_reader :player_id
78
+
79
+ def initialize(player_id)
80
+ @player_id = player_id
81
+ end
82
+
83
+ def move
84
+ self.choice = nil
85
+ until valid_input?
86
+ print "Player #{player_id}, choose rock ('R'), paper ('P') or scissors ('S')\n > "
87
+ self.choice = gets.chomp.upcase
88
+ unless valid_input?
89
+ print "That's not an allowed move!\n"
90
+ end
91
+ end
92
+ self.choice
93
+ end
94
+
95
+ private
96
+
97
+ def valid_input?
98
+ ["R","P","S"].include? self.choice
99
+ end
100
+ end
101
+
102
+ class AI
103
+ def move
104
+ ["R","P","S"].sample
105
+ end
106
+ end
107
+
108
+ schwad = RockPaperScissors.new
109
+ schwad.play
110
+ end
@@ -0,0 +1,3 @@
1
+ module Rockpaperscissorsschwad
2
+ VERSION = "0.0.2"
3
+ 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 'rockpaperscissorsschwad/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rockpaperscissorsschwad"
8
+ spec.version = Rockpaperscissorsschwad::VERSION
9
+ spec.authors = ["Schwad"]
10
+ spec.email = ["nicholas.schwaderer@gmail.com"]
11
+ spec.summary = %q{This is a simple gem that allows you to play rock paper scissors!}
12
+ spec.description = %q{to install do gem install rockpaperscissorsschwad . Then you specify the number of players, two means two humans and one means against the computer. After that it will prompt you to make a move! Good luck!}
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,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rockpaperscissorsschwad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Schwad
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: to install do gem install rockpaperscissorsschwad . Then you specify
42
+ the number of players, two means two humans and one means against the computer.
43
+ After that it will prompt you to make a move! Good luck!
44
+ email:
45
+ - nicholas.schwaderer@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/rockpaperscissorsschwad.rb
56
+ - lib/rockpaperscissorsschwad/version.rb
57
+ - rockpaperscissorsschwad.gemspec
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: This is a simple gem that allows you to play rock paper scissors!
82
+ test_files: []