Class: Master::RPS::RockPaperScissors

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

Defined Under Namespace

Modules: PrivateVars

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ RockPaperScissors

Returns a new instance of RockPaperScissors.



53
54
55
# File 'lib/rps.rb', line 53

def initialize
  @player_score = @computer_score = @ties = 0; 
end

Class Method Details

.continue(str1, str2, str3) ⇒ Object



45
46
47
48
49
50
# File 'lib/rps.rb', line 45

def continue(str1, str2, str3)
  puts  str1; 
  print str2;
  gets; 
  puts  str3;
end

Instance Method Details

#play(winning_score) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rps.rb', line 56

def play(winning_score) 
  while @player_score < winning_score && @computer_score < winning_score 
    puts "Player score: #{@player_score}, " + 
         "Computer score: #{@computer_score}, Ties: #{@ties}"; 
    player = PrivateVars.player_choice; 
    computer = Constants::COMPUTER_CHOICES.sample; 
    puts "\nPlayer chooses #{player.to_s.downcase}"; 
    puts "Computer chooses #{computer.to_s.downcase}";
    case PrivateVars.player_outcome [player, computer] 
    when :WIN
      puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"; 
      @player_score += 1;
    when :LOSE
      puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
      @computer_score += 1; 
    else 
      puts "Tie, choose again"; 
      @ties += 1;
    end;
  end;
  puts "\nFinal score: player: #{@player_score}, " +
       "computer: #{@computer_score} (ties: #{@ties})"; 
  case PrivateVars.final_outcome(@player_score, @computer_score)
  when :WIN 
    puts "Player wins!"; 
  when :LOSE
    puts "Computer wins!";
  else 
    puts "It's a tie!"; 
  end; 
  puts "";
  gets;
end