Skip to content

Instantly share code, notes, and snippets.

@bendoane bendoane/Rochambeau
Created Oct 12, 2015

Embed
What would you like to do?
Homework: day 6
class Game
attr_accessor :player_one_choice, :computer, :computer2,
def initialize
puts "Let's play Rock, Paper, Scissors!"
end
def reset(computer_wins=0,user_wins=0)
vs_user(computer_wins,user_wins)
end
def play
puts "Should I play you, the User, or myself 1000 times? (User or Computer)"
answer = STDIN.gets.chomp
answer.downcase!
until answer == "user" || answer == "computer"
puts "That is not a response I can use. Choose \"User\" or \"Computer"
answer = STDIN.gets.chomp
answer.downcase
end
if answer == "user"
vs_user
else
vs_self
end
end
def vs_self
ties = 0
rock = 0
paper = 0
scissors = 0
1001.times do
selection = %w(rock paper scissors)
self.computer = selection.sample.downcase
self.computer2 = selection.sample.downcase
puts computer
puts computer2
if computer == computer2
ties = ties + 1
elsif computer2 == "rock" && computer == "scissors"
rock = rock + 1
elsif computer2 == "scissors" && computer == "paper"
scissors = scissors + 1
elsif computer2 == "paper" && computer == "rock"
paper = paper + 1
elsif computer == "rock" && computer2 == "scissors"
rock = rock + 1
elsif computer == "scissors" && computer2 == "paper"
scissors = scissors + 1
elsif computer == "paper" && computer2 == "rock"
paper = paper + 1
end
end
puts "I have finished. The results are as follows:"
puts "Ties: #{ties}"
puts "Rock wins: #{rock}"
puts "Paper wins: #{paper}"
puts "Scissors wins: #{scissors}"
puts " "
puts "Would you like to play now?"
answer = STDIN.gets.chomp.downcase
until answer == "yes" || answer == "no"
puts "That's not a 'yes' or 'no'...Do you want to play? (Yes or No)"
answer = STDIN.gets.chomp
answer.downcase
end
if answer == "yes"
puts "Great!"
vs_user
else
puts "That's alright. I won against myself"
end
end
def vs_user(computer_wins=0,user_wins=0)
selection = %w(Rock Paper Scissors)
puts "Which do you choose? Rock, Paper, or Scissors?"
self.player_one_choice = STDIN.gets.chomp
player_one_choice.downcase!
self.computer = selection.sample.downcase!
until player_one_choice == "rock" || player_one_choice == "paper" || player_one_choice == "scissors"
puts "What game is that used for? We're playing Rock, Paper, Scissors. Pick again!"
self.player_one_choice = STDIN.gets.chomp
player_one_choice.downcase!
end
if player_one_choice == computer
puts "It's a tie!"
elsif player_one_choice == "rock" && computer == "scissors"
puts "Your #{player_one_choice} beats my #{computer}! Dang!"
user_wins = user_wins + 1
elsif player_one_choice == "scissors" && computer == "paper"
puts "Your #{player_one_choice} beats my #{computer}! Darn!"
user_wins = user_wins + 1
elsif player_one_choice == "paper" && computer == "rock"
puts "Your #{player_one_choice} beats my #{computer}! Shucks!"
user_wins = user_wins + 1
elsif computer == "rock" && player_one_choice == "scissors"
puts "My #{computer} beats your #{player_one_choice}! #winner!"
computer_wins = computer_wins + 1
elsif computer == "scissors" && player_one_choice == "paper"
puts "My #{computer} beats your #{player_one_choice}! #likeaboss!"
computer_wins = computer_wins + 1
elsif computer == "paper" && player_one_choice == "rock"
puts "My #{computer} beats your #{player_one_choice}! Are you even trying??"
computer_wins = computer_wins + 1
end
puts "Thanks for playing! Want to play again? (Yes or No)"
answer = STDIN.gets.chomp.downcase
until answer == "yes" || answer == "no"
puts "That's not a 'yes' or 'no'...Do you wanna play again? (Yes or No)"
answer = STDIN.gets.chomp
answer.downcase
end
if answer == "yes"
puts "Great!"
puts "Our Scores are as follows"
puts "User wins: #{user_wins}"
puts "Computer wins: #{computer_wins}"
if user_wins > computer_wins
puts "You are currently beating me! Are you cheating?"
elsif user_wins < computer_wins
puts "Ha! I am currently beating you!"
else
puts "We are currently tied."
end
reset(computer_wins,user_wins)
else
puts "Ok...I guess you're just afraid I'm going to win."
end
end
end
game = Game.new
game.play
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.