rockpaperscissorsbattle 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rockpaperscissorsbattle/computer.rb +8 -0
- data/lib/rockpaperscissorsbattle/game.rb +33 -0
- data/lib/rockpaperscissorsbattle/player.rb +14 -0
- data/lib/rockpaperscissorsbattle/setup.rb +43 -0
- data/lib/rockpaperscissorsbattle/version.rb +1 -1
- data/lib/rockpaperscissorsbattle.rb +5 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 295519ccda632412c5a96204d41d25100f9404a7
|
4
|
+
data.tar.gz: a499792715c80a6eebd4347f0310ec64c12b6e50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1713ead76fb87548dbe059fa9151a125e8de3b508be8436c0d19bcd11dd7f84964514f8b6a0db6054363c4242bb229b47a9a306866b1d5bca267197c7091ed63
|
7
|
+
data.tar.gz: 7896091bd123c062dd1bd3695fc114fe4d1a1cad8efc604e4ba8b22ae19bc619a90ad86032884417ac8401eae6988f45cc0a78bec259dea205cb320838ef2472
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rockpaperscissorsbattle
|
2
|
+
class Game
|
3
|
+
def initialize(args = {})
|
4
|
+
@options { r: :s, s: :p, p: :r }
|
5
|
+
@player1 = args[:player1] || Player.new
|
6
|
+
@player2 = args[:player2] || Computer.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def play
|
10
|
+
puts "Welcome to Rock Paper Scissors"
|
11
|
+
puts "Get ready to Battle!"
|
12
|
+
pick1 = @player1.pick(@options)
|
13
|
+
pick2 = @player2.pick(@options)
|
14
|
+
compare(pick1, pick2)
|
15
|
+
end
|
16
|
+
|
17
|
+
def compare(pick1, pick2)
|
18
|
+
if @options[pick1] == pick2
|
19
|
+
puts "Player1 wins!"
|
20
|
+
winner = 1
|
21
|
+
elsif
|
22
|
+
@options[pick2] == pick1
|
23
|
+
puts "Player2 wins!"
|
24
|
+
winner = 2
|
25
|
+
else
|
26
|
+
"You tied..."
|
27
|
+
winner = 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rockpaperscissorsbattle
|
2
|
+
class Setup
|
3
|
+
def initialize
|
4
|
+
@game = nil
|
5
|
+
@score = [0,0,0]
|
6
|
+
set_options
|
7
|
+
start
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_options
|
11
|
+
num_of_players = get_options
|
12
|
+
if num_of_players == 2
|
13
|
+
@game = Game.new({player2: Player.new})
|
14
|
+
else
|
15
|
+
@game = Game.new
|
16
|
+
end
|
17
|
+
@game.play
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
track_winners(@game.play)
|
23
|
+
reset
|
24
|
+
end
|
25
|
+
|
26
|
+
def track_winners(winner)
|
27
|
+
@score[winner] += 1
|
28
|
+
p @score
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
puts "Would you like to play again? (Y/N)"
|
33
|
+
choice = gets.strip.downcase
|
34
|
+
start if choice == "y"
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def get_options
|
39
|
+
puts "play with 1 or 2 players?"
|
40
|
+
gets.strip.to_i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
require "rockpaperscissorsbattle/version"
|
2
|
+
require "rockpaperscissorsbattle/player"
|
3
|
+
require "rockpaperscissorsbattle/computer"
|
4
|
+
require "rockpaperscissorsbattle/game"
|
5
|
+
require "rockpaperscissorsbattle/setup"
|
2
6
|
|
3
7
|
module Rockpaperscissorsbattle
|
4
8
|
# Your code goes here...
|
9
|
+
|
5
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rockpaperscissorsbattle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampson Crowley
|
@@ -52,6 +52,10 @@ files:
|
|
52
52
|
- bin/console
|
53
53
|
- bin/setup
|
54
54
|
- lib/rockpaperscissorsbattle.rb
|
55
|
+
- lib/rockpaperscissorsbattle/computer.rb
|
56
|
+
- lib/rockpaperscissorsbattle/game.rb
|
57
|
+
- lib/rockpaperscissorsbattle/player.rb
|
58
|
+
- lib/rockpaperscissorsbattle/setup.rb
|
55
59
|
- lib/rockpaperscissorsbattle/version.rb
|
56
60
|
- rockpaperscissorsbattle.gemspec
|
57
61
|
homepage: https://github.com/SampsonCrowley/rockpaperscissorsbattle
|