rpsviking 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a939bb0e373157b52bab428e02defb6d5ce04024
4
+ data.tar.gz: 615f9d1d4ac58f3dd2537cc762fcfba9c41f02a2
5
+ SHA512:
6
+ metadata.gz: 9258edcdb2723126e3c46aab677f47e67138da0248430facc98ffa5f6668e287a0cb241301f848fa7e79aed9a4b57368274ee5d1c5457ad1b7087673212650a0
7
+ data.tar.gz: 76c37d7f3c5b6015aa61497f3cbe1ae851a70451a72d5ff0561c81dd637b6b38b5e43223bc12f226907f390aae3b7321a680efb3d6db30a43c90415f69b771be
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpsviking.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 koziscool
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,45 @@
1
+ # Rpsviking
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/rpsviking`. 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 'rpsviking'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rpsviking
22
+
23
+ ## Usage
24
+
25
+ Add these lines to your ruby file
26
+ ---
27
+ game = Rpsviking::RockPaperScissors.new
28
+ game..game
29
+ ----
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rpsviking.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
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 "rpsviking"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/rpsviking.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rpsviking/version"
2
+
3
+ require "rpsviking/rockpaperscissors"
4
+ # require "rpsviking/player"
5
+
6
+ # game = RockPaperScissors.new
7
+ # game.game
8
+
9
+ module Rpsviking
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module Rpsviking
3
+
4
+ class Player
5
+ attr_accessor :name, :throw
6
+
7
+ def initialize(name, throw)
8
+ @name = name
9
+ @throw = throw
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,77 @@
1
+
2
+
3
+ require_relative "player"
4
+
5
+ module Rpsviking
6
+
7
+ class RockPaperScissors
8
+
9
+ attr_reader :player_throw, :computer_throw
10
+
11
+ THROWS = [ "rock", "paper", "scissors" ]
12
+
13
+ def game
14
+ loop do
15
+ puts "How many players? (1 or 2)"
16
+ @num_players = gets.chomp.to_i
17
+ if @num_players == 1 || @num_players == 2
18
+ break
19
+ else
20
+ puts "Invalid input. Enter 1 or 2."
21
+ end
22
+ end
23
+
24
+ player_throw = get_player_throw
25
+ puts "Player 1:"
26
+ @player_1 = Player.new("Player 1", player_throw)
27
+
28
+ if @num_players == 2
29
+ puts "Player 1:"
30
+ @player_2 = Player.new("Player 2", get_player_throw)
31
+ else
32
+ @player_2 = Player.new("Computer", random_throw)
33
+ puts "Computer throws: #{@player_2.throw}"
34
+ end
35
+
36
+ puts determine_winner
37
+ end
38
+
39
+ def get_player_throw
40
+ loop do
41
+ puts "enter rock, paper, or scissors:"
42
+ player_throw = gets.chomp
43
+ if valid_input?(player_throw)
44
+ return player_throw
45
+ else
46
+ puts "invalid input, try again"
47
+ end
48
+ end
49
+ end
50
+
51
+ def random_throw
52
+ THROWS.sample
53
+ end
54
+
55
+ def valid_input? (s)
56
+ THROWS.include? s.downcase
57
+ end
58
+
59
+ def determine_winner
60
+ player_throw = @player_1.throw
61
+ computer_throw = @player_2.throw
62
+ ret_string = "draw" if player_throw == computer_throw
63
+ if player_throw == "rock" && computer_throw == "paper" ||
64
+ player_throw == "paper" && computer_throw == "scissors" ||
65
+ player_throw == "scissors" && computer_throw == "rock"
66
+ ret_string = "#{@player_2.name} wins"
67
+ end
68
+ if computer_throw == "rock" && player_throw == "paper" ||
69
+ computer_throw == "paper" && player_throw == "scissors" ||
70
+ computer_throw == "scissors" && player_throw == "rock"
71
+ ret_string = "#{@player_1.name} wins"
72
+ end
73
+ ret_string
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,3 @@
1
+ module Rpsviking
2
+ VERSION = "0.1.0"
3
+ end
data/rpsviking.gemspec ADDED
@@ -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 'rpsviking/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rpsviking"
8
+ spec.version = Rpsviking::VERSION
9
+ spec.authors = ["koziscool", "strychemi" ]
10
+ spec.email = ["kozjob@yahoo.com", "and.baik@gmail.com" ]
11
+
12
+ spec.summary = %q{This implements rock paper scissors}
13
+ spec.description = %q{This is CLI rps implementation}
14
+ spec.homepage = "https://github.com/koziscool/rpsviking.git"
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: rpsviking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - koziscool
8
+ - strychemi
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description: This is CLI rps implementation
43
+ email:
44
+ - kozjob@yahoo.com
45
+ - and.baik@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
+ - bin/console
56
+ - bin/setup
57
+ - lib/rpsviking.rb
58
+ - lib/rpsviking/player.rb
59
+ - lib/rpsviking/rockpaperscissors.rb
60
+ - lib/rpsviking/version.rb
61
+ - rpsviking.gemspec
62
+ homepage: https://github.com/koziscool/rpsviking.git
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.4.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: This implements rock paper scissors
87
+ test_files: []