Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/rora/model/player.rb
Overview
A player in a Texas Hold’em game.
Instance Attribute Summary collapse
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #act ⇒ Object
- #add(card) ⇒ Object
- #end_session ⇒ Object
-
#initialize(name, stack) ⇒ Player
constructor
A new instance of Player.
- #join_game(game, seat = nil) ⇒ Object
- #leave_game ⇒ Object
- #post_big_blind ⇒ Object
- #post_small_blind ⇒ Object
- #sitting_out? ⇒ Boolean
- #start_session ⇒ Object
- #starting_hand ⇒ Object
Constructor Details
#initialize(name, stack) ⇒ Player
Returns a new instance of Player.
7 8 9 10 11 12 13 14 15 |
# File 'lib/rora/model/player.rb', line 7 def initialize name, stack raise ArgumentError, "The player name cannot be nil" if name.nil? @name = name @stack = stack.nil? ? 0 : stack @sitting_out = true @table = nil @cards = [] @log = GameLogger.new end |
Instance Attribute Details
#game ⇒ Object (readonly)
Returns the value of attribute game.
5 6 7 |
# File 'lib/rora/model/player.rb', line 5 def game @game end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/rora/model/player.rb', line 5 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
5 6 7 |
# File 'lib/rora/model/player.rb', line 5 def stack @stack end |
Instance Method Details
#act ⇒ Object
60 61 62 63 64 |
# File 'lib/rora/model/player.rb', line 60 def act raise_error_if_sitting_out "cannot act" action = "folds" @log.info("#{name} #{action}") end |
#add(card) ⇒ Object
42 43 44 |
# File 'lib/rora/model/player.rb', line 42 def add card @cards << card end |
#end_session ⇒ Object
34 35 36 |
# File 'lib/rora/model/player.rb', line 34 def end_session @sitting_out = true end |
#join_game(game, seat = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rora/model/player.rb', line 17 def join_game game, seat=nil raise ArgumentError, "#{@name} cannot join this game, the table is full" if game.table.full? raise ArgumentError, "#{@name} cannot join this game, this player is already playing another game" if !@game.nil? game.table.add self, seat @game = game end |
#leave_game ⇒ Object
24 25 26 27 |
# File 'lib/rora/model/player.rb', line 24 def leave_game end_session @game = nil end |
#post_big_blind ⇒ Object
55 56 57 58 |
# File 'lib/rora/model/player.rb', line 55 def post_big_blind raise_error_if_sitting_out "cannot post the big blind" @game.place_bet @game.buy_in / 100.00 end |
#post_small_blind ⇒ Object
50 51 52 53 |
# File 'lib/rora/model/player.rb', line 50 def post_small_blind raise_error_if_sitting_out "cannot post the small blind" @game.place_bet @game.buy_in / 200.00 end |
#sitting_out? ⇒ Boolean
38 39 40 |
# File 'lib/rora/model/player.rb', line 38 def sitting_out? @sitting_out end |
#start_session ⇒ Object
29 30 31 32 |
# File 'lib/rora/model/player.rb', line 29 def start_session raise ArgumentError, "#{@name} is not sitting at a table" if @game.nil? @sitting_out = false end |
#starting_hand ⇒ Object
46 47 48 |
# File 'lib/rora/model/player.rb', line 46 def starting_hand StartingHand.new(@cards) end |