ttw_rps 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66b6394d6daa4d5aea1a6128157802c32d72c141
4
+ data.tar.gz: 2b2c5f54b097aa07f195820ad9c8304432e9521a
5
+ SHA512:
6
+ metadata.gz: 4b8654eaddced7db59216d8b05d3af1fb537aeda22111eb69b943e1a6d14a624ca9e6fecb2393588ecf21578e9ff934047082a38fe371fb6b126465ff15aeae2
7
+ data.tar.gz: fa7d917e9cbede4c167075c7190f2bc585a900f53d5a3139a27184665803f88fa7591c98d42f911f25069a9f31826fb644d92165895dc13c63a4148baedad6d9
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ttw_rps.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # TtwRps
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/ttw_rps`. 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 'ttw_rps'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ttw_rps
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 spec` 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]/ttw_rps.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ttw_rps"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ require "ttw_rps/version"
2
+
3
+ module TtwRps
4
+
5
+ class RockPaperScissors
6
+
7
+ def initialize
8
+ @win_options = [["paper","rock"], ["rock","scissors"], ["scissors","paper"]]
9
+ end
10
+
11
+ def play
12
+ intro
13
+ if computer_mode?
14
+ @player1 = Player.new(true)
15
+ @player2 = Player.new
16
+ else
17
+ @player1 = Player.new(true)
18
+ @player2 = Player.new(true)
19
+ end
20
+ player1_move = @player1.throw(1)
21
+ player2_move = @player2.throw(2)
22
+ result(player1_move, player2_move)
23
+ end
24
+
25
+ def intro
26
+ print "\n\n\n"
27
+ puts "Rock, Paper, Scissors!!"
28
+ puts
29
+ end
30
+
31
+ def computer_mode?
32
+ loop do
33
+ puts "If this is a 2-player game, please enter 'a'."
34
+ puts "Otherwise, enter 'b' if you're playing against the computer."
35
+ mode = gets.chomp
36
+ if mode == "a"
37
+ return false
38
+ elsif mode == "b"
39
+ return true
40
+ end
41
+ end
42
+ end
43
+
44
+ def result(move1, move2)
45
+ if @win_options.include?([move1, move2])
46
+ puts "Player 1 wins!"
47
+ binding.pry
48
+ elsif @win_options.include?([move2, move1])
49
+ puts "Player 2 wins!"
50
+ elsif move1 == move2
51
+ puts "It's a tie!"
52
+ end
53
+ puts "\n\n\n"
54
+ end
55
+ end
56
+
57
+ class Player
58
+
59
+ def initialize(human=false)
60
+ @human = human
61
+ @choices = %w(rock paper scissors)
62
+ end
63
+
64
+
65
+ def throw(num)
66
+ if @human
67
+ loop do
68
+ puts
69
+ puts "Rock, paper, scissors..."
70
+ print "Player #{num}> "
71
+ move = gets.chomp.downcase.gsub(/\s+/, "")
72
+ if @choices.include?(move)
73
+ return move
74
+ else
75
+ puts "Please submit rock, paper, or scissors."
76
+ end
77
+ end
78
+ else
79
+ move = @choices.sample
80
+ puts "Player 2 threw #{move}!"
81
+ puts
82
+ move
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ module TtwRps
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ttw_rps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ttw_rps"
8
+ spec.version = TtwRps::VERSION
9
+ spec.authors = ["tt"]
10
+ spec.email = ["ttwang.303@gmail.com"]
11
+
12
+ spec.summary = %q{rock paper scissors}
13
+ spec.description = %q{Play rock paper scissors.}
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ttw_rps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-06 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Play rock paper scissors.
56
+ email:
57
+ - ttwang.303@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/ttw_rps.rb
71
+ - lib/ttw_rps/version.rb
72
+ - ttw_rps.gemspec
73
+ homepage: ''
74
+ licenses: []
75
+ metadata:
76
+ allowed_push_host: https://rubygems.org
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: rock paper scissors
97
+ test_files: []