Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/rora/model/game.rb
Instance Attribute Summary collapse
-
#buy_in ⇒ Object
readonly
Returns the value of attribute buy_in.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #add(player) ⇒ Object
- #assign_button ⇒ Object
- #deal_pocket_cards ⇒ Object
-
#initialize(arguments = nil) ⇒ Game
constructor
A new instance of Game.
- #place_bet(amount) ⇒ Object
- #post_big_blind ⇒ Object
- #post_small_blind ⇒ Object
- #pot ⇒ Object
- #remove(player) ⇒ Object
- #run_preflop_betting_round ⇒ Object
- #shuffle_deck ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(arguments = nil) ⇒ Game
Returns a new instance of Game.
4 5 6 7 8 9 |
# File 'lib/rora/model/game.rb', line 4 def initialize arguments=nil @table = arguments.nil? ? Table.new : (arguments[:table].nil? ? Table.new : arguments[:table]) @buy_in = arguments.nil? ? 50 : (arguments[:buy_in].nil ? 20 : arguments[:buy_in]) @log = GameLogger.new @started = false end |
Instance Attribute Details
#buy_in ⇒ Object (readonly)
Returns the value of attribute buy_in.
2 3 4 |
# File 'lib/rora/model/game.rb', line 2 def buy_in @buy_in end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
2 3 4 |
# File 'lib/rora/model/game.rb', line 2 def started @started end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
2 3 4 |
# File 'lib/rora/model/game.rb', line 2 def table @table end |
Instance Method Details
#add(player) ⇒ Object
15 16 17 18 19 |
# File 'lib/rora/model/game.rb', line 15 def add player raise ArgumentError, "#{player.name} cannot join game, stack of #{player.stack} is less than the buy in amount #{@buy_in}" if player.stack < @buy_in raise ArgumentError, "#{player.name} cannot join game, the game has already started" if @started player.join_game self end |
#assign_button ⇒ Object
34 35 36 37 |
# File 'lib/rora/model/game.rb', line 34 def @table.pass_the_buck @log.info("#{@table..player.name} will be the dealer for this hand"); end |
#deal_pocket_cards ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/rora/model/game.rb', line 50 def deal_pocket_cards @table.players.each do |player| player.add table.deck.deal end @table.players.each do |player| player.add table.deck.deal end end |
#place_bet(amount) ⇒ Object
59 60 61 |
# File 'lib/rora/model/game.rb', line 59 def place_bet amount @table.pot.add amount end |
#post_big_blind ⇒ Object
44 45 46 47 48 |
# File 'lib/rora/model/game.rb', line 44 def post_big_blind @table.the_big_blind.player.post_big_blind @log.info("#{@table.the_big_blind.player.name} posts the big blind"); @log.info("The pot is at #{@table.pot.value}"); end |
#post_small_blind ⇒ Object
39 40 41 42 |
# File 'lib/rora/model/game.rb', line 39 def post_small_blind @table.the_small_blind.player.post_small_blind @log.info("#{@table.the_small_blind.player.name} posts the small blind"); end |
#pot ⇒ Object
25 26 27 |
# File 'lib/rora/model/game.rb', line 25 def pot @table.pot end |
#remove(player) ⇒ Object
21 22 23 |
# File 'lib/rora/model/game.rb', line 21 def remove player player.leave_game end |
#run_preflop_betting_round ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rora/model/game.rb', line 63 def run_preflop_betting_round @log.info("-----------------------------------------------------------------") first_to_act = @table.under_the_gun first_to_act.player.act number = first_to_act.number seat_number = @table.the_seat_after(first_to_act).number while seat_number != number @table.seat(seat_number).player.act seat_number = @table.the_seat_after(@table.seat(seat_number)).number end end |
#shuffle_deck ⇒ Object
29 30 31 32 |
# File 'lib/rora/model/game.rb', line 29 def shuffle_deck @log.debug("Shuffling the deck") @table.deck.shuffle end |
#start ⇒ Object
11 12 13 |
# File 'lib/rora/model/game.rb', line 11 def start @started = true end |