2 Replies - 1260 Views - Last Post: 29 January 2017 - 12:54 PM Rate Topic: -----

#1 jstanley6  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 22-January 17

Rock, Paper, Scissors Program

Posted 28 January 2017 - 08:37 PM

Hey, I am working on this Rock, paper, scissors program but I have run into 2 problems, the first one, every once in a while when i hit the '2' option it goes straight to the invalid choice option and the code looks just like the '1' and '3' option so I have no clue what is going on, the second problem is I can't get the game to start after the user enters 'y' to play the game, However instead of 1 game I am going to be creating the Lizard, Spock game underneath the first program than the prompt will ask which game they want to play, the coding is very long because I am a beginner programmer and I know there is much faster ways to get it working, so I'm not sure if it will all fit on this forum but I can post everything I have if possible. Let me know, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Rock, Paper, Scissors Program

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: Rock, Paper, Scissors Program

Posted 28 January 2017 - 09:08 PM

It's a little hard to diagnose issues without seeing what you are actually doing. :^:
Was This Post Helpful? 0
  • +
  • -

#3 jstanley6  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 22-January 17

Re: Rock, Paper, Scissors Program

Posted 29 January 2017 - 12:54 PM

Ok let me see if it will fit..I only got the 1 program complete, the other program I will make after I get the Do you want to play the game working:

player_choice = 0
wins = 0
losses = 0
draws = 0


menu = [
    "1. Paper",
    "2. Rock",
    "3. Scissors",
    "4. Quit",
]
puts "Welcome to Rock, Paper, Scissors. Try to outsmart the computer to win. The menu options are as follows: " + menu.to_s + " Please enter only 1-4 in the menu options:"
puts "Do you want to play? Y for Yes or N for No. "
play = gets.to_s.downcase
if play == "y"

while player_choice != 4
  menu.each do | item |
    puts item
  end
  puts "Please Enter your Choice: "
  player_choice = gets.to_i
  computer_choice = rand(1..3)

  if player_choice == 1 && computer_choice == 1
    puts "You choose Paper. The computer also chooses Paper. It is a TIE!!"
    draws += 1
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 2 && computer_choice == 2
    puts "You choose Rock. The computer has also chosen Rock. It is a TIE!!!"
    draws += 1
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 3 && computer_choice == 3
    puts "You choose Scissors. The computer has also chosen Scissors. It is a TIE!!!!"
    draws += 1
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 1 && computer_choice == 2
    wins += 1
    puts "Tou choose Paper. The computer has chosen Rock. ROCK covers PAPER!! You WIN!"
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 2 && computer_choice == 3
    wins += 1
    puts "You choose Rock. The computer has chosen scissors. Rock CRUSHES Scissors! YOU WIN!!!"
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 3 && computer_choice == 2
    losses += 1
    puts "You choose Scissors. The computer chooses Rock. Rock CRUSHES Scissors. YOU LOSE!"
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 1 && computer_choice == 3
    puts "You choose Paper. The computer chooses Scissors. Scissors CUTS Paper. YOU LOSE!!"
    losses += 1
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 3 && computer_choice == 2
    losses += 1
    puts "You choose Scissors. The computer chooses Rock. Rock CRUSHES Scissors. YOU LOSE!!!"
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 3 && computer_choice == 1
    wins += 1
    puts "You choose Scissors. The computer chooses Paper. Scissors CUTS Paper. YOU WIN!!!!"
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"
  elsif player_choice == 4
    puts "Player score is " + wins.to_s + " wins " + losses.to_s + " losses " + draws.to_s + " draws!"

    if wins > losses
      puts "Player Wins!!"
    elsif losses > wins
      puts "Computer Wins!"
    else
      puts "It's a Draw. No one Wins!!"
    end
    puts "Good BYE!! Play Again Soon!!"
  else
    puts "Invalid Choice. Please try again!"
  end
end
end


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1