Module: Utils

Included in:
Blackjack
Defined in:
lib/blackjack/utils.rb

Instance Method Summary collapse

Instance Method Details

#clear_draw_handsObject



21
22
23
24
# File 'lib/blackjack/utils.rb', line 21

def clear_draw_hands
  clear
  draw_hands
end

#clear_draw_hands_ask_insuranceObject



41
42
43
44
# File 'lib/blackjack/utils.rb', line 41

def clear_draw_hands_ask_insurance
  clear_draw_hands
  ask_insurance
end

#clear_draw_hands_bet_optionsObject



46
47
48
49
# File 'lib/blackjack/utils.rb', line 46

def clear_draw_hands_bet_options
  clear_draw_hands
  draw_bet_options
end

#clear_draw_hands_game_optionsObject



51
52
53
54
# File 'lib/blackjack/utils.rb', line 51

def clear_draw_hands_game_options
  clear_draw_hands
  draw_game_options
end

#clear_draw_hands_new_deck_typeObject



31
32
33
34
# File 'lib/blackjack/utils.rb', line 31

def clear_draw_hands_new_deck_type
  clear_draw_hands
  new_deck_type
end

#clear_draw_hands_new_face_typeObject



36
37
38
39
# File 'lib/blackjack/utils.rb', line 36

def clear_draw_hands_new_face_type
  clear_draw_hands
  new_face_type
end

#clear_draw_hands_new_num_decksObject



26
27
28
29
# File 'lib/blackjack/utils.rb', line 26

def clear_draw_hands_new_num_decks
  clear_draw_hands
  new_num_decks($stdin)
end

#draw_hands_current_hand_actionObject



56
57
58
59
# File 'lib/blackjack/utils.rb', line 56

def draw_hands_current_hand_action
  draw_hands
  current_player_hand.action?
end

#load_gameObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/blackjack/utils.rb', line 10

def load_game
  return unless File.readable?(SAVE_FILE)

  a = File.read(SAVE_FILE).split('|')
  self.num_decks   = a[0].to_i
  self.deck_type   = a[1].to_i
  self.face_type   = a[2].to_i
  self.money       = a[3].to_i
  self.current_bet = a[4].to_i
end

#play_dealer_handObject



61
62
63
64
65
# File 'lib/blackjack/utils.rb', line 61

def play_dealer_hand
  dealer_hand.play
  draw_hands
  draw_bet_options
end

#save_gameObject



4
5
6
7
8
# File 'lib/blackjack/utils.rb', line 4

def save_game
  File.open(SAVE_FILE, 'w') do |file|
    file.puts "#{num_decks}|#{deck_type}|#{face_type}|#{money}|#{current_bet}"
  end
end