Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. rand_choices = ['rock', 'paper', 'scissor']
  2.  
  3. def winner_print(winner, loser, bool)
  4. if bool
  5. puts "The computer chose #{loser}. #{winner} beats #{loser}. Congratulations, you win!"
  6. else
  7. puts "The computer chose #{winner}. #{loser} loses to #{winner}. I'm sorry, you lost!"
  8. end
  9. end
  10.  
  11.  
  12. puts "Please enter your name: "
  13. print "> "
  14.  
  15. name = $stdin.gets.chomp
  16.  
  17. puts "Hello #{name}, let's play a round of rock, paper, scissor!"
  18. puts "What do you choose: "
  19. print "> "
  20.  
  21. choice_player = $stdin.gets.chomp
  22. choice_computer = rand_choices[rand]
  23.  
  24. if rand_choices.include? choice_player
  25.  
  26.  
  27. if choice_player == 'rock' && choice_computer == 'scissor'
  28. winner_print(choice_player, choice_computer, true)
  29. elsif choice_player == 'rock' && choice_computer == 'paper'
  30. winner_print(choice_computer, choice_player, false)
  31. elsif choice_player == 'paper' && choice_computer == 'rock'
  32. winner_print(choice_player, choice_computer, true)
  33. elsif choice_player == 'paper' && choice_computer == 'scissor'
  34. winner_print(choice_computer, choice_player, false)
  35. elsif choice_player == 'scissor' && choice_computer == 'paper'
  36. winner_print(choice_player, choice_computer, true)
  37. elsif choice_player == 'scissor' && choice_computer == 'rock'
  38. winner_print(choice_computer, choice_player, false)
  39. else
  40. puts "Draw! You both picked #{choice_player}!"
  41. end
  42.  
  43. else
  44. puts "You didn´t write something meaningfull!"
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement