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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96379c8dde027d08bdacf3cd1dd3975368a5870d
4
- data.tar.gz: a26c9ead1f8bfdc4b6bac836f83b78f6af5d127d
3
+ metadata.gz: 295519ccda632412c5a96204d41d25100f9404a7
4
+ data.tar.gz: a499792715c80a6eebd4347f0310ec64c12b6e50
5
5
  SHA512:
6
- metadata.gz: f5e077c4872fb9ae399ab98ada8aa8d1ed512c6bc0b2d22b4ab14903c26b14f1d4646e9ca04f5e601305438500fecac3a96ca86690bd13163d569b4618cc579d
7
- data.tar.gz: 9a0aebf55ad0b319ff0baa86f702a02726c90e15b69a8562b18038e8897ee038908ed5a076fdac83cdf650b72cc53d651a59612f11e19826efcba5965977780d
6
+ metadata.gz: 1713ead76fb87548dbe059fa9151a125e8de3b508be8436c0d19bcd11dd7f84964514f8b6a0db6054363c4242bb229b47a9a306866b1d5bca267197c7091ed63
7
+ data.tar.gz: 7896091bd123c062dd1bd3695fc114fe4d1a1cad8efc604e4ba8b22ae19bc619a90ad86032884417ac8401eae6988f45cc0a78bec259dea205cb320838ef2472
@@ -0,0 +1,8 @@
1
+ module Rockpaperscissorsbattle
2
+ class Computer < Player
3
+ def pick(options)
4
+ options.sample
5
+ end
6
+ end
7
+
8
+ end
@@ -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,14 @@
1
+ module Rockpaperscissorsbattle
2
+
3
+ class Player
4
+ def pick(options)
5
+ choice = nil
6
+ until options.include?(choice)
7
+ Q;Enter "r", "p" or "s";
8
+ choice = gets.strip
9
+ end
10
+ choice
11
+ end
12
+ end
13
+
14
+ 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,3 +1,3 @@
1
1
  module Rockpaperscissorsbattle
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
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