rock_paper_scissors_emoji 1.0.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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rock_paper_scissors_emoji.rb +12 -0
- data/lib/rock_paper_scissors_emoji/players.rb +8 -0
- data/lib/rock_paper_scissors_emoji/rps.rb +210 -0
- data/lib/rock_paper_scissors_emoji/version.rb +3 -0
- data/rock_paper_scissors_emoji.gemspec +35 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f6e49ead4f289563cb2871a4cbaccefb6a62031
|
4
|
+
data.tar.gz: e04262a0de10ce5ab51c58e5804f89f23681ce85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b99587f2bdf5e97736e5c86a2b412f2e95b12741491e160636b5faeff548fec4908b4759e283de950f0be2d9af1bf1324a4faa1c527660d26b1de72ad4c6e099
|
7
|
+
data.tar.gz: 7059b23afe4d58a7dac901ccb07c715aaa932a7528ac450536a7067d818a04478355917f68136914424f6948d01da1b20e3c659887a3fe9117ab8784fb828b38
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 yxlau
|
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,41 @@
|
|
1
|
+
# RockPaperScissorsEmoji
|
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/rock_paper_scissors_emoji`. 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 'rock_paper_scissors_emoji'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rock_paper_scissors_emoji
|
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. 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]/rock_paper_scissors_emoji.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rock_paper_scissors_emoji"
|
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,12 @@
|
|
1
|
+
require "rock_paper_scissors_emoji/version"
|
2
|
+
require 'rock_paper_scissors_emoji/players.rb'
|
3
|
+
require 'rock_paper_scissors_emoji/rps.rb'
|
4
|
+
|
5
|
+
# run RockPaperScissorsEmoji::play to play
|
6
|
+
|
7
|
+
module RockPaperScissorsEmoji
|
8
|
+
def self.play
|
9
|
+
RPS.new
|
10
|
+
end
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'io/console'
|
2
|
+
require_relative('players.rb')
|
3
|
+
|
4
|
+
class RPS
|
5
|
+
|
6
|
+
# game = RPS.new to start programme
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@moves = ['r', 'p', 's']
|
10
|
+
@emojify = {'r' => '👊 ', 'p' => '🖐 ', 's' => '✌️ ' }
|
11
|
+
@playmode = ''
|
12
|
+
@points = 0
|
13
|
+
@gamewidth = 70
|
14
|
+
@computer_win = ['Computer!-Oh hey, that\'s me!', 'meeeeeeeeeeeeee! 👾 ', 'not you :(', 'Computer']
|
15
|
+
main_menu
|
16
|
+
end
|
17
|
+
|
18
|
+
def main_menu
|
19
|
+
# welcome message
|
20
|
+
welcome
|
21
|
+
puts
|
22
|
+
|
23
|
+
# validate player mode
|
24
|
+
get_playmode until valid_mode?(@playmode)
|
25
|
+
puts
|
26
|
+
|
27
|
+
# provide user feedback on their chosen game mode
|
28
|
+
mode_confirmation(@playmode)
|
29
|
+
puts
|
30
|
+
|
31
|
+
# get number of points required to win
|
32
|
+
get_points
|
33
|
+
puts
|
34
|
+
|
35
|
+
# create players
|
36
|
+
@player1 = create_player(1)
|
37
|
+
puts
|
38
|
+
|
39
|
+
@player2 = @playmode == '2'? create_player(2) : create_computer
|
40
|
+
puts
|
41
|
+
play
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def play
|
46
|
+
run_game until game_over?
|
47
|
+
puts "The winner is #{winner == @player1? 'you!' : @computer_win.sample}\n\n" if @playmode == '1'
|
48
|
+
puts "Congratulations, #{winner.name}! You've won! \n\n" if @playmode == '2'
|
49
|
+
reset_moves
|
50
|
+
reset_player_points
|
51
|
+
play_again
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_move?(move)
|
55
|
+
quit?(move)
|
56
|
+
move == 'r' || move == 'p' || move == 's'
|
57
|
+
end
|
58
|
+
|
59
|
+
def quit?(key)
|
60
|
+
exit if key == 'q' || key == 'quit'
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_move(player, secret=false)
|
64
|
+
# secret tells us if the input should be hidden
|
65
|
+
puts "Choose a move!"
|
66
|
+
puts "Enter 'r' for rock, 'p' for paper, and 's' for scissors"
|
67
|
+
until valid_move?(player.move)
|
68
|
+
print "#{player.name}: "
|
69
|
+
if !secret
|
70
|
+
player.move = gets.chomp
|
71
|
+
end
|
72
|
+
player.move = STDIN.noecho(&:gets).chomp if secret
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def winner
|
77
|
+
if @player1.move == 's' && @player2.move == 'p' || @player1.move == 'p' && @player2.move == 'r' || @player1.move == 'r' && @player2.move == 's'
|
78
|
+
return @player1
|
79
|
+
end
|
80
|
+
@player2
|
81
|
+
end
|
82
|
+
|
83
|
+
def computer_move
|
84
|
+
@player2.move = @moves.sample
|
85
|
+
puts "Computer: #{@player2.move}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def run_game
|
89
|
+
until round_over?
|
90
|
+
if @playmode == '1'
|
91
|
+
get_move(@player1)
|
92
|
+
computer_move
|
93
|
+
else
|
94
|
+
get_move(@player1, true)
|
95
|
+
get_move(@player2, true)
|
96
|
+
end
|
97
|
+
if !round_over?
|
98
|
+
puts
|
99
|
+
puts "You both played #{@emojify[@player1.move]}! You'll have to play this round again"
|
100
|
+
puts
|
101
|
+
reset_moves
|
102
|
+
end
|
103
|
+
end
|
104
|
+
puts "#{@player1.name} played #{@emojify[@player1.move]}, while #{@player2.name} played #{@emojify[@player2.move]}"
|
105
|
+
winner.points += 1
|
106
|
+
print_score if @points > 1
|
107
|
+
reset_moves
|
108
|
+
end
|
109
|
+
|
110
|
+
def play_again
|
111
|
+
puts "Enter 'y' to play again, 'm' to return to the main menu, and 'q' to quit"
|
112
|
+
print "What would you like to do? "
|
113
|
+
action = gets.strip
|
114
|
+
quit?(action)
|
115
|
+
play if action == 'y'
|
116
|
+
if action == 'm'
|
117
|
+
reset_game
|
118
|
+
main_menu
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def reset_game
|
123
|
+
@player1 = nil
|
124
|
+
@player2 = nil
|
125
|
+
@playmode = ''
|
126
|
+
@points = 0
|
127
|
+
end
|
128
|
+
|
129
|
+
def print_score
|
130
|
+
puts
|
131
|
+
print "[Current score"
|
132
|
+
print "]".rjust(25-"Current score".length)
|
133
|
+
puts
|
134
|
+
print "[#{@player1.name}:"
|
135
|
+
print "#{@player1.points}]".rjust(25-@player1.name.length-1)
|
136
|
+
puts
|
137
|
+
print "[#{@player2.name}:"
|
138
|
+
puts "#{@player2.points}]".rjust(25-@player2.name.length-1)
|
139
|
+
puts
|
140
|
+
end
|
141
|
+
|
142
|
+
def reset_player_points
|
143
|
+
@player1.points = 0
|
144
|
+
@player2.points = 0
|
145
|
+
end
|
146
|
+
|
147
|
+
def reset_moves
|
148
|
+
@player1.move = ''
|
149
|
+
@player2.move = ''
|
150
|
+
end
|
151
|
+
|
152
|
+
def round_over?
|
153
|
+
@player1.move != @player2.move
|
154
|
+
end
|
155
|
+
|
156
|
+
def game_over?
|
157
|
+
# game ends when one of the players hits @points number of points
|
158
|
+
@player1.points == @points || @player2.points == @points
|
159
|
+
end
|
160
|
+
|
161
|
+
def create_computer
|
162
|
+
Player.new('Computer')
|
163
|
+
end
|
164
|
+
|
165
|
+
def create_player(num)
|
166
|
+
puts "Please enter your name, player #{num}"
|
167
|
+
print "Player #{num} name: "
|
168
|
+
player = gets.strip
|
169
|
+
puts "Thanks, #{player}!"
|
170
|
+
Player.new(player)
|
171
|
+
end
|
172
|
+
|
173
|
+
def get_points
|
174
|
+
# number of rounds needed to win game
|
175
|
+
puts "Choose the number of points required to win"
|
176
|
+
puts "(Hint: It can be any odd number from 1 to 21)"
|
177
|
+
until @points.between?(1,21) && @points.odd?
|
178
|
+
print "Points: "
|
179
|
+
points = gets.chomp
|
180
|
+
quit?(points) # in case user wants to quit
|
181
|
+
@points = points.to_i
|
182
|
+
puts "Please enter an odd number!" unless @points.odd?
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def mode_confirmation(mode)
|
187
|
+
puts "You have chosen single player mode! May the odds be ever in your favour!" if mode == '1'
|
188
|
+
puts "You have chosen to play against a friend. May the best friend win!" if mode == '2'
|
189
|
+
end
|
190
|
+
|
191
|
+
def valid_mode?(mode)
|
192
|
+
quit?(mode)
|
193
|
+
mode == '1' || mode == '2'
|
194
|
+
end
|
195
|
+
|
196
|
+
def get_playmode
|
197
|
+
puts "Choose a player mode:"
|
198
|
+
puts "Enter '1' for single player, '2' for two-player and 'q' to quit."
|
199
|
+
print "Play mode: "
|
200
|
+
@playmode = gets.chomp
|
201
|
+
end
|
202
|
+
|
203
|
+
def welcome
|
204
|
+
puts "=" * @gamewidth
|
205
|
+
puts "Welcome to 👊 🖐 ✌️ !"
|
206
|
+
puts "(That's emoji for rock, paper, scissors)"
|
207
|
+
puts "=" * @gamewidth
|
208
|
+
end
|
209
|
+
|
210
|
+
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 'rock_paper_scissors_emoji/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rock_paper_scissors_emoji"
|
8
|
+
spec.version = RockPaperScissorsEmoji::VERSION
|
9
|
+
spec.authors = ["yxlau"]
|
10
|
+
spec.email = ["yixuan.lau@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Play rock, paper, scissors with emoji.}
|
13
|
+
spec.description = %q{Play against the computer or play against another human being. Choose the number of games that must be won for the ultimate winner. Have fun.}
|
14
|
+
spec.homepage = "https://github.com/yxlau/rock_paper_scissors_emoji"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing 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 " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rock_paper_scissors_emoji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yxlau
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-01 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
|
+
description: Play against the computer or play against another human being. Choose
|
42
|
+
the number of games that must be won for the ultimate winner. Have fun.
|
43
|
+
email:
|
44
|
+
- yixuan.lau@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".DS_Store"
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/rock_paper_scissors_emoji.rb
|
58
|
+
- lib/rock_paper_scissors_emoji/players.rb
|
59
|
+
- lib/rock_paper_scissors_emoji/rps.rb
|
60
|
+
- lib/rock_paper_scissors_emoji/version.rb
|
61
|
+
- rock_paper_scissors_emoji.gemspec
|
62
|
+
homepage: https://github.com/yxlau/rock_paper_scissors_emoji
|
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.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Play rock, paper, scissors with emoji.
|
87
|
+
test_files: []
|