PlayRockPaperScissorsGame 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +39 -0
  3. data/bin/rps +117 -0
  4. data/lib/rps.rb +117 -0
  5. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25775aa65e253538c4ee6cfe6e93c57dd92b297d
4
+ data.tar.gz: 9560f5e0db62ae29afa297b0edf84d622167b2db
5
+ SHA512:
6
+ metadata.gz: 980250aa016623c64a355ee844bc487b7a29f154e02697945b605b682a8f5ecd0897afad8e1fbba3641e294839710457da533d042764ad326349d659fdd51763
7
+ data.tar.gz: 5178234406677eaadc5e8cd4bd30d8d35c4593802e00bda17bf67397e02e33808b051ea1ca2e3df6480d42d72023eaabfb3e30c1090d89d18a3d64cc28789cf2
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ Rock Paper Scissors
2
+ ===================
3
+
4
+ How to Run/Install
5
+ ------------------
6
+
7
+ ### Install & Run on Macintosh
8
+
9
+ 1. Run the `rps.bash` with the `Terminal`
10
+
11
+ #### Uninstalling
12
+
13
+ 1. Run the `uninstaller.sh` file with the `Terminal`
14
+
15
+ <!--
16
+ 1. Open the `Terminal` and copy + paste in this line: `\curl -sSL https://get.rvm.io | bash -s stable --ruby`
17
+ 2. Then copy and paste in this line: `gem install rps`; hit <kbd>return</kbd>
18
+
19
+ #### Running
20
+ 1. Go into the `Terminal` and type in `rps`; hit <kbd>return</kbd>
21
+
22
+ #### Troubleshooting
23
+
24
+ ##### RVM Failed Installation
25
+ If RVM fails to install (homebrew), run this in the `Terminal`: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`; hit <kbd>return</kbd>
26
+
27
+ ##### Xcrun Command line tools not found
28
+ If you get an error with `xcrun` and `command line tools not found`, you need to run this in the `Terminal`: `sudo xcode-select --install`; hit <kbd>return</kbd>.
29
+ -->
30
+
31
+ ### Install &amp; Run on Windows
32
+
33
+ 1. Download and install Ruby for Windows (if not already done); download [here](https://rubyinstaller.org/downloads/)
34
+ 2. Open `command prompt` as user and type in this: `gem install rps`; hit <kbd>enter</kbd>
35
+
36
+ #### Running
37
+
38
+ 1. Go into the `command prompt` and type in this: `rps`; hit <kbd>enter</kbd>
39
+
data/bin/rps ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+ |=================================|
5
+ | How to Run |
6
+ |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
7
+ | Mac |
8
+ |---------------------------------|
9
+ | $ ruby ~/Desktop/rps/bin/rps.rb |
10
+ |*********************************|
11
+ | Windows |
12
+ |---------------------------------|
13
+ | > CD Desktop/rps/bin |
14
+ | > rps.rb |
15
+ |_________________________________|
16
+ =end
17
+
18
+ class Master
19
+
20
+ class RPS
21
+
22
+ module Constants
23
+ NTRY_TO_SYM = {
24
+ 'p' => :PAPER,
25
+ 'r' => :ROCK,
26
+ 's' => :SCISSORS
27
+ };
28
+ VALID_ENTRIES = NTRY_TO_SYM.keys;
29
+ COMPUTER_CHOICES = NTRY_TO_SYM.values;
30
+ WINNERS = [
31
+ [:SCISSORS, :PAPER],
32
+ [:PAPER, :ROCK],
33
+ [:ROCK, :SCISSORS]
34
+ ]; # format: player choice, computer choice
35
+ LOSERS = WINNERS.map { |i,j| [j,i] }; # this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
36
+ INIT_STRINGS = [
37
+ "You are about to enter a rock-paper-scissors best of 3 match.",
38
+ "Press the return/enter key to continue...",
39
+ ""
40
+ ];
41
+ end;
42
+
43
+ class RockPaperScissors
44
+ class << self
45
+ def continue(str1, str2, str3)
46
+ puts str1;
47
+ print str2;
48
+ gets;
49
+ puts str3;
50
+ end;
51
+ end;
52
+ continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
53
+ def initialize
54
+ @player_score = @computer_score = @ties = 0;
55
+ end;
56
+ def play(winning_score)
57
+ while @player_score < winning_score && @computer_score < winning_score
58
+ puts "Player score: #{@player_score}, " +
59
+ "Computer score: #{@computer_score}, Ties: #{@ties}";
60
+ player = PrivateVars.player_choice;
61
+ computer = Constants::COMPUTER_CHOICES.sample;
62
+ puts "\nPlayer chooses #{player.to_s.downcase}";
63
+ puts "Computer chooses #{computer.to_s.downcase}";
64
+ case PrivateVars.player_outcome [player, computer]
65
+ when :WIN
66
+ puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round";
67
+ @player_score += 1;
68
+ when :LOSE
69
+ puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
70
+ @computer_score += 1;
71
+ else
72
+ puts "Tie, choose again";
73
+ @ties += 1;
74
+ end;
75
+ end;
76
+ puts "\nFinal score: player: #{@player_score}, " +
77
+ "computer: #{@computer_score} (ties: #{@ties})";
78
+ case PrivateVars.final_outcome(@player_score, @computer_score)
79
+ when :WIN
80
+ puts "Player wins!";
81
+ when :LOSE
82
+ puts "Computer wins!";
83
+ else
84
+ puts "It's a tie!";
85
+ end;
86
+ puts "";
87
+ gets;
88
+ end;
89
+ private
90
+ module PrivateVars
91
+ class << self
92
+ def player_choice
93
+ loop do
94
+ print "Choose rock (r), paper (p) or scissors (s): ";
95
+ choice = gets.chomp.downcase;
96
+ return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
97
+ puts "That entry is invalid. Please re-enter";
98
+ end;
99
+ end;
100
+ def player_outcome(plays)
101
+ return :WIN if Constants::WINNERS.include?(plays);
102
+ return :LOSE if Constants::LOSERS.include?(plays);
103
+ return :TIE if (!:WIN || !:LOSE);
104
+ end;
105
+ def final_outcome(pl, co)
106
+ return :WIN if pl > co;
107
+ return :LOSE if pl < co;
108
+ return :TIE if pl = co;
109
+ end;
110
+ end;
111
+ end;
112
+ end;
113
+ end;
114
+ end;
115
+
116
+ Master::RPS::RockPaperScissors.new.play(3); # best of 3
117
+
data/lib/rps.rb ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+ |=================================|
5
+ | How to Run |
6
+ |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
7
+ | Mac |
8
+ |---------------------------------|
9
+ | $ ruby ~/Desktop/rps/bin/rps.rb |
10
+ |*********************************|
11
+ | Windows |
12
+ |---------------------------------|
13
+ | > CD Desktop/rps/bin |
14
+ | > rps.rb |
15
+ |_________________________________|
16
+ =end
17
+
18
+ class Master
19
+
20
+ class RPS
21
+
22
+ module Constants
23
+ NTRY_TO_SYM = {
24
+ 'p' => :PAPER,
25
+ 'r' => :ROCK,
26
+ 's' => :SCISSORS
27
+ };
28
+ VALID_ENTRIES = NTRY_TO_SYM.keys;
29
+ COMPUTER_CHOICES = NTRY_TO_SYM.values;
30
+ WINNERS = [
31
+ [:SCISSORS, :PAPER],
32
+ [:PAPER, :ROCK],
33
+ [:ROCK, :SCISSORS]
34
+ ]; # format: player choice, computer choice
35
+ LOSERS = WINNERS.map { |i,j| [j,i] }; # this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
36
+ INIT_STRINGS = [
37
+ "You are about to enter a rock-paper-scissors best of 3 match.",
38
+ "Press the return/enter key to continue...",
39
+ ""
40
+ ];
41
+ end;
42
+
43
+ class RockPaperScissors
44
+ class << self
45
+ def continue(str1, str2, str3)
46
+ puts str1;
47
+ print str2;
48
+ gets;
49
+ puts str3;
50
+ end;
51
+ end;
52
+ continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
53
+ def initialize
54
+ @player_score = @computer_score = @ties = 0;
55
+ end;
56
+ def play(winning_score)
57
+ while @player_score < winning_score && @computer_score < winning_score
58
+ puts "Player score: #{@player_score}, " +
59
+ "Computer score: #{@computer_score}, Ties: #{@ties}";
60
+ player = PrivateVars.player_choice;
61
+ computer = Constants::COMPUTER_CHOICES.sample;
62
+ puts "\nPlayer chooses #{player.to_s.downcase}";
63
+ puts "Computer chooses #{computer.to_s.downcase}";
64
+ case PrivateVars.player_outcome [player, computer]
65
+ when :WIN
66
+ puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round";
67
+ @player_score += 1;
68
+ when :LOSE
69
+ puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
70
+ @computer_score += 1;
71
+ else
72
+ puts "Tie, choose again";
73
+ @ties += 1;
74
+ end;
75
+ end;
76
+ puts "\nFinal score: player: #{@player_score}, " +
77
+ "computer: #{@computer_score} (ties: #{@ties})";
78
+ case PrivateVars.final_outcome(@player_score, @computer_score)
79
+ when :WIN
80
+ puts "Player wins!";
81
+ when :LOSE
82
+ puts "Computer wins!";
83
+ else
84
+ puts "It's a tie!";
85
+ end;
86
+ puts "";
87
+ gets;
88
+ end;
89
+ private
90
+ module PrivateVars
91
+ class << self
92
+ def player_choice
93
+ loop do
94
+ print "Choose rock (r), paper (p) or scissors (s): ";
95
+ choice = gets.chomp.downcase;
96
+ return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
97
+ puts "That entry is invalid. Please re-enter";
98
+ end;
99
+ end;
100
+ def player_outcome(plays)
101
+ return :WIN if Constants::WINNERS.include?(plays);
102
+ return :LOSE if Constants::LOSERS.include?(plays);
103
+ return :TIE if (!:WIN || !:LOSE);
104
+ end;
105
+ def final_outcome(pl, co)
106
+ return :WIN if pl > co;
107
+ return :LOSE if pl < co;
108
+ return :TIE if pl = co;
109
+ end;
110
+ end;
111
+ end;
112
+ end;
113
+ end;
114
+ end;
115
+
116
+ Master::RPS::RockPaperScissors.new.play(3); # best of 3
117
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: PlayRockPaperScissorsGame
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - bag3318
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby-programmed rock paper scissors game
14
+ email: ''
15
+ executables:
16
+ - rps
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - README.md
22
+ - bin/rps
23
+ - lib/rps.rb
24
+ homepage:
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.6.11
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Rock Paper Scissors
48
+ test_files: []