Class: RockPaperScissors::Board
- Inherits:
-
Object
- Object
- RockPaperScissors::Board
- Defined in:
- lib/rock_paper_scissors/board.rb
Constant Summary collapse
- @@wins =
[ {pair: ['r', 's'], phrase: 'Rock crushes Scissors.'}, {pair: ['r', 'l'], phrase: 'Rock crushes Lizard.'}, {pair: ['p', 'r'], phrase: 'Paper covers Rock.'}, {pair: ['p', 'sp'], phrase: 'Paper disproves Spock.'}, {pair: ['s', 'p'], phrase: 'Scissors cut Paper.'}, {pair: ['s', 'l'], phrase: 'Scissors decapitate Lizard.'}, {pair: ['l', 'sp'], phrase: 'Lizard poisons Spock.'}, {pair: ['l', 'p'], phrase: 'Lizard eats Paper.'}, {pair: ['sp', 's'], phrase: 'Spock smashes Scissors.'}, {pair: ['sp', 'r'], phrase: 'Spock vaporizes Rock.'} ]
Instance Attribute Summary collapse
-
#player_moves ⇒ Object
readonly
Returns the value of attribute player_moves.
-
#plays ⇒ Object
readonly
Returns the value of attribute plays.
Instance Method Summary collapse
-
#initialize(mode) ⇒ Board
constructor
A new instance of Board.
- #options ⇒ Object
- #phrase(moves) ⇒ Object
- #place_move(player_number, move) ⇒ Object
- #winner ⇒ Object
Constructor Details
#initialize(mode) ⇒ Board
Returns a new instance of Board.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rock_paper_scissors/board.rb', line 18 def initialize(mode) @player_moves = [] @plays = {r: 'rock', p: 'paper', s: 'scissors'} if mode == 2 @plays[:l] = 'lizard' @plays[:sp] = 'Spock' end end |
Instance Attribute Details
#player_moves ⇒ Object (readonly)
Returns the value of attribute player_moves.
3 4 5 |
# File 'lib/rock_paper_scissors/board.rb', line 3 def player_moves @player_moves end |
#plays ⇒ Object (readonly)
Returns the value of attribute plays.
3 4 5 |
# File 'lib/rock_paper_scissors/board.rb', line 3 def plays @plays end |
Instance Method Details
#options ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rock_paper_scissors/board.rb', line 29 def = [] @plays.each do |symbol, word| << "#{symbol} = #{word}" end .join(', ') end |
#phrase(moves) ⇒ Object
49 50 51 52 |
# File 'lib/rock_paper_scissors/board.rb', line 49 def phrase(moves) winning_move = @@wins.select { |win| win[:pair] == moves }.first winning_move[:phrase] end |
#place_move(player_number, move) ⇒ Object
37 38 39 |
# File 'lib/rock_paper_scissors/board.rb', line 37 def place_move(player_number, move) @player_moves[player_number - 1] = move if valid?(move) end |
#winner ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rock_paper_scissors/board.rb', line 41 def winner if @@wins.any? { |win| win[:pair] == @player_moves } 1 else 2 end end |