Class: MAndMRps::Code
- Inherits:
-
Object
- Object
- MAndMRps::Code
- Defined in:
- lib/code.rb
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize ⇒ Code
constructor
A new instance of Code.
- #outcome(val) ⇒ Object
- #play ⇒ Object
- #select_opponent ⇒ Object
Constructor Details
Instance Method Details
#compare ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/code.rb', line 31 def compare if @choice1 == @choice2 puts "Tie. Try Again" elsif @choice1 == "rock" if @choice2 == "paper" outcome(2) else outcome(1) end elsif @choice1 == "paper" if @choice2 == "scissors" outcome(2) else outcome(1) end elsif @choice1 == "scissors" if @choice2 == "rock" outcome(2) else outcome(1) end end end |
#outcome(val) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/code.rb', line 61 def outcome(val) if val == 1 puts "Player 1 wins" else puts "Player 2 wins" end end |
#play ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/code.rb', line 19 def play select_opponent @choice1 = @player1.choice(@options) p @choice1 @choice2 = @player2.choice(@options) p @choice2 compare end |