Class: PaperRockScissors::Game
- Inherits:
-
Object
- Object
- PaperRockScissors::Game
- Defined in:
- lib/paper_rock_scissors/game.rb
Constant Summary collapse
- SYMBOLS =
{"R" => "S", "S" => "P", "P" => "R"}
Instance Method Summary collapse
- #check_winner(move1, move2) ⇒ Object
-
#initialize(players = 1) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
Constructor Details
Instance Method Details
#check_winner(move1, move2) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/paper_rock_scissors/game.rb', line 33 def check_winner(move1, move2) if SYMBOLS[move1] == move2 puts "Player 1 is the winner!" else puts "Player 2 is the winner!" end end |
#play ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/paper_rock_scissors/game.rb', line 16 def play loop do move1 = @player1.get_move move2 = @player2.get_move if move1 == move2 puts "Tie! Try again!" next else check_winner(move1, move2) end break end end |