Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/mblackjack/game.rb
Instance Attribute Summary collapse
-
#dealer ⇒ Object
Returns the value of attribute dealer.
-
#deck ⇒ Object
Returns the value of attribute deck.
-
#hand_arr ⇒ Object
Returns the value of attribute hand_arr.
-
#no_of_players ⇒ Object
Returns the value of attribute no_of_players.
-
#player_arr ⇒ Object
Returns the value of attribute player_arr.
Instance Method Summary collapse
-
#initialize(player_count = 1) ⇒ Game
constructor
A new instance of Game.
- #record_no_of_players ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(player_count = 1) ⇒ Game
Returns a new instance of Game.
4 5 6 7 8 9 10 |
# File 'lib/mblackjack/game.rb', line 4 def initialize(player_count=1) @deck = Deck.new @dealer = Dealer.new @no_of_players = 0 @player_arr = [@player1, @player2, @player3, @player4] @hand_arr = [@hand1, @hand2, @hand3, @hand4, @hand5, @hand6] end |
Instance Attribute Details
#dealer ⇒ Object
Returns the value of attribute dealer.
2 3 4 |
# File 'lib/mblackjack/game.rb', line 2 def dealer @dealer end |
#deck ⇒ Object
Returns the value of attribute deck.
2 3 4 |
# File 'lib/mblackjack/game.rb', line 2 def deck @deck end |
#hand_arr ⇒ Object
Returns the value of attribute hand_arr.
2 3 4 |
# File 'lib/mblackjack/game.rb', line 2 def hand_arr @hand_arr end |
#no_of_players ⇒ Object
Returns the value of attribute no_of_players.
2 3 4 |
# File 'lib/mblackjack/game.rb', line 2 def no_of_players @no_of_players end |
#player_arr ⇒ Object
Returns the value of attribute player_arr.
2 3 4 |
# File 'lib/mblackjack/game.rb', line 2 def player_arr @player_arr end |
Instance Method Details
#record_no_of_players ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/mblackjack/game.rb', line 14 def record_no_of_players puts "How many players are playing today?" @no_of_players = gets.chomp.to_i @no_of_players.times do |c| @player_arr[c] = Player.new(100) @player_arr[c].player_no = (c+1) end end |
#start ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mblackjack/game.rb', line 24 def start if no_of_players < 1 record_no_of_players end assign_hand_and_bet assign_first_two_round_cards show_player_cards check_for_two_card_blackjack show_one_dealer_card player_choose_action dealer_draws compare_with_dealer ask_if_play_again end |