Class: Rockpaperscissorsbattle::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/rockpaperscissorsbattle/game.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Game

Returns a new instance of Game.



3
4
5
6
7
# File 'lib/rockpaperscissorsbattle/game.rb', line 3

def initialize(args = {})
  @options =  { r: :s, s: :p, p: :r }
  @player1 = args[:player1] || Player.new
  @player2 = args[:player2] || Computer.new
end

Instance Method Details

#compare(pick1, pick2) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rockpaperscissorsbattle/game.rb', line 23

def compare(pick1, pick2)
  if @options[pick1] == pick2
    puts "Player1 wins!"
    winner = 1
  elsif @options[pick2] == pick1
    puts "Player2 wins!"
    winner = 2
  else
    puts "You tied..."
    winner = 0
  end
end

#playObject



13
14
15
16
17
18
19
20
21
# File 'lib/rockpaperscissorsbattle/game.rb', line 13

def play
  puts "Get ready to Battle!"

  print "Player 1:"
  pick1 = @player1.pick(@options)
  print "Player 2:"
  pick2 = @player2.pick(@options)
  compare(pick1, pick2)
end

#welcomeObject



9
10
11
# File 'lib/rockpaperscissorsbattle/game.rb', line 9

def welcome
  puts "Welcome to Rock Paper Scissors"
end