Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rand_choices = ['rock', 'paper', 'scissor']
- def winner_print(winner, loser, bool)
- if bool
- puts "The computer chose #{loser}. #{winner} beats #{loser}. Congratulations, you win!"
- else
- puts "The computer chose #{winner}. #{loser} loses to #{winner}. I'm sorry, you lost!"
- end
- end
- puts "Please enter your name: "
- print "> "
- name = $stdin.gets.chomp
- puts "Hello #{name}, let's play a round of rock, paper, scissor!"
- puts "What do you choose: "
- print "> "
- choice_player = $stdin.gets.chomp
- choice_computer = rand_choices[rand]
- if rand_choices.include? choice_player
- if choice_player == 'rock' && choice_computer == 'scissor'
- winner_print(choice_player, choice_computer, true)
- elsif choice_player == 'rock' && choice_computer == 'paper'
- winner_print(choice_computer, choice_player, false)
- elsif choice_player == 'paper' && choice_computer == 'rock'
- winner_print(choice_player, choice_computer, true)
- elsif choice_player == 'paper' && choice_computer == 'scissor'
- winner_print(choice_computer, choice_player, false)
- elsif choice_player == 'scissor' && choice_computer == 'paper'
- winner_print(choice_player, choice_computer, true)
- elsif choice_player == 'scissor' && choice_computer == 'rock'
- winner_print(choice_computer, choice_player, false)
- else
- puts "Draw! You both picked #{choice_player}!"
- end
- else
- puts "You didn´t write something meaningfull!"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement