Class: Rockpaperscissorsbattle::Setup
- Inherits:
-
Object
- Object
- Rockpaperscissorsbattle::Setup
- Defined in:
- lib/rockpaperscissorsbattle/setup.rb
Instance Method Summary collapse
- #get_options ⇒ Object
-
#initialize ⇒ Setup
constructor
A new instance of Setup.
- #reset ⇒ Object
- #set_options ⇒ Object
- #start ⇒ Object
- #track_winners(winner) ⇒ Object
Constructor Details
#initialize ⇒ Setup
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] start end |
Instance Method Details
#get_options ⇒ Object
42 43 44 45 |
# File 'lib/rockpaperscissorsbattle/setup.rb', line 42 def puts "play with 1 or 2 players?" gets.strip.to_i end |
#reset ⇒ Object
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_options ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/rockpaperscissorsbattle/setup.rb', line 10 def num_of_players = if num_of_players == 2 @game = Game.new({player2: Player.new}) else @game = Game.new end end |
#start ⇒ Object
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 |