Class: Rockpaperscissorsbattle::Setup

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

Instance Method Summary collapse

Constructor Details

#initializeSetup

Returns a new instance of Setup.



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

def initialize
  @game = nil
  @score = [0,0,0]
  set_options
  start
end

Instance Method Details

#get_optionsObject



42
43
44
45
# File 'lib/rockpaperscissorsbattle/setup.rb', line 42

def get_options
  puts "play with 1 or 2 players?"
  gets.strip.to_i
end

#resetObject



31
32
33
34
35
36
37
38
39
# File 'lib/rockpaperscissorsbattle/setup.rb', line 31

def reset
  puts "Would you like to play again? (Y/N)"
  choice = gets.strip.downcase
  if choice == "y"
    start
  else
    puts "Thanks for playing!"
  end
end

#set_optionsObject



10
11
12
13
14
15
16
17
# File 'lib/rockpaperscissorsbattle/setup.rb', line 10

def set_options
  num_of_players = get_options
  if num_of_players == 2
    @game = Game.new({player2: Player.new})
  else
    @game = Game.new
  end
end

#startObject



19
20
21
22
# File 'lib/rockpaperscissorsbattle/setup.rb', line 19

def start
  track_winners(@game.play)
  reset
end

#track_winners(winner) ⇒ Object



24
25
26
27
28
29
# File 'lib/rockpaperscissorsbattle/setup.rb', line 24

def track_winners(winner)
  @score[winner] += 1
  puts "Player 1 score: #{@score[1]}"
  puts "Player 2 score: #{@score[2]}"
  puts "Ties: #{@score[0]}"
end