Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created January 7, 2016 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krokrob/3dfb365092d81fb23520 to your computer and use it in GitHub Desktop.
Save krokrob/3dfb365092d81fb23520 to your computer and use it in GitHub Desktop.
# Choose a hand for the computer
# Ask the user his hand
# Compare both hands
# Define result
# store result
# print result
# let's do it again
CHOICE = ["Pierre","Feuille","Ciseaux"]
def computer_hand_method
return CHOICE.sample
end
# puts "Pierre, Feuille, Ciseaux ?"
# player_hand = gets.chomp
# puts computer_hand = computer_hand_method
def logic(computer_hand, player_hand)
if player_hand == "Pierre"
if computer_hand == "Pierre"
return "equality"
elsif computer_hand == "Feuille"
return "You Lose"
else
return "You Win"
end
elsif player_hand == "Feuille"
if computer_hand == "Feuille"
return "equality"
elsif computer_hand == "Pierre"
return "You Win"
else
return "You Lose"
end
else
if computer_hand == "Ciseaux"
return "equality"
elsif computer_hand == "Feuille"
return "You Win"
else
return "You Lose"
end
end
end
# puts logic(computer_hand, player_hand)
player_score = 0
computer_score = 0
while player_score < 3 && computer_score < 3
puts "Pierre, Feuille, Ciseaux ?"
player_hand = gets.chomp
puts computer_hand = computer_hand_method
puts result = logic(computer_hand, player_hand)
if result == "You Win"
player_score += 1
elsif result == "You Lose"
computer_score += 1
end
puts "Score: you = #{player_score} - computer = #{computer_score}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment