Class: RpsRabGIT::RpsGame

Inherits:
Object
  • Object
show all
Defined in:
lib/rps_rabGIT/rps_game.rb

Instance Method Summary collapse

Constructor Details

#initializeRpsGame

Returns a new instance of RpsGame.



4
5
6
7
8
9
# File 'lib/rps_rabGIT/rps_game.rb', line 4

def initialize
  @play_options = ['R', 'P', 'S']
  @win_combos = ['RS', 'SP', 'PR']
  @player_choice = ''
  @comp_choice = ''
end

Instance Method Details

#playObject



11
12
13
14
15
16
17
# File 'lib/rps_rabGIT/rps_game.rb', line 11

def play
  @comp_choice = @play_options.sample()
  prompt until valid_move?
  return 'Tie!' if @player_choice == @comp_choice
  return "Your #{@player_choice} beat computer's #{@comp_choice}" if win?
  "Computer's #{@comp_choice} beat your #{@player_choice}!"
end