I'll start by saying I've just started with programming, and Ruby is my first language. I've made a little soccer shoot-out game. I'm having problems with the end of the code looping back to where I want it.
If there's a tie, I want it to keep the same score and players, but add another round of shooting. Should I do this by creating an array to store the points?
If there's anything else I can simplify, I'd really appreciate your input.
class Shoot
def initialize
shoot
end
def shoot
@kick = 1 + rand(6)
end
def kick
@kick
end
end
response = ''
until response == 'N'
play = "Have another shoot-out? Put Y or N."
puts "Player 1's name is:"
player_1_name = gets.chomp
puts "Player 2's name is?"
player_2_name = gets.chomp
puts "#{player_1_name} and #{player_2_name}, are you ready to play sudden death (ENTER)?!"
gets.chomp
p1_score = 0
p2_score = 0
result_1 = 0
result_2 = 0
until result_1 >= 1 || result_2 >= 1
puts "#{player_1_name}, please take your kick (ENTER)."
gets.chomp!
shot_1 = Shoot.new.kick
result_1 = shot_1*0.2
puts "#{player_1_name} takes the shot, and it's looking good..."
puts "(ENTER)"
gets.chomp
if result_1 >= 1
puts "...And it's a goal!!!"
p1_score += 1
else
puts "...Oh! So close, but it's no good!!!"
end
puts "#{player_2_name}, please take your kick (ENTER)."
gets.chomp!
shot_2 = Shoot.new.kick
result_2 = shot_2*0.2
puts "#{player_2_name} takes the shot, and it's looking good..."
puts "(ENTER)"
gets.chomp
if result_2 >= 1
puts "...And it's a goal!!!"
p2_score += 1
else
puts "...Oh! So close, but it's no good!!!"
end
puts "#{player_1_name}: #{p1_score}"
puts "#{player_2_name}: #{p2_score}"
if p1_score > p2_score
puts "#{player_1_name}, you're the winner! Congratulations!"
elsif p1_score < p2_score
puts "#{player_2_name}, you're the winner! Congratulations!"
else
puts "Looks like we've gotta go another round!"
return
end
end
puts play
response = gets.chomp
end