Class: GameModel
- Inherits:
-
Mousevc::Model
- Object
- Mousevc::Model
- GameModel
- Defined in:
- lib/mousevc_rock_paper_scissors/game_model.rb
Instance Attribute Summary collapse
-
#num_players ⇒ Object
Returns the value of attribute num_players.
-
#player_one ⇒ Object
Returns the value of attribute player_one.
-
#player_two ⇒ Object
Returns the value of attribute player_two.
Instance Method Summary collapse
- #clear ⇒ Object
- #current_player ⇒ Object
- #current_player=(value) ⇒ Object
-
#initialize ⇒ GameModel
constructor
A new instance of GameModel.
- #shoot ⇒ Object
- #shoot_ready? ⇒ Boolean
- #tie? ⇒ Boolean
- #turn ⇒ Object
- #two_player? ⇒ Boolean
Constructor Details
#initialize ⇒ GameModel
Returns a new instance of GameModel.
7 8 9 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 7 def initialize super(:validation => GameValidation.new) end |
Instance Attribute Details
#num_players ⇒ Object
Returns the value of attribute num_players.
5 6 7 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 5 def num_players @num_players end |
#player_one ⇒ Object
Returns the value of attribute player_one.
5 6 7 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 5 def player_one @player_one end |
#player_two ⇒ Object
Returns the value of attribute player_two.
5 6 7 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 5 def player_two @player_two end |
Instance Method Details
#clear ⇒ Object
11 12 13 14 15 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 11 def clear @num_players = nil @player_one = nil @player_two = nil end |
#current_player ⇒ Object
17 18 19 20 21 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 17 def current_player player = :player_one if turn == '1' player = :player_two if turn == '2' player end |
#current_player=(value) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 23 def current_player=(value) player = nil if @validation.valid_hand?(value) player = @player_two = select_hand(value) if turn == '2' player = @player_one = select_hand(value) if turn == '1' end player end |
#shoot ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 49 def shoot if @player_one.beats?(@player_two) winner = '1' loser = '2' winning_hand = @player_one.to_s losing_hand = @player_two.to_s else winner = '2' loser = '1' winning_hand = @player_two.to_s losing_hand = @player_one.to_s end { :winner => winner, :loser => loser, :winning_hand => winning_hand, :losing_hand => losing_hand } end |
#shoot_ready? ⇒ Boolean
77 78 79 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 77 def shoot_ready? @player_one && @player_two end |
#tie? ⇒ Boolean
69 70 71 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 69 def tie? @player_one.ties?(@player_two) end |
#turn ⇒ Object
44 45 46 47 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 44 def turn return '2' if two_player? && @player_one return '1' end |
#two_player? ⇒ Boolean
73 74 75 |
# File 'lib/mousevc_rock_paper_scissors/game_model.rb', line 73 def two_player? @num_players == '2' end |