Sha256: 071b1ab15a20d1f24570bf6754abfd326d7dee3106def66af15eac0c0a082007
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
module Bestgemever class RockPaperScissors OPTIONS = ["rock", "paper", "scissors"] def play_game start type = game_type if type == 'c' player_input computer_input match(@player, @computer) else player1 = player_input player2 = player_input match(player1, player2) end end def start puts "Welcome to Rock, Paper, Scissors!" puts "Rock beats Scissors, Scissors beats Paper, and Paper beats Rock" end def game_type puts "Do you want to play against the computer(c) or another player(p)?" type = gets.chomp end def player_input puts "What is your choice?" choice = gets.chomp until OPTIONS.include? choice puts "Please enter one of the following: rock, paper, scissors" choice = gets.chomp end choice end def computer_input @computer = ["rock", "paper", "scissors"].sample puts "Computer: #{@computer}" end def match(player, computer) if player == computer puts "It's a tie" elsif player == "rock" if computer == "scissors" puts "Rock beats Scissors!" else puts "Paper beats Rock!" end elsif player == "scissors" if computer == "rock" puts "Rock beats Scissors!" else puts "Scissors beats Paper!" end elsif player == "paper" if computer == "rock" puts "Paper beats Rock!" else puts "Scissors beats Paper!" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bestgemever-0.0.2 | lib/bestgemever/rockpaperscissors.rb |