Sha256: c65c5f8137a0927ef19677a4fa37bae2089617f62321248356fed10ef99c3264

Contents?: true

Size: 1.89 KB

Versions: 23

Compression:

Stored size: 1.89 KB

Contents

class PlayRockPaperScissorsGame 

  class RPS

    require "ref/Constants.rb";

    class RockPaperScissors 
      class << self
        def continue(str1, str2, str3)
          puts  str1; 
          print str2;
          gets; 
          puts  str3;
        end; 
      end; 
      continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
      def initialize
        @player_score = @computer_score = @ties = 0; 
      end; 
      def play(winning_score) 
        while @player_score < winning_score && @computer_score < winning_score 
          puts "Player score: #{@player_score}, " + 
               "Computer score: #{@computer_score}, Ties: #{@ties}"; 
          player = PrivateVars.player_choice; 
          computer = Constants::COMPUTER_CHOICES.sample; 
          puts "\nPlayer chooses #{player.to_s.downcase}"; 
          puts "Computer chooses #{computer.to_s.downcase}";
          case PrivateVars.player_outcome [player, computer] 
          when :WIN
            puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"; 
            @player_score += 1;
          when :LOSE
            puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
            @computer_score += 1; 
          else 
            puts "Tie, choose again"; 
            @ties += 1;
          end;
        end;
        puts "\nFinal score: player: #{@player_score}, " +
             "computer: #{@computer_score} (ties: #{@ties})"; 
        case PrivateVars.final_outcome(@player_score, @computer_score)
        when :WIN 
          puts "Player wins!"; 
        when :LOSE
          puts "Computer wins!";
        else 
          puts "It's a tie!"; 
        end; 
        puts "";
        gets;
      end; 
      require "ref/PrivateVars.rb";
    end;
  end;
end; 

PlayRockPaperScissorsGame::RPS::RockPaperScissors.new.play(3); # best of 3

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
PlayRockPaperScissorsGame-1.2.0 lib/rps.rb
PlayRockPaperScissorsGame-1.1.9 lib/rps.rb
PlayRockPaperScissorsGame-1.1.8 lib/rps.rb