47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/RockPaperScissors.rb', line 47
def play(winning_score)
while @player_score < winning_score && @computer_score < winning_score
puts "\nPlayer score: #{@player_score}, " +
"Computer score: #{@computer_score}, Ties: #{@ties}.\n"
player = player_choice
computer = COMPUTER_CHOICES.sample
puts "\nPlayer chooses #{player.to_s.downcase}."
puts "Computer chooses #{computer.to_s.downcase}.\n"
case player_outcome [player, computer]
when :WIN
printf "\n%s beats %s, player wins the round. \n\n" % [player.to_s.capitalize, computer.to_s.downcase]
@player_score += 1
when :LOSE
printf "\n%s beats %s, computer wins the round.\n\n" % [computer.to_s.capitalize, player.to_s.downcase]
@computer_score += 1
else
puts "\nTie, choose again\n"
@ties += 1
end
end
printf "\nFinal score:\nplayer: %i, computer: %i; (ties: %i).\n\n" % [@player_score, @computer_score, @ties]
case final_outcome(@player_score, @computer_score)
when :WIN
puts "\nPlayer wins!\n"
when :LOSE
puts "\nComputer wins!\n"
end
print "\n[press the enter/return key to exit game]"
gets
end
|