Create a gist now

Instantly share code, notes, and snippets.

player_score = 0
computer_score = 0
player_reroll = true
while player_score < 100 && computer_score < 100
while player_reroll == true
puts 'Type roll to roll: '
to_roll = gets.chomp
while to_roll != 'roll'
puts 'Type roll to roll:'
to_roll = gets.chomp
end
player_die1 = rand(6)
player_die2 = rand(6)
puts "You rolled a #{player_die1} and #{player_die2}."
if player_die1 == 1 && player_die2 == 1
player_score = 0
puts 'Your score has been reset to 0. Your turn is over'
player_reroll = false
computer_reroll = true
elsif player_die1 !=1 && player_die2 != 1 && player_score < 100
player_score = player_die1 + player_die2 + player_score
puts "Your score is now #{player_score}. You can roll again."
reply = 'fun'
while reply != 'yes' && reply != 'no'
puts 'Would you like to reroll? Yes or No?'
reply = gets.chomp.downcase
end
if reply == 'yes'
player_reroll = true
computer_reroll = false
elsif reply == 'no'
player_reroll = false
computer_reroll = true
end
elsif player_die1 || player_die2 == 1
player_score = player_score
puts "Your turn is over. Your score (#{player_score}) remains unchanged."
player_reroll = false
computer_reroll = true
end
end
while computer_reroll == true
computer_die1 = rand(6)
computer_die2 = rand(6)
puts "The computer rolled a #{computer_die1} and #{computer_die2}."
if computer_die1 == 1 && computer_die2 == 1
computer_score = 0
puts 'The computer\'s score has been reset to 0. Its turn is over'
computer_reroll = false
player_reroll = true
elsif computer_die1 !=1 && computer_die2 != 1 && computer_score < 100
computer_score = computer_die1 + computer_die2 + computer_score
puts "The computer's score is now #{player_score}. It can roll again."
reply = 'fun'
sim_choice = rand(2)
sim_choice = sim_choice + 1
if sim_choice == 1
puts 'The computer chose to end its turn.'
computer_reroll = false
player_reroll = true
elsif sim_choice == 2
puts 'The computer chose to reroll.'
computer_reroll = true
player_reroll = false
end
elsif computer_die1 || computer_die2 == 1
computer_score = computer_score
puts 'The computer\'s turn is over.'
puts "Its score (#{computer_score}) remains unchanged."
computer_reroll = false
player_reroll = true
end
end
puts
puts "Player score: #{player_score}"
puts "Computer score: #{computer_score}"
puts
end
if computer_score >= 100
'Computer wins!'
elsif
computer_score <= 100
'You win!'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment