Class: Game

Inherits:
Object
  • Object
show all
Defined in:
lib/rora/model/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_inObject (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

#startedObject (readonly)

Returns the value of attribute started.



2
3
4
# File 'lib/rora/model/game.rb', line 2

def started
  @started
end

#tableObject (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

Raises:

  • (ArgumentError)


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_buttonObject



34
35
36
37
# File 'lib/rora/model/game.rb', line 34

def assign_button
  @table.pass_the_buck
  @log.info("#{@table.the_button.player.name} will be the dealer for this hand");
end

#deal_pocket_cardsObject



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_blindObject



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_blindObject



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

#potObject



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_roundObject



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_deckObject



29
30
31
32
# File 'lib/rora/model/game.rb', line 29

def shuffle_deck
  @log.debug("Shuffling the deck")
  @table.deck.shuffle
end

#startObject



11
12
13
# File 'lib/rora/model/game.rb', line 11

def start
  @started = true
end